I have a third party library which has a class where the constructor takes a std::wstring.
The constructor is defined by the third party like this in the header file:
Something(const std::wstring &theString);
My header file has this:
extern "C" __declspec(dllexport) ThirdParty::Something* createSomething(const std::wstring &theString);
My implementation is like this:
ThirdParty::Something* Bridge::createSomething(const std::wstring &theString) {
return new ThirdParty::Something(theString);
}
Now in my C# example program I have:
[DllImport("Bridge.dll", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
public static extern IntPtr createSomething(StringBuilder theString);
When I now try to call this like:
IntPtr ip = createSomething(new StringBuilder("foo"));
I get an AccessViolationException. When I use String instead of StringBuilder I get a SEHException.
What am I missing or doing incorrectly?
EDIT when I just return 0 in the createSomething function I get a StackImbalanceException when using String.
std::stringor astd::wstring. And both solutions require creating a C/C++ bridge, where the bridge doesn't accept C++ objects...