Unknown error in LibraryImport with ref parameter #116887
-
Here internal static partial class User32
{
[LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool DestroyIcon(nint hIcon);
[LibraryImport("user32.dll", SetLastError = true)]
public static partial nint CreateIconIndirect(ref ICONINFO iconInfo);
[LibraryImport("user32.dll", SetLastError = true)]
public static partial nint GetDC(nint hWnd);
[LibraryImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool ReleaseDC(nint hWnd, nint hDC);
[StructLayout(LayoutKind.Sequential)]
internal struct ICONINFO
{
[MarshalAs(UnmanagedType.Bool)]
public bool fIcon;
public uint xHotspot;
public uint yHotspot;
public nint hbmMask;
public nint hbmColor;
}
}
what's the problem? |
Beta Was this translation helpful? Give feedback.
Answered by
huoyaoyuan
Jun 21, 2025
Replies: 1 comment 3 replies
-
You may modify it this way [StructLayout(LayoutKind.Sequential)]
internal struct ICONINFO
{
public int fIcon;
public uint xHotspot;
public uint yHotspot;
public nint hbmMask;
public nint hbmColor;
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not a blittable struct. Only
[MarshalAs(UnmanagedType.U1)]
withbool
is blittable,[MarshalAs(UnmanagedType.Bool)]
is not.