Home > Back-end >  Delphi 7 DLL call a problem, consult!
Delphi 7 DLL call a problem, consult!

Time:09-21

Just contact with Delphi 7 call DLL, encounter problems, come to ask for help,
Realization of function is mainly when USB device inserted, VID and PID is correct, if correct we can make some function keys on the window,
Code red part some problems now, not very understand how to write here?
The code is as follows:
Unit 19123;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Const
Tool_vid=$4 d8.
Type
TForm1=class (TForm)
Lbl7: TLabel;
Grp1Driver: TGroupBox;
RbON: TRadioButton;
RbOff: TRadioButton;
.
.
.

CbbOutputUVLO: TComboBox;
CbbOCDrop: TComboBox;
CbbRamCompensation: TComboBox;
.
.
.
Procedure chkOCDropClick (Sender: TObject);
Procedure UpdateButtonClick (Sender: TObject);
Private
{Private declarations}

Public
{Public declarations}
end;

Var
Form1: TForm1;
GldParameters: array [0.. 20] of Integer;

Implementation

{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);

Type
TMyFunc=function (vid and pid, noOfDevs: PInteger) : Integer; Stdcall;//
Var
MCP2221Libhandle: Thandle;//load the DLL handle;
MCP2221Pointer: TFarProc;//function pointer.
MyFunc: TMyFunc;//function varibel;
Temp: integer;
Vid: integer;
Pid: integer;
NoOfDevs: Pinteger;
The begin
MCP2221Libhandle:=LoadLibrary (' C: \ Program Files \ Borland \ Delphi7 \ Projects \ McP2221_dll_um_x86 DLL ');//load the DLL
If (MCP2221Libhandle & lt;> 0) then//the load successfully;
Try
MCP2221Pointer:=GetProcAddress call (MCP2221Libhandle, pchar (' Mcp2221_GetConnectedDevices'));//get the call the function address;
If (MCP2221Pointer & lt;> Nil) then
The begin
vid:=$4 d8;
Pid:=$DD.
MyFunc:=TMyFunc (MCP2221Pointer);
Temp:=MyFunc (vid and pid);
If (Temp=0) then
The begin
TurnOffDriver. Enabled:=True;
UpdateButton. Enabled:=True;
End
The else
The begin
TurnOffDriver. Enabled:=False;
UpdateButton. Enabled:=False;
End
end;
The Finally
FreeLibrary (MCP2221Libhandle);
end;
The begin
CbbSwitchFreq. ItemIndex:=0;
CbbDutyCycle. ItemIndex:=0;
CbbRamCompensation. ItemIndex:=0;
CbbLEB. ItemIndex:=0;
CbbPDRVDeadTime. ItemIndex:=0;
CbbSDRVDeadTime. ItemIndex:=0;
CbbCurrentSenseGain. ItemIndex:=0;
CbbDifferentialOPAGain. ItemIndex:=0;
CbbInputOVLO. ItemIndex:=0;
CbbInputUVLO. ItemIndex:=0;
CbbOutputOVLO. ItemIndex:=0;
CbbOutputUVLO. ItemIndex:=0;
CbbOCDrop. ItemIndex:=0;
end;
end;

,
,
,
,

CodePudding user response:

CodePudding user response:


Embarrassed to code the following sentence should be:
TMyFunc=function (vid: Integer; Pid: Integer; NoOfDevs: PInteger) : Integer; Stdcall;

CodePudding user response:

CodePudding user response:

Prompt you to less parameters:
NoOfDevs: PInteger

CodePudding user response:

Thank FRTRNR!

Changes are as follows: if still won't do,
If (MCP2221Pointer & lt;> Nil) then
The begin
MyFunc:=TMyFunc (MCP2221Pointer);
Vid:=$4 d8;
Pid:=$DD.
Temp:=MyFunc (vid and pid, noOfDevs);
I:=noOfDevs ^; (defined before I: Integer)
If (Temp=0) then
begin

CodePudding user response:

reference 5 floor sinat_36595358 reply:
thank FRTRNR!

Changes are as follows: if still won't do,
If (MCP2221Pointer & lt;> Nil) then
The begin
MyFunc:=TMyFunc (MCP2221Pointer);
Vid:=$4 d8;
Pid:=$DD.
Temp:=MyFunc (vid and pid, noOfDevs);
I:=noOfDevs ^; (defined before I: Integer)
If (Temp=0) then
The begin


Not compile didn't pass, is wrong, did not respond to a USB device inserted,