Dinamically linking problem

Hey, I hope this does not arrive two time.
I have just sended it but it appear to not being arrived.
Sorry for evantually double reception.

Hi to everyone.

I’m new in SDL programming, and I’ve some problem in using the DLL

I’m using VC 6.0 on win32.

I’ve tried to write a program with SDL, and it work without problem if I link statically the
library (including the .lib files).
Now I was trying to link dinamically the library, but I’m in trouble with this, I’ve read
some documentation and I’ve found that I’ve to use the LoadLibrary() function to load
the dll module, the LoadLibrary is defined in winbase.h, but during the compiling
session it give me a lot of error about this header (for example it does not know the
DWORD type). Have I to include some other header or something else to link
dinamically the dll?!

Thanks in advance.

Emanuele.

a VERY long shot…
Before any other headers (like winbase.h, SDL.h, etc.) do this:

#include <windows.h>

// other headers go here

let me know if it sorted out your problem…

cheers,
k.> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
emanuele.dalmasso at libero.it
Sent: 29 April 2004 16:25
To: sdl at libsdl.org
Subject: [SDL] dinamically linking problem

Hey, I hope this does not arrive two time.
I have just sended it but it appear to not being arrived.
Sorry for evantually double reception.

Hi to everyone.

I’m new in SDL programming, and I’ve some problem in using the DLL

I’m using VC 6.0 on win32.

I’ve tried to write a program with SDL, and it work without problem if I
link statically the
library (including the .lib files).
Now I was trying to link dinamically the library, but I’m in trouble with
this, I’ve read
some documentation and I’ve found that I’ve to use the LoadLibrary()
function to load
the dll module, the LoadLibrary is defined in winbase.h, but during the
compiling
session it give me a lot of error about this header (for example it does not
know the
DWORD type). Have I to include some other header or something else to link
dinamically the dll?!

Thanks in advance.

Emanuele.

SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi to everyone.
I’m new in SDL programming, and I’ve some problem in using the DLL

I’m using VC 6.0 on win32.

I’ve tried to write a program with SDL, and it work without problem if I link statically the
library (including the .lib files).
Now I was trying to link dinamically the library, but I’m in trouble with this, I’ve read
some documentation and I’ve found that I’ve to use the LoadLibrary() function to load
the dll module, the LoadLibrary is defined in winbase.h, but during the compiling
session it give me a lot of error about this header (for example it does not know the
DWORD type). Have I to include some other header or something else to link
dinamically the dll?!

Thanks in advance.

Emanuele.

You should should include windows.h

It will give you (almost) everything you need
to do win32 development. Including LoadLibrary()
correct definitions.–
Paulo Pinto

emanuele.dalmasso at libero.it wrote:

Hey, I hope this does not arrive two time.
I have just sended it but it appear to not being arrived.
Sorry for evantually double reception.

Hi to everyone.
I’m new in SDL programming, and I’ve some problem in using the DLL

I’m using VC 6.0 on win32.

I’ve tried to write a program with SDL, and it work without problem if I link statically the
library (including the .lib files).
Now I was trying to link dinamically the library, but I’m in trouble with this, I’ve read
some documentation and I’ve found that I’ve to use the LoadLibrary() function to load
the dll module, the LoadLibrary is defined in winbase.h, but during the compiling
session it give me a lot of error about this header (for example it does not know the
DWORD type). Have I to include some other header or something else to link
dinamically the dll?!

Thanks in advance.

Emanuele.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

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

Make sure that your function pointers agree with the
SDL prototypes. GetError returns a character
pointer, not an integer. Also, SDL libraries use the
C calling convention, not the Win32 call convention.
So, replace your CALLBACK, with SDLCALL (or nothing:
c.f begin_code.h). Taking a look at SDL_main.h. It
shows that when using SDL under WinMain (which you
might have to do), you should call
SDL_SetModuleHandle(). I think it has something to do
with DirectInput, but I can’t remember. Everything
should work out fine. Go to
http://www.function-pointer.org/ for more info on
dealing with function pointers.

— emanuele.dalmasso at libero.it wrote:

