I have C++ code below:
someclass* my = new someclass();
my->doSomething();
delete my;
It just works perfect when I call this class from another C++ project.
But when I call it from C#, it gives me an error and I cannot trace the error.
This is how I call c++ dll from C#.
[DllImport(@"Helper.dll", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.BStr)]
private static extern string LoginQuery(string UserID, string UserPW, string ProxyServer, StringBuilder Cookies);
This is C++ code.
extern "C" FUNCDLL_API BSTR LoginQuery(const char* UserID, const char* UserPW, const char* ProxyServer, char Cookies[])
{
someclass* my = new someclass();
std::string ret my->doSomething();
delete my; --> here, I get error when called from C#.
return ::SysAllocString(CComBSTR(ret.c_str()).Detach());
}
Can somebody explain the reason?
EDIT The LoginQuery returns some result from class.
EDIT I changed my codes.
EDIT The error message is something like below. It is translated from Korean to English.
Additional Information: Critical error occured during runtime. Error address is 0x6799bd26(thread 0x2860). Error code is 0xc0000005. This error can be part of but which is not safe or CLR, or it can be unconfirmed part of user code. Nomarlly the reason of this error is COM-interop or marshaling error, and it can destroy stack.
If there is a handler for this exception, the program may be safely continued.