As the title states. The only solution I have come across is to create a wrapper class in C++ managed of the dll object. But honestly I dont know what that means(I do, but not technically). Could someone explain the conecpt in the thread title to me? Thank you.
Using C++ unmanaged objects from DLL in C#
Started by Slig Commando, Feb 02 2012 08:43 PM
5 replies to this topic
Ad:
#2 Senior Moderators - Reputation: 2447
Posted 02 February 2012 - 11:09 PM
If you're passing C++ classes around across DLL boundaries without using interfaces then you're doing it wrong, regardless of the managed/unmanaged setup.
Other than that, if you wish to use a "C++ class" or an unmanaged interface from .net you will have to use C++/CLI to wrap it. Unless it's a COM object, in which case .net can generate a wrapper for it.
If we're talking non-member functions and structs, then you can use pinvoke.
Other than that, if you wish to use a "C++ class" or an unmanaged interface from .net you will have to use C++/CLI to wrap it. Unless it's a COM object, in which case .net can generate a wrapper for it.
If we're talking non-member functions and structs, then you can use pinvoke.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX
ScapeCode - Blog | SlimDX
#3 Members - Reputation: 696
Posted 03 February 2012 - 01:54 AM
Alternatively to C++/CLI or COM objects you can use CXXI: https://github.com/mono/cxxi (I'm not sure how production-quality ready it is currently).
#4 Members - Reputation: 108
Posted 03 February 2012 - 01:52 PM
Washu, on 02 February 2012 - 11:09 PM, said:
If you're passing C++ classes around across DLL boundaries without using interfaces then you're doing it wrong, regardless of the managed/unmanaged setup.
There are no interfaces in unmanaged c++, unless by interface you mean an ADT, which is purely situational in unmanaged code.
Could you please explain why? As long as I am implicitly linking to my dll's, they all share the same heap, so what is the issue?
Also, I was originally wanting to implement my game engine(via dll's) in a windows form application(map editor), but then I realized there is c++ windows forms. So if that simplifies the answer at all, great!
#5 Senior Moderators - Reputation: 2447
Posted 03 February 2012 - 01:59 PM
LevyDee, on 03 February 2012 - 01:52 PM, said:
Washu, on 02 February 2012 - 11:09 PM, said:
If you're passing C++ classes around across DLL boundaries without using interfaces then you're doing it wrong, regardless of the managed/unmanaged setup.
There are no interfaces in unmanaged c++, unless by interface you mean an ADT, which is purely situational in unmanaged code.
Could you please explain why? As long as I am implicitly linking to my dll's, they all share the same heap, so what is the issue?
Also, I was originally wanting to implement my game engine(via dll's) in a windows form application(map editor), but then I realized there is c++ windows forms. So if that simplifies the answer at all, great!
The reason passing classes around between DLLs and executables without using interface is "bad" is simply this:
Its highly compiler dependent. If your DLLs are always built with the same compiler using the same build settings (release/debug, etc), then it should be all fine and dandy. But that means your DLLs are pretty much useless outside of that scenario. This is because name mangling, object layout, heck even packing differs from compiler to compiler and even from version to version.
The advantage of interfaces is that they are typically all implemented in an identical fashion. While C++ doesn't have an ABI, COM does enforce an ABI on COM interfaces, and almost every C++ compiler on the planet can produce and consume COM interfaces.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX
ScapeCode - Blog | SlimDX
#6 Members - Reputation: 114
Posted 03 February 2012 - 08:21 PM
Slig Commando, on 02 February 2012 - 08:43 PM, said:
As the title states. The only solution I have come across is to create a wrapper class in C++ managed of the dll object. But honestly I dont know what that means(I do, but not technically). Could someone explain the conecpt in the thread title to me? Thank you.
I can recommend this three-parter, it's relatively recent so you can also try contacting the author if you have any questions:
http://blogs.microso...-unmanaged.aspx
http://blogs.microso...to-managed.aspx
http://blogs.microso...er-options.aspx


















