动态连接库调用

wx114 2006-12-07 03:44:39
Delphi里动态连接库调用声明:(Delphi是正确)
function Coding(input:string):pchar;
stdcall;far;external 'convertdll.dll'name 'Coding';
function Decode(input:string):pchar;
stdcall;far;external 'convertdll.dll'name 'Decode';;

我翻译成C#
[DllImport("convertdll.dll", EntryPoint = "Coding", CallingConvention = CallingConvention.StdCall)]
public static extern string Coding(string input);

[DllImport("convertdll.dll", EntryPoint = "Decode", CallingConvention = CallingConvention.StdCall)]

public static extern String Decode(String input);

传入同样的值 ,Delphi中 Decode()得到正确的值,C#得到0000为什么?大伙帮忙看看,谢谢
...全文
135 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wx114 2006-12-07
  • 打赏
  • 举报
回复
我改成下面的形式后:
[DllImport("ConvertDll.dll", EntryPoint = "Decode",
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern string Decode([MarshalAs(UnmanagedType.AnsiBStr)]string input);
单步执行是正确,直接运行出现外部组件发生异常。不知道为什么?
dovelee 2006-12-07
  • 打赏
  • 举报
回复
string

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