c#中调用delphi的.DLL程序 出错
c#中调用delphi的.DLL程序 报错
[DllImport(@"C:\Windows\System32\USocket.dll", EntryPoint = "Queryele", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern string Queryele(string address, string COM);
public string GetEleDataByUserID(string userID)
{
string result = string.Empty;
string eleAddress = GetEleAddress(userID);
string COM = "4";
string useAndLess = Queryele(eleAddress, COM); ///从DLL程序集获取结果
result = DateTime.Now.ToShortDateString() + useAndLess; ///当前时间+累计+剩余
return result;
}
c#引用delphi的.dll。现在报错,外部组件错误
------解决思路----------------------
function Queryele(address:string; mscom:string):PChar; stdCall;
delphi 中register和pascal:参数从左向右传递,也就是说最左边的参数最先求值并传入,最右边的参数最后求值和传入。cdecl,stdcall和safecall则按从右向左方向。
PChar这个在delphi中是指针类型,在c#中用char
转成C#是这样的 public static extern char Queryele(string address, string COM);
------解决思路----------------------
返回值类型不匹配
怎么string和PChar你都定义成string了
[DllImport(@"C:\Windows\System32\USocket.dll", EntryPoint = "Queryele", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern string Queryele(string address, string COM);
public string GetEleDataByUserID(string userID)
{
string result = string.Empty;
string eleAddress = GetEleAddress(userID);
string COM = "4";
string useAndLess = Queryele(eleAddress, COM); ///从DLL程序集获取结果
result = DateTime.Now.ToShortDateString() + useAndLess; ///当前时间+累计+剩余
return result;
}
c#引用delphi的.dll。现在报错,外部组件错误
function Queryele(address:string; mscom:string):PChar; stdCall;这是delphi的方法
------解决思路----------------------
function Queryele(address:string; mscom:string):PChar; stdCall;
delphi 中register和pascal:参数从左向右传递,也就是说最左边的参数最先求值并传入,最右边的参数最后求值和传入。cdecl,stdcall和safecall则按从右向左方向。
PChar这个在delphi中是指针类型,在c#中用char
转成C#是这样的 public static extern char Queryele(string address, string COM);
------解决思路----------------------
返回值类型不匹配
怎么string和PChar你都定义成string了