dll中2次调用都没成功,怎么办? (50分)

  • 主题发起人 主题发起人 handsome1234
  • 开始时间 开始时间
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.



 
pbyte 应该定义为byte型的吧,
否则和dll里的参数的类型不匹配呀!
integer长32-bit,byty长8-bit
 
Tintfunction2 = function(mychar1:integer;var mybyte : integer):integer;stdcall;
 
是我对硬件没有手动复位
 

Similar threads

I
回复
0
查看
678
import
I
I
回复
0
查看
738
import
I
I
回复
0
查看
520
import
I
I
回复
0
查看
501
import
I
I
回复
0
查看
444
import
I
后退
顶部