Я бы хотел отслеживать различные взаимодействия ввода (перо, касание и мышь) пользователей с помощью приложения 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 Whiteboard. 2: добавлено решение dll из другого примера (не работает)