Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7059245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:12:32+00:00 2026-05-28T04:12:32+00:00

I don’t feel comfortable harnessing USB device with Delphi and have a next to

  • 0

I don’t feel comfortable harnessing USB device with Delphi and have a next to nothing knowledge of the details of writing device driver (though I’ve come accross some when learning assembly with GoASM).

The device could be either an usb modem or an usb printer.

What I need is a direction to go and sample code adressing the topic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:12:33+00:00Added an answer on May 28, 2026 at 4:12 am

    This was taken from detect if usb device is connected

     unit U_Usb;
    
     interface
    
    uses
    Windows, Messages, SysUtils, Classes, Forms;
    
    type
    
    PDevBroadcastHdr = ^DEV_BROADCAST_HDR;
    DEV_BROADCAST_HDR = packed record
    dbch_size: DWORD;
    dbch_devicetype: DWORD;
    dbch_reserved: DWORD;
    end;
    
    PDevBroadcastDeviceInterface = ^DEV_BROADCAST_DEVICEINTERFACE;
     DEV_BROADCAST_DEVICEINTERFACE = record
     dbcc_size: DWORD;
     dbcc_devicetype: DWORD;
     dbcc_reserved: DWORD;
      dbcc_classguid: TGUID;
      dbcc_name: short;
     end;
    
    const
      GUID_DEVINTERFACE_USB_DEVICE: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
      DBT_DEVICEARRIVAL = $8000; // system detected a new device
      DBT_DEVICEREMOVECOMPLETE = $8004; // device is gone
      DBT_DEVTYP_DEVICEINTERFACE = $00000005; // device interface class
    
    type
    
     TComponentUSB = class(TComponent)
       private
       FWindowHandle: HWND;
       FOnUSBArrival: TNotifyEvent;
       FOnUSBRemove: TNotifyEvent;
       procedure WndProc(var Msg: TMessage);
       function USBRegister: Boolean;
       protected
       procedure WMDeviceChange(var Msg: TMessage); dynamic;
      public
      constructor Create(AOwner: TComponent); override;
      destructor Destroy; override;
      published
        property OnUSBArrival: TNotifyEvent read FOnUSBArrival write FOnUSBArrival;
        property OnUSBRemove: TNotifyEvent read FOnUSBRemove write FOnUSBRemove;
      end;
    
      implementation
    
    constructor TComponentUSB.Create(AOwner: TComponent);
       begin
         inherited Create(AOwner);
         FWindowHandle := AllocateHWnd(WndProc);
         USBRegister;
       end;
    
       destructor TComponentUSB.Destroy;
        begin
       DeallocateHWnd(FWindowHandle);
        inherited Destroy;
       end;
    
     procedure TComponentUSB.WndProc(var Msg: TMessage);
         begin
         if (Msg.Msg = WM_DEVICECHANGE) then
          begin
          try
          WMDeviceChange(Msg);
        except
      Application.HandleException(Self);
       end;
       end
      else
         Msg.Result := DefWindowProc(FWindowHandle, Msg.Msg, Msg.wParam, Msg.lParam);
       end;
    
      procedure TComponentUSB.WMDeviceChange(var Msg: TMessage);
       var
       devType: Integer;
         Datos: PDevBroadcastHdr;
       begin
        if (Msg.wParam = DBT_DEVICEARRIVAL) or (Msg.wParam = DBT_DEVICEREMOVECOMPLETE) then
        begin
      Datos := PDevBroadcastHdr(Msg.lParam);
        devType := Datos^.dbch_devicetype;
         if devType = DBT_DEVTYP_DEVICEINTERFACE then
        begin // USB Device
         if Msg.wParam = DBT_DEVICEARRIVAL then
         begin
          if Assigned(FOnUSBArrival) then
           FOnUSBArrival(Self);
           end
            else
          begin
         if Assigned(FOnUSBRemove) then
          FOnUSBRemove(Self);
       end;
      end;
       end;
      end;
    
      function TComponentUSB.USBRegister: Boolean;
        var
          dbi: DEV_BROADCAST_DEVICEINTERFACE;
           Size: Integer;
         r: Pointer;
          begin
         Result := False;
         Size := SizeOf(DEV_BROADCAST_DEVICEINTERFACE);
          ZeroMemory(@dbi, Size);
          dbi.dbcc_size := Size;
          dbi.dbcc_devicetype := DBT_DEVTYP_DEVICEINTERFACE;
         dbi.dbcc_reserved := 0;
         dbi.dbcc_classguid := GUID_DEVINTERFACE_USB_DEVICE;
         dbi.dbcc_name := 0;
    
         r := RegisterDeviceNotification(FWindowHandle, @dbi,
          DEVICE_NOTIFY_WINDOW_HANDLE
         );
          if Assigned(r) then Result := True;
        end;
    
        end. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't know whats exactly going on, but it's definitely killing my time for nothing.
Don't they both have to convert to machine code at some point to execute
Don't overthink this - there's a very commonly used term and I ... have
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't ask why but I have the requirement to draw a border around certain
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't know if this has been answered before. Have custom routes to users. If
I don't have any experience in updating a Rails app and when I google
I don't have much PHP experience and I want to know how to best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.