Home > Cannot Set > Cannot Set Nonlocal Hook Without A Module Handle C#

Cannot Set Nonlocal Hook Without A Module Handle C#

I am using the following PInvoke statements: [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetWindowsHookEx(HookType hookType, HookProc more hot questions question feed lang-cs about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation Error Message: Cannot set non-local hook without a module handle. How to show that something is not completely metrizable How to decline a postdoc interview if there is some possible future collaboration? have a peek here

Here is the code i've been playing with, just messing about with notepad. The time now is 02:48 AM. My AccountSearchMapsYouTubePlayNewsGmailDriveCalendarGoogle+TranslatePhotosMoreShoppingWalletFinanceDocsBooksBloggerContactsHangoutsEven more from GoogleSign inHidden fieldsSearch for groups or messages Register Remember Me? Basically what i want to do is install a hook that monitors for wm_close,sc_close or smthing and when the app crashes , is closed or smthing like that to restart.

Now it works on both Windows 7 and XP. –magol May 9 '12 at 13:20 2 You have another bug in your code, the return type for SetWindowsHookEx() is IntPtr, Converting the weight of a potato into a letter grade Pen Tester's Programming Style Is it ethical for a journal to cancel an accepted review request when they have obtained sufficient Reply With Quote October 6th, 2005,04:30 AM #2 Igor Vartanov View Profile View Forum Posts Visit Homepage Elite Member Power Poster Join Date Nov 2000 Location Voronezh, Russia Posts 6,533 Re: In that case, you need a DLL.

CONTINUE READING Join & Write a Comment Already a member? HHOOK g_hhk = NULL; HINSTANCE g_hThisDll; int APIENTRY DllMain ( HINSTANCE hInstance, DWORD Go to Solution 12 9 3 Participants InteractiveMind(12 comments) LVL 25 C++2 jkr(9 comments) LVL 86 C++72 trigger-happy Do I have to write an external C++ DLL to handle it? –Shawn Oct 15 '11 at 1:11 Also I thought providing a Thread ID to SetWindowsHookEx makes it Marking as accepted along with the explanation from @shf301.

After wait returns you may be sure process is finished, so you may notify main thread and quit wait thread. Best regards, Igor Reply With Quote October 6th, 2005,06:43 AM #8 How Did The Dred Scott Decision Contribute to the Civil War? A named pipe is common. http://stackoverflow.com/questions/12357705/setwindowshookex-fails-with-error-1428 Join Now For immediate help use Live now!

I can't understand this. Get Started with C or C++ C Tutorial C++ Tutorial Get the C++ Book All Tutorials Advanced Search Forum Platform Specific Boards Windows Programming Window Hook Getting started with C or If not how do you get a thread Id for another application? Each hook procedure should follow a few guidelines.

You may don't want but you have to. https://msdn.microsoft.com/en-us/library/ms838448.aspx Btw the application is a console one dunno if that helps (surely doesn't) And there is no other way to make this app tell my app that it is quiting? You may have to register or Login before you can post: click the register link above to proceed. Not the answer you're looking for?

and yet manage to log global key presses, etc.. navigate here Is it ethical for a journal to cancel an accepted review request when they have obtained sufficient number of reviews to make a decision? Join and Comment By clicking you are agreeing to Experts Exchange's Terms of Use. Please set the third parameter to 0 and the fourth parameter to current thread ID:http://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx hMod[in] Type:HINSTANCE A handle to the DLL containing the hook procedure pointed to by thelpfnparameter.

The time now is 01:48 AM. For example: in your console application check every x seconds whether your application is still running and if it isn't restart it. Marc Gregoire - NuonSoft (http://www.nuonsoft.com) My Blog Wallpaper Cycler On 1941 Dec 7, could Japan have destroyed the Panama Canal instead of Pearl Harbor in a surprise attack? Check This Out I start my application using shellexecuteex and get its hwnd then i use GetWindowThreadProcessId(hwnd,0) to get that process threadid and my hookproc procedure is in my application's code.

Also, your MyRPrc isn't correct. Error message i get is 1428 : OLE IDispatch exception code "number" from "name": "name" (Error 1428) You have received an error code returned by an Automation object. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with

Congratulations Btw the application is a console one dunno if that helps (surely doesn't) Console cannot be hooked.

Specifically, the capacity and swap member functions will be introduced. But it is correct behavior, looks like they improved it. You'll need this declaration to call LoadLibrary: [DllImport("kernel32", SetLastError=true, CharSet = CharSet.Auto)] private static extern IntPtr LoadLibrary(string fileName); share|improve this answer edited May 9 '12 at 13:06 answered May 9 '12 I haven't tried it.

I have tried a couple versions of SetWindowsHookEx() with and without a dll but i cant get it to work yet, has anyone done this before? 11-21-2004 #2 anonytmouse View Profile if (hHook == 0) { int err = Marshal.GetLastWin32Error(); MessageBox.Show("SetWindowsHookEx Failed" + err.ToString()); return; } SetWindowHookEx always runs into error 1428 ERROR_HOOK_NEEDS_HMOD Cannot set nonlocal hook without a module handle. They should check the nCode parameter to see what they should do, and they need to pass the message to the following hook in the chain. http://culturahq.com/cannot-set/cannot-set-non-local-hook.html more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed

so, can I just scrap the DllMain function from my code now? What crime would be illegal to uncover in medieval Europe? Results 1 to 12 of 12 Thread: SetWindowsHookEx - Without DLL Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Best regards, Mike Feng MSDN Community Support | Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and

c# windows setwindowshookex share|improve this question edited Oct 6 '12 at 11:43 Konrad Viltersten 1 asked Sep 10 '12 at 18:50 Marco Klein 481315 4 You can't make this work Now if i happen to have a thread id for another program can i create a hook which will only hook that program. share|improve this answer answered Oct 15 '11 at 2:10 mike z 25.8k33761 That's what I was guessing. I start my application using shellexecuteex and get its hwnd then i use GetWindowThreadProcessId(hwnd,0) to get that process threadid and my hookproc procedure is in my application's code.

Just add the import library that you get when building your DLL to your application, then the DLL will be loaded.


  • © Copyright 2017 culturahq.com. All rights reserved.