Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. WindProc function in DLL ?

WindProc function in DLL ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ranojay
    wrote on last edited by
    #1

    Dear friends Is it possible to add a WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) or a DefWindowProc( HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam) function inside a DLL, The reason is My application wants to handle WM_USER messages but only when the DLL is loaded, So I need to have the function there in the DLL, If my Main application recieves the event it will use this handler to process this. Is this possible...if so ..How....? please Help Ranojay

    L 1 Reply Last reply
    0
    • R Ranojay

      Dear friends Is it possible to add a WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) or a DefWindowProc( HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam) function inside a DLL, The reason is My application wants to handle WM_USER messages but only when the DLL is loaded, So I need to have the function there in the DLL, If my Main application recieves the event it will use this handler to process this. Is this possible...if so ..How....? please Help Ranojay

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Ranojay wrote:

      Is this possible...if so ..How....?

      Sure, its called a subclassing. 1.) Create a WindowProc Function[^] in your DLL which looks something like this[^]. Dont forget to add the WM_USER+[number] case. 2.) After you load your DLL you need to call the SetWindowLongPtr Function[^] with the GWLP_WNDPROC index. Best Wishes, -David Delaune

      R 1 Reply Last reply
      0
      • L Lost User

        Ranojay wrote:

        Is this possible...if so ..How....?

        Sure, its called a subclassing. 1.) Create a WindowProc Function[^] in your DLL which looks something like this[^]. Dont forget to add the WM_USER+[number] case. 2.) After you load your DLL you need to call the SetWindowLongPtr Function[^] with the GWLP_WNDPROC index. Best Wishes, -David Delaune

        R Offline
        R Offline
        Ranojay
        wrote on last edited by
        #3

        Thanks a lot friend, I did add a DefWndProc function but , the control does'nt reach there, I mean how do I make this function understand that this belongs to this particular window. In case of writing program with WinMain we explicitrly specify this, but how to do that in this case.. and also regarding the "WM_USER + nuber" type of messages, I use SenMessage with HWND_BROADCAST option, but for some reason The event handler doesnt seem to respond please help Ranojay

        L 1 Reply Last reply
        0
        • R Ranojay

          Thanks a lot friend, I did add a DefWndProc function but , the control does'nt reach there, I mean how do I make this function understand that this belongs to this particular window. In case of writing program with WinMain we explicitrly specify this, but how to do that in this case.. and also regarding the "WM_USER + nuber" type of messages, I use SenMessage with HWND_BROADCAST option, but for some reason The event handler doesnt seem to respond please help Ranojay

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Hi Ranojay, I have some questions: Did you check the return value of SetWindowLongPtr? Did your process create the window you are trying to subclass? Could you show me the code where you call SetWindowLongPtr? It is almost never a good idea to use HWND_BROADCAST. Why do you need to broadcast a window message? Could you describe why you need to broadcast a message to all top level windows? Best Wishes, -David Delaune

          R 1 Reply Last reply
          0
          • L Lost User

            Hi Ranojay, I have some questions: Did you check the return value of SetWindowLongPtr? Did your process create the window you are trying to subclass? Could you show me the code where you call SetWindowLongPtr? It is almost never a good idea to use HWND_BROADCAST. Why do you need to broadcast a window message? Could you describe why you need to broadcast a message to all top level windows? Best Wishes, -David Delaune

            R Offline
            R Offline
            Ranojay
            wrote on last edited by
            #5

            Dear David Actually the project I am working on is Quite complicated and is made with Qt. But whatever the GUI mechanism be I should be able to intercept windows events right ? I havent used SetWindowLongPtr, as I do not know how to use it. I want to broadcast a particular WM_USER event and I need to have the handler only in my application..So even if all the top level windows recieve it, but Only my dll will be able to process it. Please help me with WM_USER and HWND_BROADCAST mechanism... with lots of thanks Ranojay

            L 1 Reply Last reply
            0
            • R Ranojay

              Dear David Actually the project I am working on is Quite complicated and is made with Qt. But whatever the GUI mechanism be I should be able to intercept windows events right ? I havent used SetWindowLongPtr, as I do not know how to use it. I want to broadcast a particular WM_USER event and I need to have the handler only in my application..So even if all the top level windows recieve it, but Only my dll will be able to process it. Please help me with WM_USER and HWND_BROADCAST mechanism... with lots of thanks Ranojay

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Ranojay wrote:

              But whatever the GUI mechanism be I should be able to intercept windows events right ?

              Absolutely.

              Ranojay wrote:

              I havent used SetWindowLongPtr, as I do not know how to use it.

              Well, that explains why your not successfully hooking/subclassing the window. Have I not given you enough information? Here are a few more links regarding subclassing: Windows subclassing and hooking with C++ classes[^] Simple mapping of WndProc to your specific class' WndProc - Part 1[^]

              Ranojay wrote:

              Please help me with WM_USER and HWND_BROADCAST mechanism...

              Ranojay, WM_USER ranged messages should *never* be broadcast to all top level windows. This type of behavior is every programmers worst nightmare. Please read this MSDN documentation: WM_APP Notification[^] As you see WM_USER through 0x7FFF are reserved for an applications internal messages. You need to call the RegisterWindowMessage Function[^] which uses 0xC000 through 0xFFFF to avoid causing problems with other applications. Best Wishes, -David Delaune

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups