How can I make my DLL constantly check for hotkeys but without affecting other functions in it? If I put a loop, it will not be able to get any other calls to functions.. Do I create a thread and pass my functions to the thread upon attachment?
My silly attempt..
#include "main.h"
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
enum {F9_KEYID = 1, F10_KEYID = 2};
void DLL_EXPORT Meh()
{
MSG msg = {0};
PeekMessage(&msg, 0, 0, 0, 0x0001);
TranslateMessage(&msg);
switch(msg.message)
{
case WM_HOTKEY:
if(msg.wParam == F9_KEYID)
{
MessageBoxA(0, "F9 Pressed", "DLL Message", MB_OK | MB_ICONINFORMATION);
}
else if(msg.wParam == F10_KEYID)
{
MessageBoxA(0, "F10 Pressed", "DLL Message", MB_OK | MB_ICONINFORMATION);
}
}
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
RegisterHotKey(0, F9_KEYID, 0x4000, VK_F9);
RegisterHotKey(0, F10_KEYID, 0x4000, VK_F10);
Meh();
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}