Dll?
-
hi does any one know how can i convert this code that is made by C++ in dll to C# also to be put in dll
#define DllExport __declspec( dllexport ) HHOOK h; DllExport extern LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam) { switch(nCode) { case WM_SIZING: return 0; break; case WM_MOVING: return 0; break; default: return CallNextHookEx(h,nCode,wParam,lParam); } } DllExport extern void InstallHook() { h=SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,0,0); }
-
hi does any one know how can i convert this code that is made by C++ in dll to C# also to be put in dll
#define DllExport __declspec( dllexport ) HHOOK h; DllExport extern LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam,LPARAM lParam) { switch(nCode) { case WM_SIZING: return 0; break; case WM_MOVING: return 0; break; default: return CallNextHookEx(h,nCode,wParam,lParam); } } DllExport extern void InstallHook() { h=SetWindowsHookEx(WH_CALLWNDPROC,CallWndProc,0,0); }
There's three types of ways to handle Windows messages in .NET:
- Override the
WndProc
method of a control (includingForm
, which derives fromControl
). TheMessage
structure contains the necessary information. You can use theMarshal
class and theGCHandle
structure to assist with marshaling theWPARAM
andLPARAM
. This is a Window hook. - Implement
IMessageFilter
and add it to the collection of message pump filters usingApplication.AddMessageFilter
. This is an application hook. - Finally - and you should be very careful and write good, efficient, error-checking code - are global system hooks like
WH_CALLWNDPROC
. See the article Global System Hooks in .NET[^] for more information
Decide whether you really need a global hook that applies to all Windows though. Using any language, this can decrease the performance and stability of Windows, but using a managed language will definitely decrease performance because of the runtime. In most cases, this is not necessary. Just today I recommended handling these very notification messages by simply overriding
WndProc
on a form to prevent it from being moved or resized. This would be the most efficient way and would not affect other applications.Microsoft MVP, Visual C# My Articles
- Override the