#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


Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs
http://hotjobs.sweepstakes.yahoo.com/careermakeover

It sounds like you need to include <windows.h>

You don’t need to use loadlibrary to use the dll-files though. All you
need to do, is in the Project Settings/“C/C++”/“Use run-time library” to
set “Multithreaded DLL”. That, and linking to SDL.lib and SDLmain.lib
works like a charm.

Regards,
\Mikkel GjoelOn Thu, 29 Apr 2004 emanuele.dalmasso at theboz.it wrote:

Now I was trying to link dinamically the library, but I’m in trouble with this, I’ve read
some documentation and I’ve found that I’ve to use the LoadLibrary() function to load
the dll module, the LoadLibrary is defined in winbase.h, but during the compiling
session it give me a lot of error about this header (for example it does not know the
DWORD type). Have I to include some other header or something else to link
dinamically the dll?!

Hi, thanks for reply

Tue May 4 11:11:27 2004 Damien A Wrote:

Make sure that your function pointers agree with the
SDL prototypes. GetError returns a character
pointer, not an integer. Also, SDL libraries use the

Yes, well, it was only a first try to make it work

C calling convention, not the Win32 call convention.
So, replace your CALLBACK, with SDLCALL (or nothing:

Mmh, can it work? if I load the library dinamically, the definition of SDLCALL is not still knowen during the linking fase. I’ve to try it.

c.f begin_code.h). Taking a look at SDL_main.h. It
shows that when using SDL under WinMain (which you
might have to do), you should call

I have to use the winMain() instead of using the main?
One reason I would like to use SDL is to write code in standard way!

SDL_SetModuleHandle(). I think it has something to do
with DirectInput, but I can’t remember. Everything
should work out fine. Go to
http://www.function-pointer.org/ for more info on
dealing with function pointers.

Uhmm, if I have to rewrite all declaration of function to make it work, I think I have to rewrite all of them for every single different OS, and if I have to use winmain (instead main) then I think I have to use all the specifically version for every single OS.
I would like to use sdl to have to use only one code for every OS.
In this case I think I’ll go to write code with normal windows function!!

— Emanuele Dalmasso <emanuele.dalmasso at libero.it>
wrote:

So, replace your CALLBACK, with SDLCALL (or
nothing:

Mmh, can it work? if I load the library dinamically,
the definition of SDLCALL is not still knowen during
the linking fase. I’ve to try it.

Perhaps I don’t follow you, but if I do, perhaps I can
expalin something. SDLCALL is a C macro (like
#define.) C macros are only used by your preprocessor,
which happens before compilation, which in turn
happens before linking.

I have to use the winMain() instead of using the
main?
One reason I would like to use SDL is to write code
in standard way!

To my understanding, SDL now has a module (it’s either
an object to link with or a header or both, I
personally don’t know because I can’t find much
information on it at the moment.) This module is
called SDLmain or something like that. What I do know,
I have learned from reading the SDL source code.

If you include SDL_main.h, SDL_main.h before defining
a main routine, it will transparently rename it to
another function name like sdl_main. That function, I
belive, exists in a separate object file. Now your
version of the sdl_main object file is dependant on
your system. The implementation of sdl_main is
dependant on how an SDL application must start up in
your system. This way, you can write the SAME code on
ALL operating systems, and SDL will take care of the
rest. Please, someone else on the list correct me if
I’m wrong about something.

Uhmm, if I have to rewrite all declaration of
function to make it work, I think I have to rewrite
all of them for every single different OS, and if I
have to use winmain (instead main) then I think I
have to use all the specifically version for every
single OS.
I would like to use sdl to have to use only one code
for every OS.
In this case I think I’ll go to write code with
normal windows function!!

If I understand you correctly, this is in reference to
the SDLCALL macro. That macro is defined differently
on different operating systems. Therefore, your source
code can be the same on all operating systems, and
just as above with sdl_main, SDL will take care of the
rest.

I hope I was able to help. And on a side note, if
someone can help me find an object or library
containing SDL_main for OS X Panther, I’d REALLY
appreciate it! I do not want to use XCode or
Objective-C, so nothing I have found pertaining to
SDL_main has helped me much.__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/