Discussion:
Problem with USER32.DLL
(too old to reply)
David Erbas-White
2005-02-08 23:25:26 UTC
Permalink
I'm trying to create one executable that will run on multiple operating
systems (I have to support Win95 and up). I recently added usage of
'RegisterDeviceNotification' for some uses. I don't call that routine
if the Win32Platform variable doesn't indicate NT or higher, but it is
apparently still looking for (or referring to) part of the
'RegisterDeviceNotification' call.

The error that I get is "... file is linked to missing export
USER32.DLL:RegisterDeviceNotificationA"

Obviously, the RegisterDeviceNotification is not supported on Win95, but
I'm unclear how to address this problem. Any assistance would be
appreciated.

David Erbas-White
Ed Mulroy [TeamB]
2005-02-09 05:04:15 UTC
Permalink
Getting around that isn't too difficult.

The problem is that for any Windows supplied functions you use the linker
will bundle their definitions as found in the import library into your
executable. When you called RegisterDeviceNotification in an Ascii program
it bundled int he symbol RegisterDeviceNotificationA. When you tried to run
under Windows 95, the program loader was unable to find the address of such
a function to place into your exe file and an error is generated.

The solution is to explicitly link to that function. Doing that involves
these steps:

- Create a pointer to the function
- Load the DLL with LoadLibrary and save the
module handle it returns
- Using that module handle load the function
address and save it to the pointer

Now run your program as normal, calling the function via the pointer

At the end call FreeLibrary to unload the DLL.

However what you need to do here is even more simple. All Windows programs
already load user32.dll. You need not load it. All you need do is call
GetModuleHandle to get the handle and because you did not load it, you do
not free it.

So your code would look something like this:

// typedef used to simplify the code
typedef HDEVNOTIFY (* WINAPI RegDevNoteType)
(HANDLE, void *, DWORD);

RegDevNoteType pRegisterDeviceNotification;

HMODULE user_hand = GetModuleHandle("user32.dll");

pRegisterDeviceNotification = (RegDevNoteType)
GetProcAddress(user_hand, "RegisterDeviceNotificationA");

-----now use pRegisterDeviceNotification only if it is not NULL-----
-----and it will be NULL under Windows 95----

I hope I've been clear. If not, please tell me what to redo to better
explain it.

. Ed
Post by David Erbas-White
I'm trying to create one executable that will run on multiple operating
systems (I have to support Win95 and up). I recently added usage of
'RegisterDeviceNotification' for some uses. I don't call that routine
if the Win32Platform variable doesn't indicate NT or higher, but it is
apparently still looking for (or referring to) part of the
'RegisterDeviceNotification' call.
The error that I get is "... file is linked to missing export
USER32.DLL:RegisterDeviceNotificationA"
Obviously, the RegisterDeviceNotification is not supported on Win95, but
I'm unclear how to address this problem. Any assistance would be
appreciated.
David Erbas-White
2005-02-09 07:45:51 UTC
Permalink
Ed Mulroy [TeamB] wrote:

You've explained it VERY well. I'll give it a try in the morning, and
if I have further questions I'll get back to you. THANKS!!!

David Erbas-White
David Erbas-White
2005-02-09 16:25:28 UTC
Permalink
Ed Mulroy [TeamB] wrote:

Follow-up: it worked great, thanks enormously!

David Erbas-White

Loading...