H
handsome1234
Unregistered / Unconfirmed
GUEST, unregistred user!
dll中的函数原形
WORD MCS_ErrorMsg(
WORD _wErrNo,
BYTE *_bErrMsg
);
WORD MCS_InitComm(
BYTE _bPort = 0,
DWORD _dwCommBaudRate = 115200
);
///////////////////////
unit multicardpas;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
Button3: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
type
Tintfunction2 = function(mychar1:integer;mybyte :
integer):integer;stdcall;
//Tintfunction21 = function(mychar1:integer;mybyte :
pchar):integer;stdcall;
Tintfunction22 = function(mychar1:integer;var mybyte :
integer):integer;stdcall;
Tintfunction3 =
function(mychar1,mychar2,mychar3:integer):integer;stdcall;
Tintfunction4 =
function(mychar1,mychar2,mychar3,mychar4:integer):integer;stdcall;
var
Hinst:Thandle;
Fpointer:Tfarproc;
myfunct:TIntfunction2;
myfunct22:TIntfunction22;
myresult:integer;
pbyte :integer;
begin
// GetMem(pbyte, sizeof(byte) * 20);
//pbyte:=0;
Hinst:=loadlibrary('MCS_SR.dll');
if Hinst>0 then
begin
showmessage('dll被发现');
try
begin
FPointer:=GetProcAddress(Hinst,'MCS_InitComm');
if FPointer<> nil then
begin
myFunct:=TintFunction2(Fpointer);
// myresult:=myFunct(0,115200);
end
else
showmessage ('加载MCS_InitComm失败');
if myresult=0 then
showmessage('初始化正确!')
else
showmessage('初始化不正确!');
//
FPointer:=GetProcAddress(Hinst,'MCS_ErrorMsg');
@myFunct22:=GetProcAddress(Hinst,'MCS_ErrorMsg');
if FPointer<> nil then
begin
//
myFunct:=TintFunction2(Fpointer);
myresult:=myFunct22(myresult,pbyte);
ShowMessage(IntToStr(pbyte));
// showmessage(@pbyte);
end;
end;
finally
freelibrary(Hinst);
end
end
else
showmessage('dll没有被发现');
end;
end.
WORD MCS_ErrorMsg(
WORD _wErrNo,
BYTE *_bErrMsg
);
WORD MCS_InitComm(
BYTE _bPort = 0,
DWORD _dwCommBaudRate = 115200
);
///////////////////////
unit multicardpas;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
StatusBar1: TStatusBar;
Button3: TButton;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
type
Tintfunction2 = function(mychar1:integer;mybyte :
integer):integer;stdcall;
//Tintfunction21 = function(mychar1:integer;mybyte :
pchar):integer;stdcall;
Tintfunction22 = function(mychar1:integer;var mybyte :
integer):integer;stdcall;
Tintfunction3 =
function(mychar1,mychar2,mychar3:integer):integer;stdcall;
Tintfunction4 =
function(mychar1,mychar2,mychar3,mychar4:integer):integer;stdcall;
var
Hinst:Thandle;
Fpointer:Tfarproc;
myfunct:TIntfunction2;
myfunct22:TIntfunction22;
myresult:integer;
pbyte :integer;
begin
// GetMem(pbyte, sizeof(byte) * 20);
//pbyte:=0;
Hinst:=loadlibrary('MCS_SR.dll');
if Hinst>0 then
begin
showmessage('dll被发现');
try
begin
FPointer:=GetProcAddress(Hinst,'MCS_InitComm');
if FPointer<> nil then
begin
myFunct:=TintFunction2(Fpointer);
// myresult:=myFunct(0,115200);
end
else
showmessage ('加载MCS_InitComm失败');
if myresult=0 then
showmessage('初始化正确!')
else
showmessage('初始化不正确!');
//
FPointer:=GetProcAddress(Hinst,'MCS_ErrorMsg');
@myFunct22:=GetProcAddress(Hinst,'MCS_ErrorMsg');
if FPointer<> nil then
begin
//
myFunct:=TintFunction2(Fpointer);
myresult:=myFunct22(myresult,pbyte);
ShowMessage(IntToStr(pbyte));
// showmessage(@pbyte);
end;
end;
finally
freelibrary(Hinst);
end
end
else
showmessage('dll没有被发现');
end;
end.