wow

wow

  • NA
  • 8
  • 0

DLL not working

Jun 17 2009 9:56 PM
Hi there,

I'm new to this forum and did not see a really good section where to put this subject, so I thought I put it in the C# Language.  If this is in the wrong pleace, inform me and I'll post it in the correct spot. 

I'm getting my feet wet in DLLs and for some reason my little application is not calling my DLL.  My application is suppose to call the DLL, the DLL is suppose to set a flag whenever WM_PASTE is detected.  The DLL then returns a true variable back to the application.  In the application if true, then get the top data fromt he clipboard.  This is a global hook.  Any help is greatly appreciated. 

 [DllImport("paste.dll", EntryPoint="registerHook")]
public static extern bool registerHook();

Below is in my applicatoin:
  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;
}
}
}

Below is my DLL in c++:
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);
}