Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

App. not calling DLL function?

sleepridersleeprider Posts: 1Member
Hi there,

For some reason my c# app is not calling my c++ function in my dll. A little bit about what my app is suppose to do. My app has a global hook to detect WM_PASTE. When WM_PASTE is detect in the DLL it sets a flag back to the main app. If the flag is true, then paste is detected and the top data in the clipboard is extracted into a file. I have a messagebox at the beginning of my DLL. This is to show that it got into my DLL, but it doesn't reach there. I'm using VS 2008. I build my DLL and there were no errors. So I ran it and that's what happen.

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

The function below is in my c# app:
[code]
public void copyPaste()
{
//MessageBox.Show("Before calling register hook in paste dll."); // Debugging
bool pasteDetected = registerHook();
//MessageBox.Show("After calling register hook in paste dll."); // Debugging
IDataObject idata = Clipboard.GetDataObject();
String clipString = "";

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;
}
}
}
[/code]

The function below is my function in my DLL:
[code]
LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam);
HINSTANCE GetHInstance();

extern "C"
{
_declspec(dllexport) bool registerHook()
{
MessageBox(NULL, "Inside registerHook() function.", "RegisterHook", NULL);
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:
// OutputDebugString("Cut!");
case WM_PASTE:
case WM_RENDERFORMAT:
case WM_RENDERALLFORMATS:
MessageBox(NULL, "Paste Detected
", Caption, NULL);
paste = true;
break;
case WM_COPY:
// OutputDebugString("Copy!");
break;
}
}
return CallNextHookEx(hHook,nCode,wParam,lParam);
}
[/code]
Sign In or Register to comment.