SDL_VIDEO_WINDOW_POS under XP

I am trying to get the SDL_VIDEO_WINDOW_POS environment variable to
work with no luck.

I set the variable in my program with:

putenv(“SDL_VIDEO_WINDOW_POS=10,10”);
SDL_Surface *s = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE);

But it is never picking it up. I’ve compiled the sdl.dll and traced
through it, and when it gets to the place where it does a getenv(), it
comes back NULL.

Is this an issue with the DLL having the app’s original environment
space, and not the space modified by the program? If so, how is this
expected to work?

If I set the environment variable at the prompt, and then run the
program it works.

Is there a way to set this variable from within the running program?
It’s not really practical to have the user of my program setting
environment variables, or wrapping the launching of the program in a
.bat file.

Tankko

Under Windows and a few other platforms, SDL has it’s own special
getenv/putenv functions. You need to include SDL_getenv.h to ensure that
you’re calling the correct putenv function for your platform.On Sunday 24 April 2005 17:14, Tankko Omaskio wrote:

I am trying to get the SDL_VIDEO_WINDOW_POS environment variable to
work with no luck.

I set the variable in my program with:

putenv(“SDL_VIDEO_WINDOW_POS=10,10”);
SDL_Surface *s = SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE);

But it is never picking it up. I’ve compiled the sdl.dll and traced
through it, and when it gets to the place where it does a getenv(), it
comes back NULL.

Is this an issue with the DLL having the app’s original environment
space, and not the space modified by the program? If so, how is this
expected to work?

Under Windows and a few other platforms, SDL has it’s own special
getenv/putenv functions. You need to include SDL_getenv.h to ensure that
you’re calling the correct putenv function for your platform.

Thanks! I just got done hacking another way to do this (putting the
xpos,ypos in the upper 16 bits of the width,height).

I just took a look at this, and for Win32, the SDL_getenv/SDL_getenv
is #if’d out, it just reverts to getenv/putenv. While this will work
on the Mac, CE, etc, it doesn’t do anything on Win32? Or am I
mistaken?

If I force the extern on SDL_putenv, I get a undefined symbol during linking.

I’ve spent the last few hours looking at this, and the DLL is loaded
before my WinMain is ever run, and the DLL picks up the enviornment at
that point, so there is no way that my program can set enviornment
variables that SDL.DLL will ever see.

Is anyone else able to set enviornment variables in their programs and
have them read by sdl.dll?

Tankko

Under Windows and a few other platforms, SDL has it’s own special
getenv/putenv functions. You need to include SDL_getenv.h to ensure that
you’re calling the correct putenv function for your platform.

Thanks! I just got done hacking another way to do this (putting the
xpos,ypos in the upper 16 bits of the width,height).

I just took a look at this, and for Win32, the SDL_getenv/SDL_getenv
is #if’d out, it just reverts to getenv/putenv. While this will work
on the Mac, CE, etc, it doesn’t do anything on Win32? Or am I
mistaken?

If I force the extern on SDL_putenv, I get a undefined symbol during
linking.
You appear to be correct. Once again I shouldn’t believe everything I
hear. :slight_smile:

I’ve spent the last few hours looking at this, and the DLL is loaded
before my WinMain is ever run, and the DLL picks up the enviornment at
that point, so there is no way that my program can set enviornment
variables that SDL.DLL will ever see.
What do you mean by this? It calls getenv/putenv right inside
DX5_SetVideoMode() in SDL_dx5video.c at runtime, not at DLL load time.On Sunday 24 April 2005 19:45, Tankko Omaskio wrote:

I have found that:
putenv(“SDL_VIDEO_WINDOW_POS=10,10”);
does not seem to work either - under VC 7.1. I regulary test my code to make sure it compiles with MinGW and VC++, and I have noticed that the window position IS set when I compile with MinGW, but not with VC++.

I am using the pre-built binaries for SDL for VC++ and MinGW, so perhaps it is that they were built differently? Other than that, I do not know why the putenv() works as it should with MinGW as opposed to VC++.___________________________________________________________________
Speed up your surfing with Juno SpeedBand.
Now includes pop-up blocker!
Only $14.95/month -visit http://www.juno.com/surf to sign up today!

