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

Questions regarding additional structs #1001

Closed drauch closed 11 months ago

drauch commented 11 months ago

Really like the concept of the library and started to use it today.

I've used it to generate SignerSignEx2, this generates lots of additional structs, and I've problems filling them:

1) strings in those structs are PCWSTR and not System.String typed. How to properly convert a System.String into a PCWSTR? Wouldn't it be nice if those structs would contain System.String properties? :-)

2) How to properly fill the cbSize of those structs? Is this something that is done automatically in the ctor? It doesn't look like it, so I have to use (uint) Marshal.SizeOf<STRUCT_TYPE>() am I right?

3) Unions are strangely called "Anonymous", is this correct or a generation error?

Best regards, D.R.

drauch commented 11 months ago

Another question:

CreateFile returns a SafeHandle, the struct SIGNER_FILE_INFO wants a HANDLE. How to do that? Is (HANDLE) file.DangerousGetHandle() the way to go?

drauch commented 11 months ago

One more:

CertOpenStore has a parameter of HCRYPTPROV which should be set to null. I can't pass null nor IntPtr.Zero though. How to pass NULL as this paramteter? Is new HCRYPTPROV_LEGACY(nuint.Zero) the way to go?

All the best, D.R.

drauch commented 11 months ago

Also generating constants defined in https://learn.microsoft.com/en-us/windows/win32/seccrypto/alg-id does not work, how can they be found? Do I have to manually create those?

Best regards, D.R.

PS: Sorry for the spam :-)