您的位置:程序门 -> delphi -> vcl组件开发及应用



delphi 调用dll 出错 access violation at 0x0


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


delphi 调用dll 出错 access violation at 0x0[已结贴,结贴人:legendboy]
发表于:2007-07-26 11:54:07 楼主
请问是什么原因?这个dll是用vc写的非mfc   dll
发表于:2007-07-26 11:57:351楼 得分:50
dll   原型   及你的调用代码?
发表于:2007-07-26 12:00:402楼 得分:0
c++文件
#include   "adddll.h "
int   add(int   x,int   y)
{
return   x+y;
}

头文件
#ifndef   adddll_h
#define   adddll_h
extern   "c "   int   __declspec(dllexport)add(int   x,int   y);
#endif

delphi代码

unit   unit1;

interface

uses
    windows,   messages,   sysutils,   classes,   graphics,   controls,   forms,   dialogs,
    stdctrls;

type
    tadd=function(a:integer;b:integer):integer   ;stdcall;
    tform1   =   class(tform)
        button1:   tbutton;
        procedure   button1click(sender:   tobject);
    private
        {   private   declarations   }
    public
        {   public   declarations   }
    end;

var
    form1:   tform1;
    th:thandle;
    add:tadd;
implementation

{$r   *.dfm}

procedure   tform1.button1click(sender:   tobject);
var
      answer:integer;
begin
th:=loadlibrary( 'adddll.dll ');
@add:=getprocaddress(th, 'add ');
answer:=add(1,2);
form1.caption:=inttostr(answer);
end;

end.

发表于:2007-07-26 12:42:593楼 得分:0
var
answer:integer;
begin
th:=loadlibrary( 'adddll.dll ');
if   th> 0   then
begin
@add:=getprocaddress(th, 'add ');
answer:=add(1,2);
form1.caption:=inttostr(answer);
end;
freelibrary(   th   );
end;
发表于:2007-07-26 13:42:344楼 得分:0
不行啊,还是那个错误
发表于:2007-07-26 14:10:205楼 得分:0
搜索了一下,现在明白了,是ecdcl和stdcall的问题,呵呵项目紧,慌了.


快速检索

最新资讯
热门点击