Recommended Posts

I've read a few different methods for doing this, but none seem to work in my case. Here's the situation:
I had a c++ class, which I've successfully compiled/ran/tested in C++/CLI. Sweet.
Now I wish to call this from C#. I tried exporting as a dll, but it's not quite working, not sure if that's even the best way. Viewing the dll, my method is available (using dll export viewer):
?Init@Watcher@@QAEHXZ 0x100017a0 0x000017a0 1 (0x1) ManagedCppTest.dll D:\Dev\ManagedCppTest\debug\ManagedCppTest.dll Exported Function
Now, in C#, I can create a Watcher object, but can't call the Init method:
Watcher test = new Watcher(); //works fine
test.Init(); //no init
Am I doing this wrong, or is there an easier way?

Share this post

Link to post

Share on other sites

Original post by ThrumpAhh ok thanks. This stuff is all new to me, so not sure what is managed / non-managed... or at least I do sometimes until I get confused. I'll try to make my class public ref and see how that goes.

Basically:

Managed = Memory allocation is handled by the CLR garbage collector. Therefore, it acts like a C# class-- you create it with new, and the GC will free the memory when there aren't any references to it remaining.

Unmanaged = This is basically your classic C++ class. You can create it on the heap or the stack, and if you use new you must use delete. You cannot export these to unmanaged languages without wrapping it.

My knowledge of C++/CLI is a little fuzzy, so if I'm off base (or outright wrong), someone correct me.

0

Share this post

Link to post

Share on other sites

Here is the header to an example I threw together for myself. This is just code to help you get you along the way. But you still have to put together the solution/project space correctly in both the C++ and C# projects to get this to work.