winapi - C++ GetProcAddress not working -


this question has answer here:

i have following code:

typedef int (winapi* fnenginestart)();   int __stdcall enginestart() { bool freeresult = 0, runtimelinksuccess = 0; //variables later use hmodule libraryhandle = 0; //here handle api module/dll stored. fnenginestart fn = 0;  libraryhandle = afxloadlibrary(l"flowengine.dll"); //get handle of our api module //so loaded. if (libraryhandle != null) //if library loading successfull.. {     fn = (fnenginestart)getprocaddress(libraryhandle,         "fnenginestart");     if (runtimelinksuccess = (fn != null)) //if operation successful...     {         int returnvalue = fn(); //call messageboxa function         //from user32.dll     }     else     {         messagebox(0, l"error", 0, 0);     }     freeresult = freelibrary(libraryhandle);     //from process...     return freeresult; //routine successful } return exit_failure; //else, failed } 

this code works example user32.dll , messageboxa not own dll...

int __declspec(dllexport) __stdcall fnenginestart() {    messagebox(0, l"succes!", 0, 0);    return 0; } 

how make work own dll well? in advance.

the issue dealing name mangling. use extern "c" compiler doesn't mangle name. example:

extern "c" int __declspec(dllexport) __stdcall fnenginestart() {    messagebox(0, l"succes!", 0, 0);    return 0; } 

note: __stdcall functions name-decorated leading underscore, followed @, , number (in bytes) of arguments passed on stack. number multiple of 4, on 32-bit aligned machine. source

if compiler supports it, can in dll , should work way have now.

extern "c" int __declspec(dllexport) __stdcall fnenginestart() {    #pragma comment(linker, "/export:" __function__ "=" __funcdname__)    messagebox(0, l"succes!", 0, 0);    return 0; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -