您的位置:首页 > 编程语言 > Delphi

最简单的delphi加载C++dll实例

2013-06-11 08:17 253 查看
C++的dll:

#ifndef _DLL_FOR_DEL_H_

#define _DLL_FOR_DEL_H_

extern "C"

{

_declspec(dllexport)int mult();

};

#endif

---------

#include "dllfordel.h"

int mult()

{

return 5*6;

}

================================delphi==========================

unit CPlusDllTest;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, StdCtrls;

type

CplusFuc=function():Integer;stdcall;

TForm1 = class(TForm)

lbl1: TLabel;

edt1: TEdit;

btn1: TButton;

btn2: TButton;

procedure btn1Click(Sender: TObject);

procedure btn2Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

Func:CplusFuc;

hMhd:Thandle ;

ret:Integer;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);

begin

hMhd:=LoadLibrary('dllfordel.dll');

if hMhd=null then

begin

Application.MessageBox('加载C++ dll失败',0)

end

else

begin

// Application.MessageBox('加载C++ dllsucess','加载dll',MB_OK) ;

@Func:=GetProcAddress(hMhd,'mult');

ret:=Func();

edt1.Text:=IntToStr(ret);

end;

end;

//end;

//end;

procedure TForm1.btn2Click(Sender: TObject);

begin

edt1.Text:='';

end;

end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: