刚刚接触用delphi 7调用 DLL ,遇到问题,特来求救。
实现功能主要是当USB设备插入,判断VID,PID是否正确,如果正确就使能窗口上的一些功能键。
现在代码红色部分有些问题,不是很明白这里应该怎么写?
代码如下:
unit 19123;interfaceuses
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;。
。
。
。
实现功能主要是当USB设备插入,判断VID,PID是否正确,如果正确就使能窗口上的一些功能键。
现在代码红色部分有些问题,不是很明白这里应该怎么写?
代码如下:
unit 19123;interfaceuses
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;。
。
。
。
解决方案 »
- fastreport 问题?
- 请问怎样制作像qq一样可以自检木马或病毒的功能?
- 如何判断WebBrowser将一个网页完全打开?????
- TDriveComboBox控件问题,怎样解决软驱无盘时选中软驱的异常事件,在线等
- 请helloworlder (perfect) 进来接分!谢谢你公布★分布式程序设计文档★
- 我的可用分为什么不自动增长了?请斑竹关注,兄弟们也有这种情况吗?
- 要实现如下的功能应用什么技术?
- 在delphi中如何调用带返回参数存储过程?
- 一个窗体,可以最小化到任务栏,也可以最小化到系统托盘图标而隐藏窗体,如何判断当前是最小化到哪个状态?
- 求助!关于绘图程序刷新!!三个问题各100分献上!!!
- 发邮件问题
- delphi7表中如何加序号
不好意思 代码下面这句应该是:
TMyFunc=function(vid:Integer;pid:Integer;noOfDevs:PInteger):Integer;stdcall;
noOfDevs:PInteger
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
不是编译没有通过,是功能不对,USB device 插入没有反应。