Cannot Set The Keyboard Hook Error=0
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about windows hooks hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask windows global hook Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join c# hook them; it only takes a minute: Sign up Setting WH_KEYBOARD hook fails with error 1428 up vote 0 down vote favorite This is my C++ code: #include
Setwindowshookex Example
lParam) { std::cout << "Hook callback" << std::endl; return CallNextHookEx(hook, nCode, wParam, lParam); } int main(int argc, char **argv) { hook = SetWindowsHookEx(WH_KEYBOARD, keyboardHook, NULL, NULL); if (hook == NULL) { std::cout << "Error " << GetLastError() << std::endl; return 1; } std::cout << "Hook set" << std::endl; } I compile it using Visual Studio like this: cl /D_WIN32_WINNT=0x0401 foo.cc /link user32.lib When I run it, I get error 1428. C:\>foo.exe Error 1428 This is the meaning of wh_keyboard_ll error 1428. C:\nocaps>net helpmsg 1428 Cannot set nonlocal hook without a module handle. Could you please help me to understand this error and get this code working? It would be great if you could provide me a working code that works and invokes the callback? I see that if I use WH_KEYBOARD_LL hook instead, it works fine. But I need to understand how WH_KEYBOARD hook can be made to work. c++ visual-studio share|improve this question asked Jan 3 '14 at 4:45 Lone Learner 2,01221239 It says right in the documentation you need to put the hook procedure in a DLL, which is injected. –chris Jan 3 '14 at 4:46 @chris If I understand it correctly, it means that my keyboardHook function cannot be in the same EXE as the main function because the keyboardHook function needs to be in a separate DLL. Have I understood it correctly? –Lone Learner Jan 3 '14 at 4:58 Yes, because you're doing it globally, and the low level keyboard and mouse hooks are special. Anyway, it also says that NULL and 0 as the last two arguments to SetWindowsHookEx might result in an error. NULL is not the current module. GetModuleHandle(NULL) is. –chris Jan 3 '14 at 5:04 @LoneLearner Do you need more help? –manuell Jan 4 '14 at 20:12 @manuell I am all set with this on
Studio 2015 products Visual Studio Team Services Visual Studio Code Visual Studio Dev Essentials Office Office Word/Excel/PowerPoint Microsoft Graph Outlook OneDrive/Sharepoint Skype Services Store Cortana Bing Application Insights Languages wh_mouse_ll & platforms Xamarin ASP.NET C++ TypeScript .NET - VB, C#, F# Server
Setwindowshookex C#
Windows Server SQL Server BizTalk Server SharePoint Dynamics Programs & communities Students Startups Forums MSDN Subscriber downloads Sign in
Wh_callwndproc
Search Microsoft Search Windows Dev Center Windows Dev Center Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store http://stackoverflow.com/questions/20896711/setting-wh-keyboard-hook-fails-with-error-1428 opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx for enterprise Windows Store opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Hooks Hook Reference Hook Functions Hook Functions SetWindowsHookEx SetWindowsHookEx SetWindowsHookEx CallMsgFilter CallNextHookEx CallWndProc CallWndRetProc CBTProc DebugProc ForegroundIdleProc GetMsgProc JournalPlaybackProc JournalRecordProc KeyboardProc LowLevelKeyboardProc LowLevelMouseProc MessageProc MouseProc SetWindowsHookEx ShellProc SysMsgProc UnhookWindowsHookEx TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. SetWindowsHookEx function Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread. Syntax C++ Copy HHOOK WINAPI SetWindowsHookEx( _In_ int idHook, _In_ HOOKPROC lpfn, _In_ HINSTANCE hMod, _In_ DWORD dwThreadId ); Parameters idHook [in] Type: int The type of hook procedure to be installed. This pa
for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers https://www.experts-exchange.com/questions/21793781/Error-creating-keyboard-hook.html Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > Error creating keyboard hook. Want to Advertise Here? Solved Error creating keyboard hook. Posted on 2006-03-29 C++ 7 Verified Solutions 22 Comments 2,043 Views Last Modified: 2008-02-01 Hi, This compiles http://www.codeproject.com/Articles/1264/KeyBoard-Hooks fine, but an "Error creating keyboard hook" keeps occuring ... #include
Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question about this article Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Articles » General Programming » DLLs & Assemblies » Hooks ArticleBrowse CodeStatsRevisionsAlternatives Comments (133) Add your ownalternative version Tagged as C++VC6WindowsWin2KVisual-StudioDev Stats 643.6K views16.6K downloads155 bookmarked Posted 23 Jul 2001 KeyBoard Hooks H. Joseph, 23 Jul 2001 4.75 (52 votes) 1 2 3 4 5 4.75/5 - 52 votes6 removedμ 4.14, σa 1.79 [?] Rate this: Please Sign up or sign in to vote. This example shows how to write global hooks .This program captures all the Keyboard events and save the keys to a text file. Download demo project - 18 Kb Introduction Hooks are one of the most powerful features of Windows. We can hooks to trp all the events in the Windows environment. This example shows how to trap keyboard events and save the keys to a text file. In the Microsoft® Window