Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GeneratedDllImport in System.Diagnostics.FileVersionInfo and System.Runtime.InteropServices.RuntimeInformation #52739

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal static partial class Interop
{
internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixVersion", CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetUnixVersion(byte[] version, ref int capacity);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixVersion", CharSet = CharSet.Ansi, SetLastError = true)]
private static partial int GetUnixVersion(byte[] version, ref int capacity);

internal static string GetUnixVersion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ internal enum FileStatusFlags
HasBirthTime = 1,
}

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)]
internal static extern int FStat(SafeHandle fd, out FileStatus output);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat", SetLastError = true)]
internal static partial int FStat(SafeHandle fd, out FileStatus output);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", SetLastError = true)]
internal static extern int Stat(string path, out FileStatus output);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat", CharSet = CharSet.Ansi, SetLastError = true)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is CharSet = CharSet.Ansi needed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had the p/invoke source generators avoid making any assumptions about CharSet if it isn't set, so it requires explicitly specifying either CharSet or MarshalAs when marshalling string/char.

internal static partial int Stat(string path, out FileStatus output);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", SetLastError = true)]
internal static extern int LStat(string path, out FileStatus output);
[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat", CharSet = CharSet.Ansi, SetLastError = true)]
internal static partial int LStat(string path, out FileStatus output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32)]
internal static extern void GetNativeSystemInfo(out SYSTEM_INFO lpSystemInfo);
[GeneratedDllImport(Libraries.Kernel32)]
internal static partial void GetNativeSystemInfo(out SYSTEM_INFO lpSystemInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
[DllImport(Libraries.Kernel32)]
internal static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
[GeneratedDllImport(Libraries.Kernel32)]
internal static partial void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ internal static partial class Interop
{
internal static partial class Version
{
[DllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoExW")]
internal static extern bool GetFileVersionInfoEx(
[GeneratedDllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoExW")]
internal static partial bool GetFileVersionInfoEx(
uint dwFlags,
string lpwstrFilename,
uint dwHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static partial class Interop
{
internal static partial class Version
{
[DllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoSizeExW")]
internal static extern uint GetFileVersionInfoSizeEx(uint dwFlags, string lpwstrFilename, out uint lpdwHandle);
[GeneratedDllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "GetFileVersionInfoSizeExW")]
internal static partial uint GetFileVersionInfoSizeEx(uint dwFlags, string lpwstrFilename, out uint lpdwHandle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Version
{
[DllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "VerQueryValueW")]
internal static extern bool VerQueryValue(IntPtr pBlock, string lpSubBlock, out IntPtr lplpBuffer, out uint puLen);
[GeneratedDllImport(Libraries.Version, CharSet = CharSet.Unicode, EntryPoint = "VerQueryValueW")]
internal static partial bool VerQueryValue(IntPtr pBlock, string lpSubBlock, out IntPtr lplpBuffer, out uint puLen);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Link="Common\Interop\Windows\Kernel32\Interop.GetSystemInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Memory" />
<Reference Include="System.Reflection" />
<Reference Include="System.Reflection.Extensions" />
<Reference Include="System.Runtime" />
Expand Down