16,749
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <windows.h>
extern "C"
{
_declspec(dllexport) int _cdecl getSum(int x, int y);
_declspec(dllexport) int _cdecl getMax(int x, int y);
_declspec(dllexport) int _cdecl getMin(int x, int y);
}
int getSum(int x, int y)
{
return x + y;
}
int getMax(int x, int y)
{
return (x>y) ? x : y;
}
int getMin(int x, int y)
{
return (x<y) ? x : y;
}
extern "C" BOOL APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
MessageBox(0,"Dll Process Attach.","Dll Main",0);
}
else
if (dwReason == DLL_PROCESS_DETACH)
{
MessageBox(0,"Dll Process Detach.","Dll Main",0);
}
return TRUE;
}
unit unitMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function getSum(x,y:Integer):Integer;cdecl; external 'DllDemo.dll';
function getMax(x,y:Integer):Integer;cdecl; external 'DllDemo.dll';
function getMin(x,y:Integer):Integer;cdecl; external 'DllDemo.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c: Integer;
begin
a := 5;
b := 4;
c := getSum(a,b);
ShowMessage('sum: ' + IntToStr(c));
c := getMax(a,b);
ShowMessage('max: ' + IntToStr(c));
c := getMin(a,b);
ShowMessage('min: ' + IntToStr(c));
end;
end.