library lib1; ..... exports OpenComm; SendText; CloseComm; begin ... end. unit unit1;interface uses ActiveX,....procedure OpenComm(Port:Integer);stdcall; procedure SendText(Text:PChar);stdcall; procedure CloseComm;stdcall;implementationprocedure OpenComm(Port:Integer); begin MSComm1.CommPort:=1; MSComm1.Open; end; procedure SendText(Text:PChar); begin MSComm1.Output:=string(Text); end; procedure CloseComm; begin MSComm1.Close; end; initialization CoIntialize(nil); MSComm1:=TMSComm.Create(nil); finalization MSComm1.Free; CoUnitialize; end.
hiflower(花) 您好??哪该怎么接收数据。在这里面。
最好接收时在dll中转化好的传回来,
exports SetCallback;type TCallback=procedure(s:string); TABC=class(TComponent) procedure MSCommOnComm(Sender:TObject); end; var FCallback:TCallback; ABC:TABC;procedure SetCallback(ACallback:TCallback); begin FCallback:=@ACallback; end; procedure TABC.MSCommComm(Sender:TObject); var s:string; begin while MSComm1.InBufferCount>0 do begin s:=MSComm1.Input; if Assigned(FCallback) then FCallback(PChar(s)); end; end;initialization ... ABC:=TABC.Create(nil); MSComm1.OnComm:=ABC.MSCommOnComm finalization ... ABC.Free; end.
我做过。
.....
exports
OpenComm;
SendText;
CloseComm;
begin
...
end.
unit unit1;interface
uses
ActiveX,....procedure OpenComm(Port:Integer);stdcall;
procedure SendText(Text:PChar);stdcall;
procedure CloseComm;stdcall;implementationprocedure OpenComm(Port:Integer);
begin
MSComm1.CommPort:=1;
MSComm1.Open;
end;
procedure SendText(Text:PChar);
begin
MSComm1.Output:=string(Text);
end;
procedure CloseComm;
begin
MSComm1.Close;
end;
initialization
CoIntialize(nil);
MSComm1:=TMSComm.Create(nil);
finalization
MSComm1.Free;
CoUnitialize;
end.
SetCallback;type
TCallback=procedure(s:string);
TABC=class(TComponent)
procedure MSCommOnComm(Sender:TObject);
end;
var
FCallback:TCallback;
ABC:TABC;procedure SetCallback(ACallback:TCallback);
begin
FCallback:=@ACallback;
end;
procedure TABC.MSCommComm(Sender:TObject);
var
s:string;
begin
while MSComm1.InBufferCount>0 do
begin
s:=MSComm1.Input;
if Assigned(FCallback) then
FCallback(PChar(s));
end;
end;initialization
...
ABC:=TABC.Create(nil);
MSComm1.OnComm:=ABC.MSCommOnComm
finalization
...
ABC.Free;
end.