Hi,
I am having some trouble returning a string from a c++ dll. I tend to get
junk data back and I am not sure of the method, my code so far:
Function is declared in c++ dll 'Test' and exported like this:
extern "C" __declspec( dllexport ) BSTR getbagstr();
extern "C" __declspec( dllexport ) BSTR getbagstr() {
g.getbag()->setdisplaybag( "ZZZZZZZZZZZZZZ ZZZZZZZZZZZZZZ" );
const char * buff = g.getbag()->getdisplaybag( ).c_str();
return SysAllocStringB yteLen (buff , lstrlen(buff));
}
I want use the function via interop services - p/invoke - to display the
string in a simple c# program:
[DllImport("Test ")]
private static extern IntPtr getbagstr();
public static string getBagString()
{
return Marshal.PtrToSt ringAuto(getbag str());
}
The data I am returning is not correct. All display bag does is store and
return the string as below. I am returning int data correctly, but strings
are proving difficult. Anybody able to help?
void Bag::setdisplay bag(const string & str) {
displaybag = str;
}
string Bag::getdisplay bag() { return displaybag; }