动态连接库调用 Delphi / Windows SDK/APIhttp://www.delphi2007.net/DelphiBase/html/delphi_20061207154439235.html
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为什么?大伙帮忙看看,谢谢
string
我改成下面的形式后:
[DllImport("ConvertDll.dll", EntryPoint = "Decode",
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern string Decode([MarshalAs(UnmanagedType.AnsiBStr)]string input);
单步执行是正确,直接运行出现外部组件发生异常。不知道为什么?