刚刚接触用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;。



解决方案 »

  1.   


    不好意思 代码下面这句应该是:
    TMyFunc=function(vid:Integer;pid:Integer;noOfDevs:PInteger):Integer;stdcall; 
      

  2.   

    提示你少个参数:
     noOfDevs:PInteger
      

  3.   

    谢谢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
      

  4.   


    不是编译没有通过,是功能不对,USB device 插入没有反应。