Thanks,
Using windows.h instead of winbase.h LoadLibrary (and the a?other function required to
link dinamically a DLL) works.
But now that I’m trying to compile in this way, I’m in trouble about how to write code, I
think I’m wrong in something (I’ve no experience with DLL use).
Here’s an example of code (it only initialize and close the SDL system):
#include “SDL.h”
#include <windows.h>
typedef int (CALLBACK* FZ_SDL_INIT)(int);
typedef void (CALLBACK* FZ_SDL_QUIT)(void);
typedef int (CALLBACK* FZ_SDL_GETERROR)(void);
#ifdef __cplusplus
extern “C”
#endif
int main(int argc,char **argv){
HINSTANCE hSdlDLL;
FZ_SDL_INIT lpfnDll_SDL_Init;
FZ_SDL_QUIT lpfnDll_SDL_Quit;
FZ_SDL_GETERROR lpfnDll_SDL_GetError;
hSdlDLL = LoadLibrary("SDL.dll");
if(hSdlDLL == NULL){
printf("Cannot find SDL.DLL\n");
exit(1);
}
lpfnDll_SDL_Init = (FZ_SDL_INIT)GetProcAddress(hSdlDLL,"SDL_Init");
lpfnDll_SDL_Quit = (FZ_SDL_QUIT)GetProcAddress(hSdlDLL,"SDL_Quit");
lpfnDll_SDL_GetError = (FZ_SDL_GETERROR)GetProcAddress(hSdlDLL,"SDL_GetError");
// Initialize the SDL library
if( lpfnDll_SDL_Init(SDL_INIT_VIDEO) < 0){
// fprintf(stderr, “Couldn’t initialize SDL: %s\n”, SDL_GetError());
fprintf(stderr, “Couldn’t initialize SDL: %s\n”, lpfnDll_SDL_GetError());
exit(1);
}
// Clean up on exit
// atexit(SDL_Quit);
FreeLibrary(hSdlDLL);
lpfnDll_SDL_Quit();
return 0;
}
I hope there is another way to do it!
I’ve tried at least to remap the function with some fzPointer with the same name, but it
goes wrong. Have I to redefine a pointer for each function I go to use???
Other all I cannot use something like atexit(SDL_Quit), because the function
SDL_Quit() have not an address (it’s named lpfnDll_SDL_Quit ).
Last problem: I cannot link this code because it don’t find “winMain()” function, have I to
remap also this function?
I hope to be wrong in something because to write code in this way is terrible!!! (and I
think is not portable at all !!!)
Sorry for lengh of this post, I’ll try to be shorter next times.
Thanks in advance.–
Emanuele Dalmasso.
On 30 Apr 2004 at 14:24, Paulo Pinto wrote:
You should should include windows.h
It will give you (almost) everything you need
to do win32 development. Including LoadLibrary()
correct definitions.
–
Paulo Pinto