SDL_WINDOWID hack on win32

I’m trying to make this work but I’m not able to do it…

I’m using SDL 1.2.4, I’ve looked at the sources and I don’t understand
why it doesnt works. SDL always opens it’s window, also with a putenved,
valid, SDL_WINDOWID.

One problem maybe the fact that I cannot use SDL_main in this
application since it’s a DLL, but I’ve looked at the sources in
wincommon/, windib/ and windx5/ and really I don’t understand WHY that
window opens, the correct behaviour should be a crash IMHO, if SDL is
unable to hook to the window I specify since all the code does is a
SDL_Window = strtol(SDL_windowid)!

Here is a piece of the code, what I’m trying to do is an web browser
plugin that use SDL (with ActiveX interface for IE and the NS4 one for
netscape and other borwsers on linux…)

CWnd *w=pdc->GetWindow();
HWND hwnd = w->GetSafeHwnd();

/* this HWND is valid since I can draw in the correct place using
Windows calls like ::FillRect() */

RECT rect;
w->GetWindowRect(&rect);

if(!m_surface) {
char buffer[100];

log( “Window: %lx (%ld,%ld) -> (%ld,%ld)\n”, hwnd, rect.left,rect.top,
rect.right, rect.bottom);

log( “RcBounds (%ld,%ld) (%ldx%ld)\n”, rcBounds.left, rcBounds.top,
rcBounds.Width() , rcBounds.Height());

sprintf(buffer, “SDL_WINDOWID=%ld”, hwnd);
putenv(buffer);
putenv(“SDL_VIDEODRIVER=directx”); /* tried with windib too and
without this line */

log(“Variable SDL_WINDOWID = %s\n”,getenv(“SDL_WINDOWID”));

// tried to init it here or in the class constructor

if(SDL_Init(SDL_INIT_VIDEO)<0) {
log( “Unable to init SDL!\n”);
exit(0);
}

if(!(m_surface = SDL_SetVideoMode(rcBounds.Width(),
rcBounds.Height(), 0, 0))) {
log( “Impossibile aprire la surface SDL!!\n”);
exit(0);
}
}

Bye,
Gabry

sprintf(buffer, “SDL_WINDOWID=%ld”, hwnd);
putenv(buffer);

The C runtime doesn’t keep environment variables in the same place as the
win32 api or something lame like that. This has come up on the list
before:

http://www.libsdl.org/pipermail/sdl/2001-August/037785.html

No idea if that’s your problem, but it’s worth looking into.

–ryan.

Maybe this will help:
http://www.libsdl.org/pipermail/sdl/2002-June/046616.html

RK.

Gabriele Greco wrote:>I’m trying to make this work but I’m not able to do it…

I’m using SDL 1.2.4, I’ve looked at the sources and I don’t understand
why it doesnt works. SDL always opens it’s window, also with a putenved,
valid, SDL_WINDOWID.

One problem maybe the fact that I cannot use SDL_main in this
application since it’s a DLL, but I’ve looked at the sources in
wincommon/, windib/ and windx5/ and really I don’t understand WHY that
window opens, the correct behaviour should be a crash IMHO, if SDL is
unable to hook to the window I specify since all the code does is a
SDL_Window = strtol(SDL_windowid)!

Here is a piece of the code, what I’m trying to do is an web browser
plugin that use SDL (with ActiveX interface for IE and the NS4 one for
netscape and other borwsers on linux…)

CWnd *w=pdc->GetWindow();
HWND hwnd = w->GetSafeHwnd();

/* this HWND is valid since I can draw in the correct place using
Windows calls like ::FillRect() */

RECT rect;
w->GetWindowRect(&rect);

if(!m_surface) {
char buffer[100];

log( “Window: %lx (%ld,%ld) -> (%ld,%ld)\n”, hwnd, rect.left,rect.top,
rect.right, rect.bottom);

log( “RcBounds (%ld,%ld) (%ldx%ld)\n”, rcBounds.left, rcBounds.top,
rcBounds.Width() , rcBounds.Height());

sprintf(buffer, “SDL_WINDOWID=%ld”, hwnd);
putenv(buffer);
putenv(“SDL_VIDEODRIVER=directx”); /* tried with windib too and
without this line */

log(“Variable SDL_WINDOWID = %s\n”,getenv(“SDL_WINDOWID”));

// tried to init it here or in the class constructor

if(SDL_Init(SDL_INIT_VIDEO)<0) {
log( “Unable to init SDL!\n”);
exit(0);
}

if(!(m_surface = SDL_SetVideoMode(rcBounds.Width(),
rcBounds.Height(), 0, 0))) {
log( “Impossibile aprire la surface SDL!!\n”);
exit(0);
}
}

Bye,
Gabry


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