dahall / Vanara

A set of .NET libraries for Windows implementing PInvoke calls to many native Windows APIs with supporting wrappers.
MIT License
1.75k stars 190 forks source link

RtlGetVersion not found in NtDll #421

Closed emako closed 9 months ago

emako commented 10 months ago
<PackageReference Include="Vanara.PInvoke.NtDll" Version="3.4.16" />

RtlGetVersion not found in NtDll.

dahall commented 10 months ago

See https://github.com/dahall/Vanara/blob/da04510b0af70a14389922625e67cae0273eb319/PInvoke/Kernel32/SysInfoApi.cs#L2162

emako commented 10 months ago

It looks different from the API results of NtDll. R2X3O7$0QXUF1X57AT~QSHS

emako commented 10 months ago

image NtDll.RtlGetVersion is OK.

public static class NtDll
{
    [SecurityCritical]
    [DllImport(Lib.NTdll, SetLastError = true, CharSet = CharSet.Unicode)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    public static extern int RtlGetVersion(out OSVERSIONINFOEX versionInfo);
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFOEX
{
    public int OSVersionInfoSize;
    public int MajorVersion;
    public int MinorVersion;
    public int BuildNumber;
    public int Revision;
    public int PlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string CSDVersion;
    public ushort ServicePackMajor;
    public ushort ServicePackMinor;
    public short SuiteMask;
    public byte ProductType;
    public byte Reserved;
}

Could you reopen the issuse?

dahall commented 10 months ago

Both those methods (GetVersionEx and RtlGetVersion) are marked as obsolete in lieu of the functions in VersionHelpers.h. You can find the Varana equivalents at PInvoke/Kernel32/VersionHelpers.cs

dahall commented 10 months ago

To use GetVersionEx you have to set the size or use the Default field:

var ver = OSVERSIONINFOEX.Default;
if (!GetVersionEx(ref ver)) ...
emako commented 10 months ago

Kernel32.OSVERSIONINFOEX.Default make Kernel32.GetVersionEx return true, but it seems that the value is not eq to NtDll.RtlGetVersion.

Kernel32.GetVersionEx image

NtDll.RtlGetVersion image

Addtional infos:

My TargetFramework like following and I don't use any app.manifest file.

<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework> // in my exe csproj
<TargetFramework>net7.0-windows</TargetFramework> // in my lib csproj