this is a c++ example that i found on the internet + i'm trying to modify. it compiles successfully but when i try to use the functions in a vb.net application it causes a System.EntryPointNotFoundException error:
this is the .def file:Code:// hookDll.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" #pragma data_seg("Shared") //these variables will be shared among all processes to which this dll is linked HHOOK hkKey = NULL; HINSTANCE hInstHookDll=NULL; HWND parentHWnd = NULL; #pragma data_seg() #pragma comment(linker,"/section:Shared,rws") BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch(ul_reason_for_call) { case DLL_PROCESS_ATTACH: hInstHookDll = (HINSTANCE)hModule; //we initialize our variable with the value that is passed to us break; } return TRUE; } LRESULT CALLBACK procCharMsg(int nCode,WPARAM wParam, LPARAM lParam) //this is the hook procedure { MSG *msg; //a pointer to hold the MSG structure that is passed as lParam if(nCode >=0 && nCode == HC_ACTION) //if nCode is less than 0 or nCode is not HC_ACTION we will call CallNextHookEx { msg=(MSG *)lParam; //lParam contains pointer to MSG structure. if(msg->message==WM_CTLCOLOREDIT) //we handle only WM_CTLCOLOREDIT messages { SendMessage(parentHWnd,WM_CTLCOLOREDIT,0,0); //passing this message to parent application } } return CallNextHookEx(hkKey,nCode,wParam,lParam); } //set the hook //how can i change this to a function that returns hWnd if it hooks successfully? HWND __stdcall SetHook(HWND hWnd) { if(hkKey == NULL) hkKey = SetWindowsHookEx(WH_GETMESSAGE,procCharMsg,hInstHookDll,0); parentHWnd = hWnd; return parentHWnd; } //remove the hook void __stdcall RemoveHook() { if(hkKey !=NULL) UnhookWindowsHookEx(hkKey); hkKey = NULL; }
+ this is how i'm declaring them in vb.net:Code:EXPORTS SetHook @2 RemoveHook @3
vb Code:
Declare Function SetHook Lib "hookDll.dll" (ByVal hWnd As IntPtr) As IntPtr Declare Sub RemoveHook Lib "hookDll.dll" ()
what am i doing wrong?


Reply With Quote