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

GetIconInfo throws "Pointers cannot reference marshaled structures. Use ByRef instead." #126

Closed
jnm2 opened this issue Feb 18, 2021 · 1 comment · Fixed by #127
Closed
Assignees
Labels
bug Something isn't working

Comments

@jnm2
Copy link
Contributor

jnm2 commented Feb 18, 2021

This broke in 0.1.362-beta and works in 0.1.355-beta-gc4a93d0827.

System.Runtime.InteropServices.MarshalDirectiveException: 'Cannot marshal 'parameter #2': Pointers cannot reference marshaled structures. Use ByRef instead.'

Generated code, minus most of the doc comments:

internal static unsafe bool GetIconInfo(SafeHandle hIcon, out ICONINFO piconinfo)
{
    fixed (ICONINFO*piconinfoLocal = &piconinfo)
    {
        return PInvoke.GetIconInfo(hIcon, piconinfoLocal);
    }
}

[DllImport("User32", ExactSpelling = true, SetLastError = true)]
internal static extern unsafe bool GetIconInfo(SafeHandle hIcon, [Out] ICONINFO*piconinfo);
internal partial struct ICONINFO
{
    /// <summary>
    /// <para>Type: <b>BOOL</b></para>
    /// <para>Specifies whether this structure defines an icon or a cursor. A value of <b>TRUE</b> specifies an icon; <b>FALSE</b> specifies a cursor.</para>
    /// <para><see href = "https://docs.microsoft.com/windows/win32/api//winuser/ns-winuser-iconinfo#members">Read more on docs.microsoft.com</see>.</para>
    /// </summary>
    internal bool fIcon;
    internal uint xHotspot;
    internal uint yHotspot;
    internal HBITMAP hbmMask;
    internal HBITMAP hbmColor;
}

ICONINFO.fIcon is now declared as bool instead of BOOL, meaning that ICONINFO is no longer blittable.

It looks like this could be a result of #104.

@jnm2 jnm2 changed the title GetCursorInfo throws "Pointers cannot reference marshaled structures. Use ByRef instead." GetIconInfo throws "Pointers cannot reference marshaled structures. Use ByRef instead." Feb 18, 2021
@AArnott AArnott added the bug Something isn't working label Feb 18, 2021
@AArnott AArnott self-assigned this Feb 18, 2021
AArnott added a commit that referenced this issue Feb 18, 2021
@AArnott
Copy link
Member

AArnott commented Feb 18, 2021

Thanks for catching the regression.

AArnott added a commit that referenced this issue Feb 18, 2021
AArnott added a commit that referenced this issue May 6, 2022
…est.Sdk-17.0.0

Bump Microsoft.NET.Test.Sdk from 16.11.0 to 17.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants