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 8447833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:16:27+00:00 2026-06-10T10:16:27+00:00

Hi All I need a C++ code to get Portable Device Notification when a

  • 0

Hi All I need a C++ code to get Portable Device Notification when a user connects some Portable Device to system . my part of code for getting mass storage device notification is as follow , please go through it and suggest me how to do it for portable devices .

LRESULT CALLBACK DLLWindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HDEVNOTIFY hDeviceNotify;
__int32 devType;
char c;
char buf[5]={0};
PawCallBack *callbackHandle;
char Buffer[10];
switch (message)
{
case WM_CREATE:
    RegisterHotKey(hwnd, 1, MOD_ALT  , VK_SNAPSHOT);
    RegisterHotKey(hwnd, 2, 0 , VK_SNAPSHOT);
    if ( ! DoRegisterDeviceInterfaceToHwnd(WceusbshGUID, hwnd, &hDeviceNotify) )
    {
        // Terminate on failure.
        ExitProcess(1);
    }
    break;
case WM_HOTKEY:
    LPSTR temppath;
    CaptureScreen(GetDesktopWindow());
    UnicodeToAnsi(temp_filename, &temppath);
    callbackHandle      = new PawCallBack;
    strcpy(callbackHandle->ImageSavePath,temppath);
    callbackHandle->servicecode     = 111;
    if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10,0))
    {
        //MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
    }
    delete callbackHandle;

    break;

case WM_DEVICECHANGE:
    {
        PDEV_BROADCAST_HDR pHdr;
        PDEV_BROADCAST_VOLUME vol;

        // Output some messages to the window.
        switch (wParam)
        {
        case DBT_DEVICEARRIVAL:
            //MessageBoxA(NULL,"Device Arrived", "Info", MB_OK);
            pHdr = (PDEV_BROADCAST_HDR)lParam;
            if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
            {

                vol = (PDEV_BROADCAST_VOLUME)pHdr;
                c = DriveMaskToLetter(vol->dbcv_unitmask);
                memset(buf,0,5);
                sprintf(buf,"%c:", c);
                //MessageBoxA(NULL,&c, "Device Arrived", MB_OK);
                callbackHandle      = new PawCallBack;
                strcpy(callbackHandle->DriveName, buf);
                callbackHandle->servicecode     = 109;
                if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10, 0))
                {
                    //MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
                }
                delete callbackHandle;
            }
            break;

        case DBT_DEVICEREMOVECOMPLETE:
            pHdr = (PDEV_BROADCAST_HDR)lParam;
            if(pHdr->dbch_devicetype == DBT_DEVTYP_VOLUME)
            {
                vol = (PDEV_BROADCAST_VOLUME)pHdr;
                c = DriveMaskToLetter(vol->dbcv_unitmask);
                memset(buf,0,5);
                sprintf(buf,"%c:",c);
                callbackHandle      = new PawCallBack;
                strcpy(callbackHandle->DriveName,buf);
                callbackHandle->servicecode     = 110;

                if(!myPipe.SendMsg(_T("PAWAGENT"), callbackHandle, sizeof(PawCallBack), Buffer, 10, 0))
                {
                    //MessageBoxA(NULL,"Cannot Send to pipe","Drive Info",MB_OK);
                }
                delete callbackHandle;
            }
            break;

        }
        break;
case WM_DESTROY:
    PostQuitMessage (0);
    break;
case WM_CLOSE:
    if ( ! UnregisterDeviceNotification(hDeviceNotify) )
    {
        MessageBoxA(NULL, "UnregisterDeviceNotification Failed", "Info",MB_OK);
    }
    UnregisterHotKey(hwnd, 1);
    UnregisterHotKey(hwnd, 2);
    break;
default:
    return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
}

the above code is working perfect for mass storage devices but now i want to extend this for portable devices so please go through my code and suggest me what to do for portable devices. thanks in advance ..

  • 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-06-10T10:16:28+00:00Added an answer on June 10, 2026 at 10:16 am

    I think you need to take a look @ this two links

    This is very basic tutorial to get you started with WMI
    http://blogs.technet.com/b/heyscriptingguy/archive/2006/03/20/how-can-i-get-a-list-of-installed-device-drivers.aspx

    This is the real code you will need

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa390425(v=vs.85).aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all i am in need of some help getting my code working correctly
I have SPListItem and some text field. I need in code get all versions
I need to write some code that would loop though all rows of a
I've been trying to get this code to work for hours! All I need
I need a code to get all the days of all weeks in current
I need to optimize code to get room for some new code. I do
I found all the code I need to make SHBrowseForFolder work in my application.
What's the code syntax, and what all do I need to install and configure,
I need to move all the hard coded strings in my source code in
I need a way to remove ALL using statements from code and fully qualify

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.