Jump to content
  • Advertisement
Sign in to follow this  
beebs1

DLL Files

This topic is 4055 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya, I'm having some trouble using a DLL dynamically. I have created the DLL exporting it's function like so:
extern "C" __declspec (dllexport) VOID CALLBACK ShowMessage();
The client loads it with the following code:
typedef void (WINAPI *SHOWMESSAGE)();

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nShowCmd )
{
    HINSTANCE hDLL;
    hDLL = LoadLibrary("test.dll");

    if( !hDLL ) { handle error... }

    SHOWMESSAGE _ShowMessage = NULL;
    _ShowMessage = (SHOWMESSAGE)GetProcAddress(hDLL, TEXT("ShowMessage"));

    if( !_ShowMessage ) { handle error... }

    // etc.

}
The call to GetProcAddress() always seems to fail, and I'm not sure why. If anyone could suggest anything it would be much appreciated. Many thanks :)

Share this post


Link to post
Share on other sites
Advertisement
Try

_ShowMessage = (SHOWMESSAGE)GetProcAddress(hDLL, TEXT("_ShowMessage@0"));

if that succeeds then you need to change the dll compilation settings so that it uses undecorated function names.

Share this post


Link to post
Share on other sites
A couple of very useful (and freely available) utilities to use when working with dlls are Dependency Walker, which makes it very easy to check out the export and import tables of dlls and which includes a profiler that tracks dynamically loaded dlls. And Process Explorer which will makes it very easy to examine the various modules loaded into a particular process.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!