Creating a Dll that export a class (Solved)

Hello,

Iam new to making dlls in C++ (native dlls), I did create dlls using C#/VB.net which is entirely a different process from creating dlls in C++.

what i found that there are many ways to export a class so that you can use the methods in it in another applications (C++ or .net applications or both).

ways that i have found are by using an interface, using loadlibrary and malloc, using wrapper class (C++/CLI) and finally the old C way by exporting bridge methods (extern "C").

I dont want to learn all of them. what i want is someone to tell me how every way will end up on the client side so that i can decide which way to choose. for example if I went with the C approach (extern "C" functions) on the client side the usage will require passing the object created by the factory method as a parameter to the exported method. maybe providing a segment of the client code for each way will be nice...

What I really hope for is making a dll (or two dll files native + CLI) that the developers can use at the end as if they are using a class defined by their code, like this ClassName.Method() or CLassName->Method() for C++

thanks for any help you can provide...
Last edited on
Under Windows it's easy to export a class from a DLL.
Just modify the class' header the following way:
1
2
3
4
5
6
7
8
9
10
#ifdef MAKING_DLL
    #define DLL_API  __declspec(dllexport)
#else
    #define DLL_API  __declspec(dllimport)
#endif

class DLL_API Myclass
{
    ...
};


You just have to define the "MAKING_DLL" macro when you compile the DLL and make sure that whatever name you choose instead of "MAKING_DLL" won't be defined as a macro by your dll's clients.

Of course you'll have to provide the class header with the DLL.

Microsoft documentation on the topic:
http://msdn.microsoft.com/en-us/library/a90k134d.aspx
http://msdn.microsoft.com/en-us/library/8fskxacy.aspx
what about name mangling or what ever it is called... will providing the class header help in that? also if lets say I made a wrapper class in CLI/C++ and included the header file from my native class... do i need to include the header file for my class so that .net developers can use my class? like do they need to extract some info from it in order to use the class? or is giving them only the two dlls (native + wrapper) enough...

ah cant decide, tell me toum if you were in my place, and you want to distribute a class so that it can be used by both developers (C++ and .net) how would you do it?

finally... thank you very much for your help toum.

You need to provide the class header because it contains the class interface.

As for name mangling, compilers targeting Windows generally use the same as Visual C++.

I don't know anything about .net, so I can't help you on that.
Google is your friend:
http://www.codeproject.com/Articles/42319/Using-NET-Classes-Modules-from-Native-C
http://stackoverflow.com/questions/569603/using-c-class-dll-in-c-sharp-application
okey thanks for the help and the links will do some readings about the topic...

do i need like to mark this thread as solved or something?? Iam new here.
Topic archived. No new replies allowed.