Einzelnen Beitrag anzeigen

wschrabi

Registriert seit: 16. Jan 2005
448 Beiträge
 
#9

AW: C++ DLL in Delphi einbinden

  Alt 21. Jul 2011, 20:40
Hi,
also ich konnte die DLL so einbinden. Siehe unten.
Doch mein Problem ist jetzt der InputEnableBuffer.

Ursp war in der Deklaration:
function HidDevice_GetInputReport_Control (device: HID_DEVICE;
var buffer: Byte;
bufferSize: LongInt):BYTE; stdcall; external DLLNAME ;

Doch der buffer ist 12 Bytes lang und anfangs mit 00. Das erste Byte des Buffers muss 00 sein. (= ReportID)

Also ich habs wie in C mit memget gemacht. Das Compilieren geht aber obwohl die Packete im Analyser sichtbar sind,
zeigt ShowRead immer das slebe an. Woran mag das liegen?

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

const
  DLLNAME = 'SLABHIDDevice.dll';

  // Return Codes
 HID_DEVICE_SUCCESS                        = $00;
 HID_DEVICE_NOT_FOUND                     = $01;
 HID_DEVICE_NOT_OPENED                   = $02;
 HID_DEVICE_ALREADY_OPENED              = $03;
 HID_DEVICE_TRANSFER_TIMEOUT            = $04;
 HID_DEVICE_TRANSFER_FAILED              = $05;
 HID_DEVICE_CANNOT_GET_HID_INFO         = $06;
 HID_DEVICE_HANDLE_ERROR                 = $07;
 HID_DEVICE_INVALID_BUFFER_SIZE         = $08;
 HID_DEVICE_SYSTEM_CODE                   = $09;
 HID_DEVICE_UNSUPPORTED_FUNCTION       = $0A;
 HID_DEVICE_UNKNOWN_ERROR                = $FF;



type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure ShowRead(ReportID: Byte; Data: Pointer; Size: Word);


  end;

  HID_DEVICE = Pointer;

  TBuffer = record
    inhalt: string[14];
    end;


var
  Form1: TForm1;


 function HidDevice_GetNumHidDevices(VID: Word; PID: Word): integer; stdcall; external DLLNAME ;
 function HidDevice_Open(var device: HID_DEVICE; DevNum: Integer; VID: Word; PID: Word): BYTE; stdcall; external DLLNAME ;

 function HidDevice_GetInputReport_Control (device: HID_DEVICE;
                                               var buffer: Pointer; // urspr ist hier var buffer: BYTE gestanden
                                               bufferSize: LongInt):BYTE; stdcall; external DLLNAME ;

 function HidDevice_GetInputReport_Interrupt(device: HID_DEVICE;
                                               var buffer: array of Char;   // urspr ist hier var buffer: BYTE gestanden
                                               bufferSize: LongInt;
                                               numReports: LongInt;
                                               var bytesReturned: LongInt):BYTE; stdcall; external DLLNAME ;

 function HidDevice_GetInputReportBufferLength(device: HID_DEVICE): Integer; stdcall; external DLLNAME ;
 function HidDevice_Close(device: HID_DEVICE):BYTE stdcall; external DLLNAME ;


 implementation


{$R *.dfm}


const
  VID = $152A;
  PID = $8261;

var
  devNum: integer;
  m_hid: HID_DEVICE;
  line : String;
  Stop: Boolean = False;
  //InputEnableBuffer: ;
    bufferPtr : Pointer;

procedure TForm1.ShowRead( ReportID: Byte;  Data: Pointer; Size: Word);
var
  I: Integer;
  Str: string;
begin
  Str := Format('RD %.2x ', [ReportID]);
  for I := 0 to Size - 1 do
    Str := Str + Format('%.2x ', [Cardinal(PChar(Data)[I])]);
  Memo1.Lines.Add(Str);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  status: Byte;
  len1: LongInt;
  i,BytesRead: LongInt;
begin
  devNum := HidDevice_GetNumHidDevices(VID, PID);
  ShowMessage('DeviceID = '+IntToStr(devNum));

  if devNum <> 0 then
    begin
    status := HidDevice_Open(m_hid, devNum-1,VID, PID);
    if (status = HID_DEVICE_SUCCESS) then    ShowMessage('OK!');

    repeat
    begin
    len1 := HidDevice_GetInputReportBufferLength(m_hid);
    //InputEnableBufferPtr.inhalt[1] := $00;
    if len1 <> 0 then
        begin
        //HidDevice_GetInputReport_Interrupt(m_hid, InputEnableBuffer,len1-1,1, BytesRead);
        HidDevice_GetInputReport_Control(m_hid, BufferPtr,len1-1);
        //ShowRead( ReportID: Byte;  const Data: Pointer; Size: Word);
        ShowRead( 00,  BufferPtr, len1-1);


        end;
    end;

    until Stop;

    end;

    HidDevice_Close(m_hid);

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Stop:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 GetMem(BufferPtr, 15 * SizeOf(Byte));
                                    ';
end;

end.

Geändert von wschrabi (21. Jul 2011 um 21:42 Uhr)
  Mit Zitat antworten Zitat