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 6199517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:12:12+00:00 2026-05-24T04:12:12+00:00

I am facing a strange problem regarding Hooking. I have a procedure which acts

  • 0

I am facing a strange problem regarding Hooking. I have a procedure which acts as a hooked procedure in C++/CLI, After SendMessage it unables to hook the procedure, while this is not the behavior while debugging the process in debug mode, when the hooked process is attached, successfully, all the statments of HookedProc will be observed as executed.
I am unable to find the correct behavior.

This behavior is un desireable , as I have to deliver the process and use the process without using VS.

Code :

Object^ Injector::InvokeRemote(IntPtr hWnd, String^ assemblyFile, String^ typeName, String^            methodName, array<Object^>^ args)
{
    RequestMessage^ msg = gcnew RequestMessage();
    msg->AssemblyFile = assemblyFile;
    msg->TypeName = typeName;
    msg->MethodName = methodName;
    msg->Args = args;
    ::Serialize(msg);

    HINSTANCE hinstDLL = LoadLibrary((LPCTSTR) _T("InjectLib.dll"));
    DWORD threadID = GetWindowThreadProcessId((HWND)hWnd.ToPointer(), NULL);
    HOOKPROC procAddress = (HOOKPROC)GetProcAddress(hinstDLL, "MessageHookProc");
    HHOOK messageHookHandle = SetWindowsHookEx(WH_CALLWNDPROC, procAddress, hinstDLL, threadID);

    // This forces it to be loaded into the target adress space
    ::SendMessage((HWND)hWnd.ToPointer(), WM_INVOKEREMOTE, 0, 0);

     TCHAR tValue[100];
     memset(tValue,0,100);
     DWORD ReturnValue = GetLastError();
     _stprintf(tValue,L"%d",ReturnValue);
     String^ strRetVal = gcnew String(tValue);

    ::UnhookWindowsHookEx(messageHookHandle);   

    Object^ retVal = Deserialize();
    return retVal;
}

and the followig one is the hook procedure

int __stdcall MessageHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{   
    try
    {
        if (nCode == HC_ACTION)
        {
            try
            {
                if (pCW->message == WM_INVOKEREMOTE)
                {                                                           
                        String^ assemblyFile = "";
                        Assembly^ assembly = nullptr;
                        AppDomain^ currentDomain = AppDomain::CurrentDomain;
                        currentDomain->AssemblyResolve += gcnew ResolveEventHandler(HelperClass::ResolveRequestMessageAssembly);


                        RequestMessage^ msg = (RequestMessage^)Deserialize();
                        currentDomain->AssemblyResolve -= gcnew ResolveEventHandler(HelperClass::ResolveRequestMessageAssembly);                                                
                        assemblyFile = Path::Combine(Path::GetDirectoryName(Assembly::GetExecutingAssembly()->Location), msg->AssemblyFile);
                        assembly = Assembly::LoadFrom(assemblyFile);                    

                        Type^ type = assembly->GetType(msg->TypeName);              
                        Object^ retVal = type->InvokeMember(msg->MethodName, BindingFlags::Static | BindingFlags::Public | BindingFlags::InvokeMethod, nullptr, nullptr, msg->Args);
                        Serialize(retVal);                                          
                }
            }
            catch(Exception^ ex)
            {               
                 System::Windows::Forms::MessageBox::Show( ex->InnerException->ToString(), L"PAUSE", System::Windows::Forms::MessageBoxButtons::OK);
            }
        }       
    }
    catch(Object^ ex)
    {       
        IntPtr ptr = Marshal::StringToHGlobalUni(ex->ToString());
        LPCTSTR error = reinterpret_cast<LPCTSTR>(ptr.ToPointer());
        ::MessageBox(NULL, error, L"InvokeRemote Failed", MB_ICONERROR | MB_OK);
        Marshal::FreeHGlobal(ptr);
        Serialize(nullptr);
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}
  • 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-24T04:12:13+00:00Added an answer on May 24, 2026 at 4:12 am

    To me this seems like a permissions/rights issue…

    When debugging in VS there a so-called “Debug privilege” in play…

    You can elevate your own process to contain this privilege though you need admin rights (UAC!) for that – some useful links:

    http://msdn.microsoft.com/en-us/library/ff541528%28v=vs.85%29.aspx
    http://msdn.microsoft.com/en-us/magazine/cc163823.aspx
    http://www.codeproject.com/KB/system/accessctrl3.aspx
    http://msdn.microsoft.com/en-us/library/system.security.accesscontrol.objectsecurity_methods.aspx

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

Sidebar

Related Questions

I am facing a very strange problem. I have a grid and when i
I am facing a strange problem while running my application. I have a class
i am facing strange problem i deployed a webservice in EC2 which is up
Good morning, I´m facing a very strange problem on which I haven´t found a
I am facing a strange problem with AVAudioRecorder. In my application i need to
I am facing strange problem, Whenever I commented second if condition, it works in
I'm facing this strange problem. I'm trying to read a file that is located
I am facing a strange problem while sorting a list of strings with integer
I am facing this strange problem while working with Generic Base Classes. I am
I am facing this strange problem with the following section of code <% if

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.