View Single Post
Old 02-04-2011, 19:50   #59 (permalink)
y3kt
No Life Poster
 
y3kt's Avatar
 
Join Date: Feb 2006
Location: Club-Berry
Posts: 1,938
Member: 238127
Status: Offline
Sonork: 100.1574867
Thanks Meter: 3,526
Donate money to this user
I am trying to connect directly to BlackBerry, i have read many things by now and have this piece of code to get a valid handle with path to device, but for some reason it is not working, can anybody take a look at this code and give any opinion?

Code:
function TForm1.GetDevicePath: THandle;
var
   BytesReturned           : DWORD;
   LPGUID                  : TGUID;
   DeviceInfo              : HDEVINFO;
   DeviceInterfaceData     : TSPDeviceInterfaceData;
   DetailData              : PSPDeviceInterfaceDetailData;
begin
  LPGUID := GUID_DEVINTERFACE;
  DetailData := nil;
  GetDevicePath := INVALID_HANDLE_VALUE;
  LoadSetupApi;
  
  DeviceInfo := SetupDiGetClassDevs(@LPGUID, nil, 0, DIGCF_PRESENT or DIGCF_DEVICEINTERFACE);

  if not(DeviceInfo = Pointer(INVALID_HANDLE_VALUE)) then
  begin
    
    DeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData);

    if not SetupDiEnumDeviceInterfaces(DeviceInfo, nil, LPGUID, 0, DeviceInterfaceData)  then
    begin
       if SetupDiGetDeviceInterfaceDetail(DeviceInfo, @DeviceInterfaceData, nil, 0, BytesReturned, nil) then
       begin
          DetailData := AllocMem(BytesReturned);

         if DetailData =  Pointer(INVALID_HANDLE_VALUE) then
          begin
             SetupDiDestroyDeviceInfoList(DeviceInfo);
             GetDevicePath:=INVALID_HANDLE_VALUE;
          end;
          DetailData.cbSize:= SizeOf(TSPDeviceInterfaceDetailData);

          if SetupDiGetDeviceInterfaceDetail(DeviceInfo, @DeviceInterfaceData, DetailData,
                                             BytesReturned, BytesReturned, nil) = false  then
          begin
             FreeMem(DetailData);
             GetDevicePath:=INVALID_HANDLE_VALUE;
          end;

         if DetailData.DevicePath = '' then
          begin
             SetupDiDestroyDeviceInfoList(DeviceInfo);
             FreeMem(DetailData);
          end;

          GetDevicePath := CreateFile(DetailData.DevicePath, GENERIC_WRITE or GENERIC_READ,
                                      FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
                                      FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0 );
          FreeMem(DetailData);
       end;
    end;
  end;
  UnloadSetupApi;
end;
It is compiling well, but it never returns a valid handle, maybe i am using wrong GUID?

Any help would be appreciated, thanks
  Reply With Quote
 
Page generated in 0.08882 seconds with 7 queries