I want import an external C++ DLL in my C# code. But my following code doesn't work...
I build my C# with "Any CPU" and my C++ DLL is built in 32 bits.
Here my C++ DLL function:
extern "C" DWORD __stdcall ScanForIed(LPSTR lpstrHtmlIedTag, LPSTR lpStartIpAddress, DWORD iNbAddressesToScan, LPSTR lpSelectedAddress)
{// exported function (entry point)
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
AFX_MANAGE_STATE(AfxGetStaticModuleState());
USES_CONVERSION;
DWORD uiReturnVal = -1;
CString strBuf;
TCHAR tcBuf[256] = { 0 };
MBS2WSTR(lpStartIpAddress, tcBuf);
........
return uiReturnVal;
}
And my C# function where I call my DLL:
[System.Runtime.InteropServices.DllImport("C:\\Users\\212721485\\Documents\\CBWatch\\Archive_CBW3\\CBW3SyncFiles\\CBW3SyncFiles\\IEDfinder.dll")]
public static extern int ScanForIed(StringBuilder lpstrHtmlIedTag, StringBuilder lpStartIpAddress, uint iNbAddressesToScan, StringBuilder lpSelectedAddress);
private void buttonSearchIp_Click(object sender, EventArgs e) {
StringBuilder test1 = new StringBuilder("CBWatch3");
StringBuilder test2 = new StringBuilder("10.5.47.1");
StringBuilder test3 = new StringBuilder("10.5.47.153");
ScanForIed(test1,test2,100,test3);
}
I try to use "StringBuilder" or "string" for LPSTR argument and "uint" for DWORD argument. And I tried to build my C# program in 32 bits but I have the same error
When I run my program, I have this error:
"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
Have you some ideas of problem ? Thank's for any helps !
User contributions licensed under CC BY-SA 3.0