.
Tengo un problema al realizar el hook al mensaje WH_CBT de forma global mas no por Theard y es que no se instala dicho hook, obtube el error y su descripción pero ni idea a que se refiere :(.
#include <iostream>
#include <windows.h>
HHOOK hHRes;
LRESULT CALLBACK CBTProc( int , WPARAM , LPARAM );
void ErrorExit(LPTSTR lpszFunction);
int main()
{
char s[500] ={};
hHRes = ::SetWindowsHookExA( WH_CBT , &CBTProc , GetModuleHandle( NULL ) , 0 );
if ( hHRes == NULL ) {
/* le resto 2 para establecer un caracter nulo en formato WCHAR */
::FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM , NULL , ::GetLastError() , NULL , (WCHAR*)&s , (DWORD) strlen(&s[0])/2 - 2 , NULL );
::MessageBoxExW(NULL,(WCHAR*)&s,NULL,0,NULL);
}
return 0;
}
LRESULT CALLBACK CBTProc( int nCode, WPARAM wParam, LPARAM lParam )
{
::UnhookWindowsHookEx( hHRes );
return ::CallNextHookEx( hHRes , nCode , wParam , lParam );
}
Edito: Lei por hay que se debe hacer esto en una dll, que tan cierto es?...
Temibles Lunas!¡.
.
Asi es:
Cita de: MSDNThe global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. Global hooks should be restricted to special-purpose applications or to use as a development aid during application debugging. Libraries that no longer need a hook should remove its hook procedure.
.
Perfecto no estaba tan lejos entonces gracias!¡.
Dulce sLunas!¡.