我想使用 Microsoft Whiteboard 应用程序跟踪用户的各种输入交互(笔、触摸和鼠标)。有没有办法不挂钩应用程序并使用 WM_POINTER 消息?(因为某种原因我无法完成这项工作)编程语言对我来说并不重要。
DLL 代码:
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#pragma data_seg("Shared")
#pragma data_seg()
#pragma comment(linker,"/section:Shared,rws")
#include <windows.h>
#include <stdio.h>
HHOOK global;
extern "C" __declspec(dllexport) LRESULT WINAPI procedure(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION) {
//lets extract the data
CWPSTRUCT* data = (CWPSTRUCT*)lParam;
if (data->message == WM_CLOSE) {
//lets get the name of the program closed
char name[260];
GetWindowModuleFileNameA(data->hwnd, name, 260);
//extract only the exe from the path
char* extract = (char*)((DWORD)name + lstrlenA(name) - 1);
while (*extract != '\\')
extract--;
extract++;
MessageBoxA(0, "A program has been closed", extract, 0);
}
}
return CallNextHookEx(global, nCode, wParam, lParam);
}
Python 代码(应该从 dll 接收数据,例如何时何地触摸它):
import ctypes
import os
from ctypes import *
from ctypes.wintypes import *
user32 = WinDLL('user32', use_last_error=True)
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
user32.SetWindowsHookExA.errcheck = errcheck_bool
user32.SetWindowsHookExA.restype = HHOOK
user32.SetWindowsHookExA.argtypes = (c_int, # _In_ idHook
HOOKPROC, # _In_ lpfn
HINSTANCE, # _In_ hMod
DWORD) # _In_ dwThreadId
user32.CallNextHookEx.restype = LRESULT
user32.CallNextHookEx.argtypes = (HHOOK, # _In_opt_ hhk
c_int, # _In_ nCode
WPARAM, # _In_ wParam
LPARAM) # _In_ lParam
user32.GetMessageW.argtypes = (LPMSG, # _Out_ lpMsg
HWND, # _In_opt_ hWnd
UINT, # _In_ wMsgFilterMin
UINT) # _In_ wMsgFilterMax
user32.TranslateMessage.argtypes = (LPMSG,)
user32.DispatchMessageW.argtypes = (LPMSG,)
GetModuleHandle = ctypes.windll.kernel32.GetModuleHandleA
GetModuleHandle.restype = POINTER(c_void_p)
#LoadLibrary = ctypes.windll.kernel32.LoadLibraryA
#LoadLibrary.argtypes = [c_wchar_p]
#LoadLibrary.restype = c_int
GetProcAddress = ctypes.windll.kernel32.GetProcAddress
GetProcAddress.restype = HOOKPROC
def pointer_msg_loop():
dll_name = 'Dll.dll'
dll_abspath = os.path.abspath(os.path.join(os.path.dirname(__file__), '.', dll_name))
print(dll_abspath)
lib = kernel32.LoadLibraryA(dll_abspath.encode(encoding='ascii'))
handle = GetModuleHandle(dll_abspath.encode(encoding='ascii'))
print(lib)
print(handle)
procedure = GetProcAddress(handle, "procedure")
print(procedure)
if (procedure):
print('correct value procedure')
tHook = user32.SetWindowsHookExW(WH_CALLWNDPROC, procedure, lib, 0)
print(ctypes.WinError(GetLastError()))
print(tHook)
print(ctypes.WinError(GetLastError()))
msg = MSG()
while True:
bRet = user32.GetMessageW(byref(msg), None, 0, 0)
if not bRet:
break
if bRet == -1:
raise WinError(get_last_error())
user32.TranslateMessage(byref(msg))
user32.DispatchMessageW(byref(msg))
1:添加了一个工作示例,我想将其转换为收听我的 Microsoft 白板窗口。2:添加了另一个示例的 dll 解决方案(不起作用)