[SDL] SDL_putenv("SDL_WINDOWID=") on Visual Studio 2003.net

Mark R. Stevens mark.r.stevens at verizon.net
Tue Sep 6 19:18:14 PDT 2005

I have been trying to get SDL to draw into a qt widget with moderate 
success. After pouring over the mailing lists, I found the SDL_WINDOWID 
envar for setting the Wid:

       char variable[256];
       sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
       if (::putenv(variable) == -1)
         // ....

However (as many people have pointed out) this does not seem to work as 
a new window pops up with directx. Further digging revealed the problem. 
Since sdl is compiled into a separate dll, it uses a separate 
environmental block than the application and hence the putenv is not 
accessible within the dll.

I then tried:

#include <SDL_getenv.h>

       char variable[256];
       sprintf(variable, "SDL_WINDOWID=0x%lx", winId());
       if (SDL_putenv(variable) == -1)
         // ....

However, this leads to many unstable seg faults. Finally, I hacked 
SDL_getenv.c so that for visual studio, SDL_putenv and SDL_getenv call 
::putenv and ::getenv. This seems to work as they mod the environment 
block of the sdl dll.

Is this the best fix? I am new (about 2 days) to SDL so I feel like I am 
missing something obvious. I can post the mods to the SDL_getenv.{h,c} 
if it would help.



Mark R. Stevens, Ph.D.    mstevens at cra.com
Principal Scientist     1-617-491-3474x570
Charles River Analytics http://www.cra.com

More information about the SDL mailing list