在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);
出现未将对象引用到实例的错误,请问我该如何正确调用?
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);
出现未将对象引用到实例的错误,请问我该如何正确调用?
-----------------
var去掉
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 得到一样的结果,都报错。各位,帮忙看看