What do you mean by this? It calls getenv/putenv right inside
DX5_SetVideoMode() in SDL_dx5video.c at runtime, not at DLL load time.

Unless I am mistaken, the routine DX5_SetVideoMode() is contained in
the DLL, and the DLL is loaded automatically when the .exe is run, but
before WinMain is called. Therefore, the DLL gets the environment as
it was when it was loaded, so no changes via putenv will be reflected
in the DLL’s environment. Or at least that’s what my tests show and
is my understanding about how the environment is dealt with in
Windows. Please correct me if I am wrong, and I hope I am, otherwise
there is no way to position the window via code (without my hack and a
custom DLL)

Someone else mentioned that this works under MinGW by not VC. That
could be in how the code is generated that auto loads the DLL. The
MinGW generated code might not load the DLL at the beginning, but
closer to when it is being called, allowing the environment to be read
correctly. Or, the version of getenv that MinGW uses is better then
the one that is used by VC and reads the apps environment, not the
DLL’s.

TankkoOn 4/25/05, Tyler Montbriand wrote:

On Sunday 24 April 2005 19:45, Tankko Omaskio wrote:

Under Windows and a few other platforms, SDL has it’s own special
getenv/putenv functions. You need to include SDL_getenv.h to ensure that
you’re calling the correct putenv function for your platform.

Thanks! I just got done hacking another way to do this (putting the
xpos,ypos in the upper 16 bits of the width,height).

I just took a look at this, and for Win32, the SDL_getenv/SDL_getenv
is #if’d out, it just reverts to getenv/putenv. While this will work
on the Mac, CE, etc, it doesn’t do anything on Win32? Or am I
mistaken?

If I force the extern on SDL_putenv, I get a undefined symbol during
linking.
You appear to be correct. Once again I shouldn’t believe everything I
hear. :slight_smile:

I’ve spent the last few hours looking at this, and the DLL is loaded
before my WinMain is ever run, and the DLL picks up the enviornment at
that point, so there is no way that my program can set enviornment
variables that SDL.DLL will ever see.
What do you mean by this? It calls getenv/putenv right inside
DX5_SetVideoMode() in SDL_dx5video.c at runtime, not at DLL load time.


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

I decided to go check this behavior before going shooting off my mouth again,
and sure enough, It Doesn’t Work™. The only way I got it to work was with
a custom build of SDL with NEED_SDL_GETENV defined. It doesn’t seem to be
defined under windows by default, but maybye it should be.On Monday 25 April 2005 17:43, Tankko Omaskio wrote:

Unless I am mistaken, the routine DX5_SetVideoMode() is contained in
the DLL, and the DLL is loaded automatically when the .exe is run, but
before WinMain is called. Therefore, the DLL gets the environment as
it was when it was loaded, so no changes via putenv will be reflected
in the DLL’s environment. Or at least that’s what my tests show and
is my understanding about how the environment is dealt with in
Windows. Please correct me if I am wrong, and I hope I am, otherwise
there is no way to position the window via code (without my hack and a
custom DLL)

Hi,

Refering to an old topic title (april 2005) I was unable to use this environment
variable to set the default location of the window at startup.
To solve this the following code works, but is of course platform dependant:

SetWindowPos(GetForegroundWindow(),HWND_NOTOPMOST,0,0,width,height,SWP_NOCOPYBITS|SWP_SHOWWINDOW);

This call proves that the SDL_SetVideoMode can use SetWindowPos. The problem I
have is the environment variable. getenv always returns NULL, even when I set
it in the My Computer properties of windows.

A solution is to enable NEED_SDL_GETENV. This obviously works. Now I got the
implemntation changed a little to always use the SDL_getenv variable and also
checking the getenv (same for putenv) within this function. More or less I’m
now creating and filling SDL_env char array from SDL_getenv.c with the
neccesary getenv windows variables.
Is this a possible good solution for the problems that arise with getenv under
XP ?

Another option would be to create another SDL_WM_SetWindowPosition function.
Actually I’d like to see both implemented.

John Beuving