CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    6

    Access Violation error

    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

  2. #2
    Join Date
    Apr 2002
    Posts
    86
    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.

  3. #3
    Join Date
    Jun 2003
    Posts
    58
    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

  4. #4
    Join Date
    Apr 2002
    Posts
    86
    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.
    Last edited by Myself dot NET; January 26th, 2004 at 11:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured