VB调用DLL函数写法换成DELPHI问题?
VB中:
Public Declare Function auto_init Lib "comdll.dll " (ByVal CommPort As Long, ByVal Baud As Long) As Long '打开串口
Public Declare Function ic_exit Lib "comdll.dll " (ByRef commhandle As Long) As Long '关闭串口
Public Declare Function lsct5557hex Lib "comdll.dll " (ByVal commhandle As Long, ByRef keystr As Byte) As Long
请求DELPHI中调用写法?
打开出宽方法我使用:
Function auto_init( CommPort : LongWord; Baud : LongWord):LongWord; STDCALL external dllname; // '打开串口
可是调用时出现内存错误,请 帮忙。
[解决办法]
procedure TfrmMain.comMainReceiveData(Sender: TObject; Buffer: Pointer;
BufferLength: Word);
var
nIndex : Integer;
boolZero : Boolean;
arrByte : array [1..8] of Byte;
strReceiveData : string;
begin
//内存移位
Move(Buffer^,arrByte,BufferLength);
strReceiveData := ' ';
boolZero := True;
//从高位到低位转换Buffer
for nIndex := BufferLength downto 1 do
begin
if (boolZero) and (Chr(arrByte[nIndex]) <> '0 ') then
boolZero := False;
if (boolZero = False) and (Chr(arrByte[nIndex]) <> '= ') then
strReceiveData := strReceiveData + Chr(arrByte[nIndex]);
end;
//屏幕显示不断刷新
LCDCurrentWeight.Indicatorstring := strReceiveData;
RefreshLCD(LCDTare.Indicatorstring);
//毛重是否变化
if FboolIsEnter = False then FstrGrossWeight := strReceiveData;
end;
[解决办法]
没看出楼主的写法有什么问题,至多把LongWord改成Longint。
Function auto_init(CommPort, Baud: Longint): Longint; stdcall; external dllname; // '打开串口
有没有测试过在VB中按VB的写法调用是否正确呢?
[解决办法]
注意ByVal和ByRef区别一般就没有问题了。
ByVal按值,ByRef按地址