Windows Portable device event monitoring using MFC C++

Aparna S A 6 Reputation points
2020-08-08T19:28:37.127+00:00

I need to develop an application to monitor events on Portable devices using C++ MFC. I'm using WPD API for the same. But encountering a few issues. I am not getting the Filename in case of the delete operation. and also not able to register for more than one Portable device.

HRESULT hr = S_OK;
PWSTR eventCookie = nullptr;
ComPtr<IPortableDevice> device;

   device = nullptr;
   hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);

   DWORD pnpDeviceIDCount = EnumerateAllDevices();

   for(int i=0;i<pnpDeviceIDCount;i++)
   {
       ChooseDevice(&device,i);
       if (device == nullptr)
       {
           continue ;
       }

       RegisterForEventNotifications(device.Get(), &eventCookie);
   }
 CoUninitialize();
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,412 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} vote