Function Interface of dll;
I think in dll function looks like, with datatype BSTR
CustomConvert(BSTR dataStr)
{........}
dll Interface:
CustomConvert(IntPtr dataStr) //Returns strings
The data I need to pass is something like this:
string strTemp = "pŒ®í§…Êtf°B²bßZÃQô"; // something like this
obj.CustomConvert(strTemp);
But I am getting the exception "string" cannot convert to "System.IntPtr"; After searching in internet I found something like this.
obj.CustomConvert(System.Runtime.InteropServices.Marshal.StringToBSTR(strTemp));
But System.Runtime.InteropServices.Marshal.StringToBSTR(strTemp) convert strTemp in numerical numbers like 2035295. But I need to pass the actual value in strTemp.
Any help or suggestions?
To pass a
BSTR
you can do something like:and then pass the
string
directly without doing anything.Note that in the
CustomConvert
you mustn't free theBSTR
, because it is "owned" by the C#.