Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4015096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:34:38+00:00 2026-05-20T09:34:38+00:00

I am trying to send user registered message to window procedure, procedure receives a

  • 0

I am trying to send user registered message to window procedure, procedure receives a message but it fails to see that its specific registered message i am sending.

So from start… I make sure that all dll instances share the meessage.

#pragma data_seg (".shared")
...
...
UINT    WM_HOOKEX = 0;
...
#pragma data_seg ()
#pragma comment(linker,"/SECTION:.shared,RWS")

In dllmain i make sure its only registered once

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    if( ul_reason_for_call == DLL_PROCESS_ATTACH ) 
    {
        hDll = (HINSTANCE) hModule; 
        //DisableThreadLibraryCalls( hDll );

        if( WM_HOOKEX==NULL )
            WM_HOOKEX = ::RegisterWindowMessage( _T("WM_HOOKEX_RK") );          
    }

    return TRUE;
}

Later with exported dll function(that shares dll and the message) that i use in my app i hook to the procedure of the desired window and send it this message with

SendMessage( plist,WM_HOOKEX,0,1 );

The hooked procedure receives the message(as i am inspecting it with dll debugging) but it fails to see what message it is. Dll debugging shows that the thread has the message registered in its memory though but procedure doesnt recieve correct message parameters.

Also i am sure it is receiving this message and not some other one because this is the only message directed to the procedure that i invoke, so i leave out the possibility that my custom mssg might still be in queue, then why i wonder why for several days now, why is it not receiving message as it should even debugging shows that it holds the custom message in its memory!

This is the procedure that recieves it(or actually doesnt)

#define pCW ((CWPSTRUCT*)lParam)

LRESULT HookProc (
  int code,       // hook code
  WPARAM wParam,  // virtual-key code
  LPARAM lParam   // keystroke-message information
)
{
    if( (pCW->message == WM_HOOKEX) && pCW->lParam ) 
    {
        ::UnhookWindowsHookEx( g_hHook );

        if( g_bSubclassed ) 
            goto END;       // already subclassed?

        // Let's increase the reference count of the DLL (via LoadLibrary),
        // so it's NOT unmapped once the hook is removed;
        TCHAR lib_name[MAX_PATH]; 
        ::GetModuleFileName( hDll, lib_name, MAX_PATH );

        if( !::LoadLibrary( lib_name ) )
            goto END;       

        // Subclass START button
        OldProc = (WNDPROC) 
            ::SetWindowLong( g_hWnd, GWL_WNDPROC, (long)NewProc );
        if( OldProc==NULL )         // failed?
            ::FreeLibrary( hDll );
        else {                      // success -> leave "HookInjEx.dll"
            ::MessageBeep(MB_OK);   // mapped into "explorer.exe"
            g_bSubclassed = true;
        }       
    }
    else if( pCW->message == WM_HOOKEX ) 
    {
        ::UnhookWindowsHookEx( g_hHook );

        // Failed to restore old window procedure? => Don't unmap the
        // DLL either. Why? Because then "explorer.exe" would call our
        // "unmapped" NewProc and  crash!!
        if( !SetWindowLong( g_hWnd, GWL_WNDPROC, (long)OldProc ) )
            goto END;

        ::FreeLibrary( hDll );

        ::MessageBeep(MB_OK);
        g_bSubclassed = false;  
    }

END:
    return ::CallNextHookEx(g_hHook, code, wParam, lParam);
}

I suspect all of this has to do with the fact that i am sending the message with exported function which i call from my app. If i do this with function from the example app that came with original project, it uses imported function i think so perhaps exported function might be the cause.

Also i am unable to test imported function as its from another language.

edit:

So i also tried to register mssg everytime as someone here suggested but it made no differene, the weird thing here is that everything works fine if i call the function which hooks and sends the mssg internally, this is the header of the function that the gui app uses(in this case all works fine)

#if !defined INJECT_EX__H
#define INJECT_EX__H


#ifdef INJECT_EX_EXPORTS
#define HOOKDLL_API __declspec(dllexport)
#else
#define HOOKDLL_API __declspec(dllimport)
#endif


extern int HOOKDLL_API g_bSubclassed;
HOOKDLL_API int InjectDll();
HOOKDLL_API int UnmapDll();

#endif // !defined(INJECT_EX__H)


#define DIPSLIBAPI extern "C" __declspec(dllexport)

// External function prototypes
DIPSLIBAPI BOOL WINAPI SetDIPSHook(BOOL hook_it, BOOL just_save_list, int lobby, int type);

So this is the header that i believe gui app uses injectdll function as imported function and maybe thats why it works? If i use the function as exported without this header then mssg is not seen right.

edit2:

Here are the preprocessor directives from dll project:
_DEBUG
WIN32
_WINDOWS
_USRDLL
INJECT_EX_EXPORTS

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:34:39+00:00Added an answer on May 20, 2026 at 9:34 am

    I’m not entirely clear on what you describe the problem to be. I’m guessing it would correspond to the behavior you’d get if WM_HOOKEX was still 0 in the injected dll. Assuming this is the problem, you need to do the following:

    volatile UINT WM_HOOKEX = 0;
    

    This ensures that the compiler will not optimize references to WM_HOOKEX but rather read it from memory every time you use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to send a PHP email the easy way but I cannot work out
I am trying to send some text from the client's end to the server.
I am trying to send email using apache james with this code public static
I am working on a new app and am trying to customize where Devise
I am using Ruby on Rails 3 and I would like to handle user
I am in the process of learning the MVC pattern in practise, meaning that
CouchDB offers validation prior to allowing an object/row to be inserted into the database.
I've got a web application, deployed on GlassFish 3.0.1, which is using container managed
I'm working on a hobby project consisting of a multi-player web browser game. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.