mono / CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
MIT License
3.14k stars 518 forks source link

Error with NamespacesDerived.cs in NamespacesDerived.CSharp #464

Closed Mage15 closed 9 years ago

Mage15 commented 9 years ago

This is my first time trying to use CppSharp. I using VS 2013 on Windows 8 and have followed the "Compiling on Windows/Visual Studio" build steps for building the 32 bit version. However now when I build CppSharp from the VS Developers Command Prompt I am getting 3 errors. I opened the solution in VS 2013 and chose not to upgrade to .NET 4.5, so I am still targeting 4.0.


VS seems to be calling out this section of code: private void DestroyNativeInstance(bool force) { Base dummy; NativeToManagedMap.TryRemove(Instance, out dummy); if (ownsNativeInstance) Marshal.FreeHGlobal(__Instance); }


VS recommends this fix: private void DestroyNativeInstance(bool force) { NamespacesBase.Base dummy; NativeToManagedMap.TryRemove(Instance, out dummy); if (ownsNativeInstance) Marshal.FreeHGlobal(__Instance); }

However since this file is auto-generated the fix won't remain and is reverted back to the error when the solution is built.

I am wondering if I have not done something correctly or if this is a bug.

Thanks.

ddobrev commented 9 years ago

I work on something related at present, I'll fix it soon. If you want, you can help. You need to change the line:

                    WriteLine("{0} {1};", @interface != null ? @interface.Name : className, Helpers.DummyIdentifier);

in CSharpTextTemplate.GenerateDisposeMethods. This line needs to type a fully qualified name instead of the short name used now. You can use QualifiedIdentifierIfNeeded for the purpose.

ddobrev commented 9 years ago

I've sent a pull at https://github.com/mono/CppSharp/pull/474, when it's merged, this will be fixed.

Mage15 commented 9 years ago

I hadn't had the opportunity to get to this until this morning. I just pulled the code down and this appears to not have made it into origin as of yet. So I went ahead and made your suggested change:

WriteLine("{0} {1};", @interface != null ? @interface.Name : className, Helpers.DummyIdentifier);

to

WriteLine("{0} {1};", @interface != null ? @interface.Name : QualifiedIdentifierIfNeeded(@base), Helpers.DummyIdentifier);

It now seems to build correctly! Thank you for your help with this.