Problem with WM_USER

Hi all,

I have to integrate a third party dll into my sdl application on a Win32
platform. The dll polls for a resource and, to notify that something
happended, it sends a WM_USER to a previously provided window handler. This
handler cannot be the SDL window handler (I tried to, but it doesn’t work).
So, I created a window via CreateWindow API call. I have to run a PeekMessage
loop over that window so it can process the messages, but it seems to conflict
with the SDL_PollEvent loop that I run elsewhere.

The scenario is as follows (the calls are not sintactically correct, but they
can be understood) :

Main thread (my app):
while( true )
{
SDL_PollEvent( ev )
if( ev.type >= SDL_USEREVENT )
SDL_PushEvent( ev );
}

Secondary thread (my app):
hdl = CreateWindow(’’,0,0,0,0,0,0,0,0,0); // fake window
Register3rdPartyDll( hdl );
while( true )
{
// loop for processing the fake window event queue
if( PeekMessage( hdl, WM_USER ) // only processing WM_USER event
{
translatemsg;
dispatchmsg;
}
}

3rd party dll:
register custom Window Proc for the fake window.
Run a thread for polling the resource and post WM_USER to the fake window if
smthg happened
The custom window proc calls my code through a callback when WM_USER is
processed.

The problem is that I get a Memory Exception inside the 3rd party dll in my
main thread when I call the SDL_PollEvent.

Since the SDL_Event struct defines the event type as a UInt8 and WM_USER is
0x0400 (out of range of a uint8 type), i cannot figure out how to bypass the
WM_USER from inside the SDL_PollEvent loop.

Thank you very much for your help.

ALBERT

Albert Fern?ndez Marsal <afmarsal cirsa.com> writes:

Hi all,

I have to integrate a third party dll into my sdl application on a Win32
platform. The dll polls for a resource and, to notify that something
happended, it sends a WM_USER to a previously provided window handler. This
handler cannot be the SDL window handler (I tried to, but it doesn’t work).
So, I created a window via CreateWindow API call. I have to run a
PeekMessage
loop over that window so it can process the messages, but it seems to
conflict
with the SDL_PollEvent loop that I run elsewhere.

The scenario is as follows (the calls are not sintactically correct, but
they
can be understood) :

Main thread (my app):
while( true )
{
SDL_PollEvent( ev )
if( ev.type >= SDL_USEREVENT )
SDL_PushEvent( ev );
}

Secondary thread (my app):
hdl = CreateWindow(’’,0,0,0,0,0,0,0,0,0); // fake window
Register3rdPartyDll( hdl );
while( true )
{
// loop for processing the fake window event queue
if( PeekMessage( hdl, WM_USER ) // only processing WM_USER event
{
translatemsg;
dispatchmsg;
}
}

3rd party dll:
register custom Window Proc for the fake window.
Run a thread for polling the resource and post WM_USER to the fake window
if
smthg happened
The custom window proc calls my code through a callback when WM_USER is
processed.

The problem is that I get a Memory Exception inside the 3rd party dll in my
main thread when I call the SDL_PollEvent.

Since the SDL_Event struct defines the event type as a UInt8 and WM_USER is
0x0400 (out of range of a uint8 type), i cannot figure out how to bypass the
WM_USER from inside the SDL_PollEvent loop.

Thank you very much for your help.

ALBERT

Ok, after some tests, there’s no problem with the events. I tried a simple
program with 2 threads:

1st:
while( true )
{
sdl_pollevent;
sdl_updaterects;
}

2nd:
while( true )
{
process events for fake window;
}

and it works, so forget about the last problem. But something keeps the 3rd
party dll from working. The call to sdl_pollevent provokes a memory exeption
in the 3rd party dll. May it be related to the fact that both calls are in
separate dll’s loaded by my main app? Maybe the window proc can’t be reached
when consuming events?

Thank you.

ALBERT