这个是用vc编写的dll中的一个示例函数。
int MacTest(int * random)
{
  *random = 10;
  return 0;
}
在delphi中如下调用:
procedure func;
var
  i: integer;
begin
  MacTest(@i);
  showmessage(inttostr(i));
end;在该函数执行的时候,提示内存访问错误。就是访问了不该访问的内存。
但是如果把“  showmessage(inttostr(i));”这行去掉,就不会报错了。
奇怪啊。

解决方案 »

  1.   

    vc中有没有声明stdcall或cdecl,Delphi中要与vc中的声明相同
      

  2.   

    在delphi中改成下面的方式试试:
    procedure func;
    var
      i: Pinteger;
    begin
      try
        New(i);
        MacTest(i);
        showmessage(inttostr(i^));
      finally
        Dispose(i);
      end;  
    end;
      

  3.   

    注意delphi引用DLL函数stdcall还是cdcel
      

  4.   

    你应该定义一个过程类型:
    TFun=function(Random:integer):integer;stdcall;
    再用loadlibrary 试试
      

  5.   

    错了,应该这样
    TFun=function(Random:PInteger):integer;stdcall;
      

  6.   

    sxqwhxq(步青云) :
    使用loadlibrary还是出同样的错误。postren(小虫) :
    vc中声明的是__declspec;delphi中使用stdcall