M
muntyanu
Hi all,
I am passing string from C++ to C# but not sure which way is more
correct. Here it is:
First approach:
CDAnetCSharpHooks:assString( )
{
char str[] = "String to pass";
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( str );
}
Second approach:
CDAnetCSharpHooks:assString( )
{
char str[] = "String to pass";
CString temp(str);
System::String * dotNetStr = new System::String( temp);
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( dotNetStr );
}
C# method
public void UseStringInDotNet( String str )
{
// create new thread and use string in it
}
UseStringInDotNet() is creating new thread and that is why PassString()
will finish its work before UseStringInDotNet() finishes its own.
Basically first approach is working, but sometimes on the .NET side I
have some unpredictable behaviour in memory. I am wondering if that
memory for str buffer is cleared before C# get its work done. In this
respect will be the second approach more safe ?
Thank you very much in advance for any suggestions
Roman
I am passing string from C++ to C# but not sure which way is more
correct. Here it is:
First approach:
CDAnetCSharpHooks:assString( )
{
char str[] = "String to pass";
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( str );
}
Second approach:
CDAnetCSharpHooks:assString( )
{
char str[] = "String to pass";
CString temp(str);
System::String * dotNetStr = new System::String( temp);
DotNetObject *obj = new DotNetObject();
obj->UseStringInDotNet( dotNetStr );
}
C# method
public void UseStringInDotNet( String str )
{
// create new thread and use string in it
}
UseStringInDotNet() is creating new thread and that is why PassString()
will finish its work before UseStringInDotNet() finishes its own.
Basically first approach is working, but sometimes on the .NET side I
have some unpredictable behaviour in memory. I am wondering if that
memory for str buffer is cleared before C# get its work done. In this
respect will be the second approach more safe ?
Thank you very much in advance for any suggestions
Roman