Necessity of SDL_RegisterApp?

I’ve been working with the “SDL_RegisterApp” business recently.
I’m trying to figure out if it is really needed. in my case it
would appear not (with an NT4 and Win98 system), but I’m sure
there’s plenty of cases where it’s needed. if we look in
wincommon/SDL_sysevents.c, line 426, we see this code…

/* This function needs to be passed the correct process handle
by the application. The following call just returns a handle
to the SDL DLL, which is useless for our purposes and causes
DirectInput to fail to initialize.
if ( ! hInst ) {
hInst = GetModuleHandle(NULL);

this code allows the user to pass NULL for the module’s handle,
but it comes with a stern warning that it won’t work.
that’s where i’m a little puzzled. for me it is working great.
calling SDL_RegisterApp myself, passing NULL for hInst has
taken care of all my input problems on both my win98 and nt4
maybe i’m just gettin real lucky and it “shouldn’t” be working,
but it seems pretty stable for now
the question then is, does the current SDL need the ModuleHandle
from the hosting application, or can it just get the handle for
itself? if it doesn’t need info from the hosting application, it
seems we could call SDL_RegisterApp from SDL internally and not
bother the hosting application with it at all?
with this we could remove the heavy reliance on requiring SDLmain
to handle the dirty initializing work for us?

of course, this all seems to fly in the face of the warning
comment here, so i’m suspect this could still be a very bad idea.

perhaps the author of this comment can shed some light on the
situation? it would be a pretty scary change to remove the need
for this call. but if it is possible, it seems like it would be
worth pursuing.

I’ve been working with the “SDL_RegisterApp” business recently.

Well, if you look at D??_CreateWindow(), you’ll see that they actually
call SDL_RegisterApp() themselves, so if you don’t call it from WinMain()
then it gets called later with a NULL hInst argument.

As you can see looking over the threads mentioning that they don’t get
keyboard input on NT, you’ll find that this isn’t good enough - people
need to actually pass the handle of the process, and not the DLL.

It’s worth persuing, but I’m hesitant to remove the code in WinMain()
without extensive testing on a wide variety of platforms.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software