delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks
求教,c#如何调用delphi编写的dll中的函数 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiBase/html/delphi_20061219114602118.html
如题;  
  由于工作需要用到c#,但是有写函数用c#太不习惯了,于是用delphi写,但是调用时出现了问题,开始以为是函数写错了,但是后来写了个最简单的showmessage也不行  
   
  delphi中  
        声明部分  
        procedure   Showmsg(mText:string);       cdecl;  
        定义部分  
        procedure   Showmsg(mText:string);       cdecl;  
        begin  
          ShowMessage(mText);//就随便测试下  
        end;  
        给出端口  
        exports  
            Showmsg;                     //编译生成Project2.dll  
   
  c#中  
        引用  
          [DllImport("Project2.dll")]    
          private   static   extern   string   Showmsg(string   mText);  
        随便放入一个按纽点击事件  
            Showmsg("afsdfas");  
        结果只show出了第一个字符   “a”  
   
        如果把delphi中的过程写成一个函数,那就show成了空的,没接收到入参  
   
  不知道应该怎样写,请高手指点  
         
 

仔细看一下有关教材,Delphi里的string类型与C里面的并不一样,  
  procedure   Showmsg(mText:pchar);       cdecl;  
  这样才可以  
   
   
 

但是c#里面好象没有pchar型,只有char型  
  试了一下不行,show出来的是乱码。。。

汗,我的意思是指在DELPHI里面要使用pchar   型......

或者干脆使用指针+长度   两个参数来传递.....

结贴

posted on 2008-10-14 16:35 delphi2007 阅读(658) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。