C#调用delphi Dll中pchar 返回值解决
(2013-09-20 22:40:11)
相信不少使用c#的朋友碰到过相似的问题,我今天在开发中也碰到相似问题,但愿能给你们一点启示吧! 在delphi中申明的函数原型为 function aa(var writedate:pchar;var validdate:pchar):integer;stdcall;动态库的名称为valid.dll 并且函数的返回值是经过两个pchar类型来返回的 那么咱们在c#中该用何种类型来接收pchar呢,我的建议用stringbuilder 咱们在c#中能够这用来申明 [DllImport("valid.dll"),EntryPoint="aa" CharSet=Charset.Ansi] public static extern int checkDate(ref StringBuilder WriteDate,ref StringBuilder LimitDate); 记住若是delphi中用var来申明变量的,在C#中必定要加ref 的,另外在delphi中用pchar类型的变量在C#中最好用StringBuilder 不然得话可能用C#来调用Delphi Dll 会报错,一般提示为内存写保护的错误信息。