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
1.99k stars 84 forks source link

The API "Gdi32" is ambiguous #1201

Closed lsj13210 closed 2 weeks ago

lsj13210 commented 3 weeks ago
all

NativeMethods.txt User32. Gdi32. DwmAPI. Kernel32. WM* SC S_ CW* MSGFLTINFO*

my config above but second line Gdi32.* trigger exception :The API "Gdi32" is ambiguous how could i fix it,anyone can help?

AArnott commented 3 weeks ago

This is because gdi32.dll contains methods that are expressed both in the "SDK" and the "WDK". I think we'll just fix this by generating from both.

AArnott commented 3 weeks ago

In the meantime, the workaround would be to ask for the specific functions you need. That's the recommended approach anyway since it will result in far less code generated, and less bloat in your dll.

lsj13210 commented 3 weeks ago

Thank you very much for your reply. way 1: lower the version to 0.02.188-beta, way 2: As per your prompt, config the specified method name, which also solved the problem

for someone like me who is lazy, sometimes I want to produce all the methods at once so that I can easily retrieve a method, even if I only remember the approximate name. Otherwise, I have to search for the Win32 API ,try to copy and paste the complete method name, which feels very inconvenient.

Another area of confusion is why this issue occurs in higher versions and not in lower versions?

AArnott commented 3 weeks ago

Lower versions used older metadata and (if you go back far enough) didn't include the WDK metadata at all. So the ambiguity is introduced when you have more metadata that describes more functions.