delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
动态连接库调用 Delphi / Windows SDK/API
http://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);  
  单步执行是正确,直接运行出现外部组件发生异常。不知道为什么?  
 

posted on 2009-02-11 16:49 delphi2007 阅读(356) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。