How to set an entry point for dll

At first I thought of an entry point in the DLLMain DLL, but then when I try to import it into C #, I get an error that the entry point was not found. Here is my code:

#include <Windows.h> int Test(int x,int y) { return x+y; } BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: MessageBox(0,L"Test",L"From unmanaged dll",0); case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE; } 

How can I set an entry point for my dll? And if you don't mind, can you give me a little explanation about the entry point?

How do I need to import the same DLL again and change the entry point so that I can use other functions in the same DLL? thanks in advance.

+8
c ++ dll winapi dllimport
source share
1 answer

In your example, it seems that you intend Test () to be an entry point, but you are not exporting it. Even if you start exporting it, it may not work properly with the name "C ++ decoration" (mangling). I would suggest redefining your function as:

 extern "C" __declspec(dllexport) int Test(int x,int y) 

The extern "C" component will remove the C ++ name crash. The __declspec(dllexport) component exports a character.

See http://zone.ni.com/devzone/cda/tut/p/id/3056 for details.

Edit: you can add as many entry points as you want. The call code just needs to know the name of the character to be received (and if you create a static .lib that will take care of this for you).

+10
source share

All Articles