none
(WPD) Trouble with multiple calls to IPortableDeviceManager::GetDevices

    Question

  • Hi all. I am not sure if the trouble I'm running into is Interop related or related to the WPD API specifically. I've this is posted in the wrong forum, please feel free to move it. 

    In any case, I am working on a C# application that uses WPD and am having trouble with the GetDevices method mentioned in the title. The initial problem was that I was only able to get one device ID even if multiple devices were connected to the machine. I followed the discussion here and here and found that modifying the IL for the Interop wrapper from:

    .method public hidebysig newslot abstract virtual          

    instance void  GetDevices([in][out] string&  marshal(lpwstr) pPnPDeviceIDs,

                                    [in][out] uint32& pcPnPDeviceIDs) runtime managed internalcall 

    {

    } // end of method IPortableDeviceManager::GetDevices

    to:

    .method public hidebysig newslot abstract virtual          

    instance void  GetDevices([in][out] string[]  marshal(lpwstr[]) pPnPDeviceIDs,

                                    [in][out] uint32& pcPnPDeviceIDs) runtime managed internalcall 

    {

    } // end of method IPortableDeviceManager::GetDevices


    and found that this got me to a point where I was able to get device IDs for all of the devices connected to the machine (not just the first one). However, this only worked once. On subsequent calls, I could retrieve the count properly but only the first device ID string would be valid. The rest would be null. I even tried changing string[] to native int[] in the IL, and then marshalling the strings in manually and ended up with the same result. 

    Anyone encountered this before? It seems like this must be an issue with the method itself. However, I'm still fairly new to C# Interop so it's possible I'm not properly marshaling the array of strings (actually the native type is LPWSTR*, a pointer to an array of string pointers). Any help is appreciated.


    • Edited by Tristan Bull Thursday, April 26, 2012 9:13 PM
    • Moved by Mike Feng Tuesday, May 08, 2012 12:44 PM C# (From:Common Language Runtime)
    Thursday, April 26, 2012 9:13 PM

Answers