microsoft / CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.
MIT License
2.07k stars 87 forks source link

Bug: CONNECT_UPDATE_PROFILE cannot be found #1131

Closed 0x5bfa closed 7 months ago

0x5bfa commented 8 months ago

Actual behavior

CONNECT_UPDATE_PROFILE cannt be found though I added this const to the NativeMethods.txt file.

Expected behavior

It must be found.

Repro steps

  1. NativeMethods.txt content:

    WNetCancelConnection2
    CONNECT_UPDATE_PROFILE
  2. NativeMethods.json content (if present):

  3. Any of your own code that should be shared?

Context

AArnott commented 8 months ago

CONNECT_UPDATE_PROFILE is a value on an enum in the metadata. When you compile your project, a warning should have been produced telling you to switch asking for CONNECT_UPDATE_PROFILE out for asking for the enum type name itself. Do you see that when you build?

0x5bfa commented 8 months ago

I could not find the enum name. Looking at the docs about WNetCancelConnection2A, I have thought this is defined by #define directive.

AArnott commented 7 months ago

When I put CONNECT_UPDATE_PROFILE into my NativeMethods.txt file, I see this warning when building, which tells you the name of the enum to use:

CsWin32Sandbox\NativeMethods.txt(1,1,1,23): warning PInvoke004: Use the name of the enum that declares this constant: NET_USE_CONNECT_FLAGS

0x5bfa commented 5 months ago

How do I know that enum class before building?

AArnott commented 5 months ago

You might not know before building, but since building emits a warning that tells you the enum type name, you can then fix it.