<pre lang="C++"> // MyApp "main.cpp" DLL::createObjects(10); // creates 10 objects that are stored inside DLL // DLL "hook.cpp" namespace DLL { std::vector<MyObject> objects; EXPORT VOID CALLBACK createObjects(INT count) { for(INT i=0; i < count; ++i) objects.push_back(MyObject()); } } LRESULT CALLBACK hookProc(int code, WPARAM wParam, LPARAM lParam) { if(code == HC_ACTION) { MSG* msg = (MSG*)lParam; if(msg->hWnd == myAppHWND && msg->message == WM_PAINT) assert(DLL::objects.size()); // why is it always has the size of 0? } return CallNextHookEx(0, code, wParam, lParam); }
assert(DLL::objects.size()); // shouldn't be this vector of size 10?
createObjects
Quote:A global hook monitors messages for all threads in the same desktop as the calling thread. A thread-specific hook monitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate DLL module. A thread-specific hook procedure is called only in the context of the associated thread. If an application installs a hook procedure for one of its own threads, the hook procedure can be in either the same module as the rest of the application's code or in a DLL. If the application installs a hook procedure for a thread of a different application, the procedure must be in a DLL. For information, see Dynamic-Link Libraries.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)