I want to create a dll in C++ (NOT MFC) in a way so that others can use the functionality that i've build in my dll. So with other words, when someone is programming C#, he should be able to add my DLL as reference and have access to the functions of that dll.
Now i've read a topic about that here on how to do that:
http://www.codeguru.com/forum/showthread.php?t=231254
So all i have to do according to that post is declare my functions as extern "C" and create a DEF file. But i have a question about using extern "C".
I have a main.cpp file in my dll which has the folliwing main code:
I also have to other files, test.h and test.cpp. The headerfile contains the structure of my class:Code:BOOL WINAPI DllMain(HINSTANCE hInstance,DWORD fwdReason, LPVOID lpvReserved) { switch(fwdReason) { case DLL_PROCESS_ATTACH: break; case DLL_THREAD_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_DETACH: break; } return(TRUE); // The initialization was successful, a FALSE will abort // the DLL attach }
and the sourcefile has the logic of my class:Code:class cTest { public: void MyFunc ( ); }
So my question now is, how do i use extern "C" in my case?? What i want is when others use my DLL is that they have access to my classes. So that they can simply say something like this in their application:Code:void cTest::MyFunc ( ) { MessageBox ( NULL, "The test worked!", "Test", MB_OK ); }
cTest test = new cTest();
test.MyFunc();
Do i just encapsulate my entire class in a extern "C" block?? like so:
Or can i only use structs in this case??Code:extern "C" { //my entire class //comes in here }
Well, i really hope someone here can help me out with my questions
Thanks for any help!





Reply With Quote