Loading a DLL at runtime?

Started by
11 comments, last by Tree Penguin 19 years, 8 months ago
Isn't there anyone who can help me?

Any help would be greatly appreciated! This is starting to piss me off.

Lets list my problem a little better:

I got a DLL with this function:

__declspec(dllexport) int gameStartGame(void){
// blabla
return 1;
}

I want to load that dll at runtime, using LoadLibrary, i do it like this and it works (at least, it doesn't return NULL):

module=LoadLibrary(file);

Then i want to get a pointer to the function i mentioned earlier (gameStartGame) like this:

typedef int (*GAMESTARTGAMEPROC) (void);
GAMESTARTGAMEPROC gameStartGame;

//...

gameStartGame=(GAMESTARTGAMEPROC)GetProcAddress(module,"gameStartGame");

And it is NULL, with the error (127) can't find the specified procedure.

As i said any help will be appreciated very much!

EDIT: After LoadLibrary this error is set (and before a different unsignificant error):
ERROR 6: The handle is invalid.
Does that help?

EDIT2: I now use LoadLibraryEx and i get no errors (0: Succeeded)

[Edited by - Tree Penguin on August 21, 2004 3:06:49 PM]
Advertisement
Define your function like this:
extern "C" __declspec(dllexport) gameStartGame(){...}


This guarantees it doesn't get C++ name decoration (i.e. its name remains 'gameStartGame' in the DLL)

That fixed it, thank you very much!

This topic is closed to new replies.

Advertisement