急:c#的string和delphi的widestring不相容怎么办罗???(附了源码)
//----------------------------------------------------------------
在delphi写了一个简单的动态库函数:
function TcpConnect(ServerAddr: WideString; var str:WideString ): Boolean; stdcall ;
begin
result:=false;
try
str := ServerAddr ;
result:=true;
except
;
end;
end;
//------------------------------------------------------------------------
然后在c#中调用:
[DllImport("Func5.dll", EntryPoint="TcpConnect", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
public static extern bool TcpConnect(string addr ,out string str);
Private void btnTcpConnect_Click(object sender, System.EventArgs e)
{
string str;
if(TcpConnect("192.0.0.76",out str)) {Response.Write(str);}
else
{Response.Write("failed");}
}
显示结果:192.0
(应该显示192.0.0.76 啊)
//-----------------------------------------------------------------------
delphi的widestring和c#的string不相容怎么办罗???