I am loading a 3rd party dll which returns string value.
The string is returned properly in vb.net but when I wrote the same code in c# it is returning an empty string.
My c# declaration and calling code.
[DllImport("desdll.dll"]
public static extern short TDESDecrypt(string strIn, string key, string strOut)
char c= '\0';
string strEncDecResult = new string(c, 1024);
TDESDecrypt(strIn, key, strEncDecResult);
strEncDecResult = strEncDecResult.Substring(0, ((strEncDecResult.IndexOf('\0') + 1 - 1));
vijay jPosted May 8, 2007, 1:25 AM
I had to pass the output parameter as a the STRING BUILDER to get the required output.
The declaration has to be like
private
static extern short TDESDecrypt(string strIn, string key, [MarshalAs(UnmanagedType.LPStr)] StringBuilder strOut);StringBuilder
SBOutParam = new StringBuilder(0, 1024);TDESDecrypt(passwd , cEncDecKey , SBOutParam);
strEncDecResult = SBOutParam.ToString();
The below link gives explanation on using strings as param
http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/
Scott LyslePosted May 7, 2007, 4:15 AM
http://msdn2.microsoft.com/en-us/library/aa288468(VS.71).aspx