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

GlobalMemoryStatusEx fails to meet API precondition #1743

Closed
sharwell opened this issue Nov 22, 2023 · 1 comment
Closed

GlobalMemoryStatusEx fails to meet API precondition #1743

sharwell opened this issue Nov 22, 2023 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@sharwell
Copy link
Member

Actual behavior

PInvoke.GlobalMemoryStatusEx is generated as follows:

/// <inheritdoc cref="GlobalMemoryStatusEx(winmdroot.System.SystemInformation.MEMORYSTATUSEX*)"/>
[SupportedOSPlatform("windows5.1.2600")]
internal static unsafe winmdroot.Foundation.BOOL GlobalMemoryStatusEx(out winmdroot.System.SystemInformation.MEMORYSTATUSEX lpBuffer)
{
    fixed (winmdroot.System.SystemInformation.MEMORYSTATUSEX* lpBufferLocal = &lpBuffer)
    {
        winmdroot.Foundation.BOOL __result = PInvoke.GlobalMemoryStatusEx(lpBufferLocal);
        return __result;
    }
}

Expected behavior

MEMORYSTATUSEX.dwLength is set prior to invoking the native method.

Repro steps

  1. NativeMethods.txt content:
GlobalMemoryStatusEx
  1. NativeMethods.json content (if present):
{
}
  1. Any of your own code that should be shared?

Context

  • CsWin32 version: 0.3.49-beta
  • Win32Metadata version (if explicitly set by project): Not set
  • Target Framework: net6.0-windows
  • LangVersion (if explicitly set by project): Not set
@sharwell sharwell added the bug Something isn't working label Nov 22, 2023
@AArnott
Copy link
Member

AArnott commented Nov 22, 2023

Thanks for reporting this, @sharwell.
The metadata for this method is wrong. It attributes the parameter as [out] when it must be [in, out] to support the fact that it must be initialized by the caller first. In fact the docs for this method show it as in, out.

Once the metadata is fixed, CsWin32 will emit this as a ref parameter. It is up to the caller of the CsWin32 generated API to initialize the struct's length field, just as it would in C++.

@AArnott AArnott transferred this issue from microsoft/CsWin32 Nov 22, 2023
@mikebattista mikebattista self-assigned this Nov 30, 2023
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

No branches or pull requests

3 participants