Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Newsgroup Archive
Microsoft Office
VBA Developer
VBA - PPT Keyboard Hook not working with Office 64-bit
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Bourgui, post: 6941696"] Hi all, I have created an addin for PowerPoint, in which I have setup a keyboard hook to assign shortcuts for my functions. The problem I have is with Office 2010, the 64-bit version. When I attempt to register the hook using SetWindowsHookEx, I get a LastDLLError of 126, which is apparently "Module not found". I'm guessing this has to do with the handle to PPT that I am passing on to SetWindowsHookEx, but I'm not able to go any further. The code looks like: [code] Public Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpFn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As Long Public Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long Public Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As Long Private hWndPPT As Long Sub SetHook() Dim lThreadID As Long If Not GetPPTHandle Then Exit Sub If isHooked Then Exit Sub 'We should NEVER set the same hook twice, as lThreadID = GetCurrentThreadId 'Set a local hook HookHandle = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyHandler, hWndPPT, lThreadID) If HookHandle <> 0 Then isHooked = True End Sub Function GetPPTHandle() As Boolean GetPPTHandle = True hWndPPT = GetModuleHandle(vbNullString) If IsNull(hWndPPT) Then GetPPTHandle = False End Function [/code] I have tried "casting" the module's handle to a LongPtr, since I reckon that's what it wants, but no luck, SetWindowsHookEx always returns the error. Any idea what I'm doing wrong? I have never worked with 64-bit before. Thanks! [/QUOTE]
Verification
Post reply
Forums
Archive
Newsgroup Archive
Microsoft Office
VBA Developer
VBA - PPT Keyboard Hook not working with Office 64-bit
Top