question

AparnaSA-7123 avatar image
0 Votes"
AparnaSA-7123 asked ·

Windows Portable device event monitoring using MFC C++

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();
c++windows-api-general
· 3
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Another method is to use SHChangeNotifyRegister

I tested with a mobile and I get the file name when I delete a file (while I don't get it either with WPD interfaces...)

0 Votes 0 ·

I can't receive event when adding or removing a file using the WPD API sample. Does @Castorix31's solution work for you? And what error you get when register for more than one Portable device? It works for me.


0 Votes 0 ·

@AparnaSA How are things going? Please let us know if there is any progress.

0 Votes 0 ·

0 Answers