剛剛接觸用delphi 7呼叫 DLL ,遇到問題,特來求救。
實作功能主要是當USB設備插入,判斷VID,PID是否正確,如果正確就使能視窗上的一些功能鍵。
現在代碼紅色部分有些問題,不是很明白這里應該怎么寫?
代碼如下:
unit 19123;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
Tool_vid=$04d8;
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,pid,noOfDevs:PInteger):Integer;stdcall; //
var
MCP2221Libhandle:Thandle; //load DLL handle;
MCP2221Pointer:TFarProc; //function pointer;
MyFunc:TMyFunc; //function varibel;
Temp:integer;
vid:integer;
pid:integer;
noOfDevs:Pinteger;
begin
MCP2221Libhandle:=LoadLibrary('C:\Program Files\Borland\Delphi7\Projects\mcp2221_dll_um_x86.dll'); //load DLL
if(MCP2221Libhandle<>0)then //load successfully;
try
MCP2221Pointer:=GetProcAddress(MCP2221Libhandle,pchar('Mcp2221_GetConnectedDevices')); //get the call function address;
if(MCP2221Pointer <>nil) then
begin
vid:=$4D8;
pid:=$DD;
MyFunc:=TMyFunc(MCP2221Pointer);
Temp:=MyFunc(vid,pid);
if(Temp=0) then
begin
TurnOffDriver.Enabled:=True;
UpdateButton.Enabled:=True;
end
else
begin
TurnOffDriver.Enabled:=False;
UpdateButton.Enabled:=False;
end
end;
Finally
FreeLibrary(MCP2221Libhandle);
end;
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;
。
。
。
。
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
不好意思 代碼下面這句應該是:
TMyFunc=function(vid:Integer;pid:Integer;noOfDevs:PInteger):Integer;stdcall;
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
提示你少個引數:noOfDevs:PInteger
uj5u.com熱心網友回復:
謝謝frtrnr!修改如下:好像還是不行。
if(MCP2221Pointer <>nil) then
begin
MyFunc:=TMyFunc(MCP2221Pointer);
vid:=$4D8;
pid:=$DD;
Temp:=MyFunc(vid,pid,noOfDevs);
I:=noOfDevs^;(前面定義過I :Integer)
if(Temp=0) then
begin
uj5u.com熱心網友回復:
不是編譯沒有通過,是功能不對,USB device 插入沒有反應。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/61660.html
