[DllImport("paste.dll", EntryPoint="registerHook")] public static extern bool registerHook();
public void Paste() { bool pasteDetected = registerHook(); IDataObject idata = Clipboard.GetDataObject(); if (pasteDetected && (idata != null)) /// Pasting { /// If the item is a text format then store in buffer and continue on. if (idata.GetDataPresent(DataFormats.Text)) /// Text format. { clipString = (String)idata.GetData(DataFormats.Text); keyBuffer += clipString; } } }
HHOOK hHook;HMODULE hHookDLL = LoadLibrary("paste.dll"); // Need to link with paste.dll LPCTSTR Caption = "Paste Detected!";bool paste = false;LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam);HINSTANCE GetHInstance();extern "C" bool _declspec(dllexport) __stdcall registerHook(){ hHook = SetWindowsHookEx(WH_CALLWNDPROC, MsgHookProc, hHookDLL, 0); return paste;}LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam){ if(nCode >= 0) { PCWPSTRUCT pstInfo = (PCWPSTRUCT)lParam; switch(pstInfo->message) { case WM_CUT: case WM_PASTE: case WM_RENDERFORMAT: case WM_RENDERALLFORMATS: MessageBox(NULL, "Paste Detected\n", Caption, NULL); paste = true; break; case WM_COPY: break; } } return CallNextHookEx(hHook,nCode,wParam,lParam);}