| 发表于: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. | | |
|