Click to See Complete Forum and Search --> : Access Violation error


drk76
January 26th, 2004, 01:01 AM
Hi Everyone,

I am using SetWindowLong() function to override the default window proc of another application.
Everything works fine I am able to process some of the message sent to the application.
Now I want to automaticaly setback the Orignal window proc using SetWindowLong() the application unloads my dll.
I have tried putting the code(SetwindowLong) in DllMain()--under DLL_PROCESS_DETACH. but the application crashes. When I do this.

While I run it in Debug mode
I am getting a Access Violation Error.
please help.....
drk76

Myself dot NET
January 26th, 2004, 02:34 AM
From MSDN on DLL initialization/termination tasks:

Calling imported functions other than those located in Kernel32.dll may result in problems that are difficult to diagnose. For example, calling User, Shell, and COM functions can cause access violation errors, because some functions in their DLLs call LoadLibrary to load other system components. Conversely, calling those functions during termination can cause access violation errors because the corresponding component may already have been unloaded or uninitialized.

SilentJackqh
January 26th, 2004, 12:13 PM
Sets a new address for the window procedure.
Windows NT/2000 or later: You cannot change this attribute if the window does not belong to the same process as the calling thread.

From MSDN

Myself dot NET
January 26th, 2004, 10:30 PM
The window does belong to the same process as the calling thread because his DLL is loaded in the address space of that process, so a thread in that process is running his code.

The problem is calling SetWindowLong() from the DLL_PROCESS_DETATCH notification, as Microsoft states not to. DLL initialization/termination handlers should perform simple tasks only, and should not rely on DLL's other than kernel32.dll.