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.05k stars 85 forks source link

We are trying to use Microsoft.Windows.CsWin32 in a VbProj WinForms net6 and we have issue with the namespace #957

Closed akokouri closed 10 months ago

akokouri commented 1 year ago

Actual behavior

We are trying to use Microsoft.Windows.CsWin32 in a VbProj WinForms net6 and we have issue with the namespace. The winforms namespace is System.Windows.Forms. In many generated code the code is used like Windows.Forms instead of System.Windows.Forms. This cause the project to fail in build, because is confused with Windows.Win32 (namespace) generated code.

Expected behavior

To have a completed build

Repro steps

Use the Microsoft.Windows.CsWin32 in a vb winforms project that has autogenerated code that uses Windows.Forms instead of System.Windows.Forms

Is there any workaround for this? Could we change the generated namespace in something else?

AArnott commented 1 year ago

CsWin32 only generates C# code. There is no way it will work for you in a .vbproj.

paul1956 commented 10 months ago

@AArnott is there a way to generate the code in a C# project but reference it from a VB Project. An example of this would be very useful.

AArnott commented 10 months ago

Sure. You can configure your C# project to generate the APIs, and either use InternalsVisibleToAttribute in the C# project to expose those APIs to your VB project, or use the NativeMethods.json file to configure the generated code to be public instead of internal. But it's still not supported, because VB doesn't support pointers, and interop often requires pointers. Not always though, so your mileage may vary.