I am having problems importing an unmanaged C ++ dll into C # [winform]. Can anyone help?
Basically, I'm just trying to create a saferyray of strings in C ++ and trying to send it to C #.
Here is my C ++ code.
extern "C" __declspec(dllexport) BOOL GetStringArr(SAFEARRAY* arr) { SAFEARRAY* myArray; SAFEARRAYBOUND rgsabound[1]; rgsabound[0].lLbound = 0; rgsabound[0].cElements = 5; myArray = SafeArrayCreate(VT_BSTR, 1, rgsabound); VARIANT* pvData = (VARIANT*)(myArray->pvData); pvData[0].vt = VT_BSTR; pvData[0].bstrVal = SysAllocString(L"FirstString"); pvData[1].vt = VT_BSTR; pvData[1].bstrVal = SysAllocString(L"SecondString"); pvData[2].vt = VT_BSTR; pvData[2].bstrVal = SysAllocString(L"ThirdString"); pvData[3].vt = VT_BSTR; pvData[3].bstrVal = SysAllocString(L"FourthString"); pvData[4].vt = VT_BSTR; pvData[4].bstrVal = SysAllocString(L"FifthString"); arr = myArray; return true; }
Here is my C # code.
[DllImport("MyData.dll", EntryPoint = "GetStringArr")] public static extern bool GetStringArr([MarshalAs(UnmanagedType.SafeArray)] out Array strServerList);
I get an exception when I call GetStringArr from C #. I'm sure there is something stupid that I do. Can anybody help?
Thanks in advance.
c ++ c # dllimport
Alag20
source share