您的位置:程序门 -> delphi -> windows sdk/api



在c#中调用delph编写的dll的函数时,老是出现未将对象引用到实例的错误


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


在c#中调用delph编写的dll的函数时,老是出现未将对象引用到实例的错误[已结贴,结贴人:wei0527]
发表于:2007-11-27 14:16:25 楼主
在c#中调用delph编写的dll的函数时,老是出现未将对象引用到实例的错误:  
delphi编写的dll中函数声明:function       deliverfromesm(var       smtype,       content,caller:pchar):integer;  
我在c#中声明:  
[dllimport("esmapi.dll",charset               =               charset.ansi,callingconvention               =               callingconvention.stdcall)]  
static       extern       int       deliverfromesm(ref       string       smtype,ref       string       content,ref       string       caller);  
调用:  
string       smtype="";  
string       content="";  
string       caller="";  
int       reportval=deliverfromesm(       ref       smtype,ref       content,ref       caller);  
出现未将对象引用到实例的错误,请问我该如何正确调用?
发表于:2007-11-27 15:37:441楼 得分:0
怎么没有人回答呢?自己先顶一下
发表于:2007-11-28 13:40:482楼 得分:0
那位delphi比较熟悉的,说一下,我该在delphi中怎么正确调用啊
发表于:2007-11-28 13:53:483楼 得分:20
function               deliverfromesm(var               smtype,               content,caller:pchar):integer;
-----------------
var去掉
发表于:2007-11-28 14:14:484楼 得分:0
to:sdzeng
去掉也不行啊
发表于:2007-11-28 14:23:195楼 得分:0
请问,加var和不加有什么区别?
发表于:2007-11-28 17:50:016楼 得分:30
问一下这个是否是一个委托中用到的?如果是,那pchar这里就不可以用string了,因为他们的实际接口长度不一样的。如果不是,那string应该ok,有问题,就找找可能是这个dll内部的问题了
发表于:2007-11-30 09:06:077楼 得分:0
dll是人家提供的,联系不到相关技术人员了,但他们提供的delphi可执行文件,调用正常。可惜的是,没有源码
发表于:2007-12-04 15:28:428楼 得分:0
  声明:      
    function       test(var       nparam1:       integer;       var       nparam2:       pchar):       integer;       stdcall;external'api.dll';      
    调用:      
    p1,p2:pchar;      
    npa2:       integer;      
    r:       integer;      
    npa1:array[0..20000]       of       char;      
       
    p1       :=       npa1;      
    r       :=       test(npa2,p1);      
在delphi调用成功,我在c#中这么声明调用:
[dllimport("esmapi.dll",charset       =       charset.ansi,callingconvention       =       callingconvention.stdcall)]
static   extern   int   test(   ref   int   buffercount,       byte[]   buffer);
int   buffercount=-1;
//stringbuilder   buffer=new   stringbuilder(20000);
byte[]   buffer=new   byte[20000];
int   reportval=test(ref   buffercount,   buffer);//执行会在这行报错,提示:未将对象引用到实例
buffer参数我用stringbuilder   得到一样的结果,都报错。各位,帮忙看看
发表于:2007-12-06 10:42:529楼 得分:0
问题自己解决,但还是谢谢两位。


快速检索

最新资讯
热门点击