Error using a c++ dll in a C#code

Asked

Viewed 105 times

0

I created a dll with a code in C++, when I went to use gave an error.

function within the dll that I tried to use

extern "C" __declspec(dllexport) void ClickLeftMouse(int x, int y){
POINT cursorPos;
cursorPos.x = x;
cursorPos.y = y;
HWND hwnd = FindWindow(0, (LPCWSTR)"PXG Client");
DWORD dw = MAKEWORD(cursorPos.x, cursorPos.y);
SendMessage(hwnd, WM_LBUTTONDOWN, MK_LBUTTON, dw);
SendMessage(hwnd, WM_LBUTTONUP, MK_LBUTTON, dw);}

as I declared the function that is inside the dll, already in the code c#.

[DllImport("MouseEvent.dll")]
public static extern void ClickLeftMouse(int x, int y);

how I call the function

private void checkBox_bother_CheckedChanged(object sender, EventArgs e)
{
    ClickLeftMouse(546, 16);
}

When I click to use the function of the following error, someone can help me? Print do erro

  • Has this dll been added to your project references? Project Menu > Add Reference...

  • I just put and keeps giving the same error. I thought I was just putting the dll in the project folder..

  • He must not be recognizing the path. Check out this post Soen http://stackoverflow.com/questions/2864673/specify-the-search-path-for-dllimport-in-net

  • Also did not give..

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.