Hi all. I posted this in the CLR forum and didn't get any responses except a suggestion to post it here... Any help is appreciated.
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.
View the full article




Sign In
Create Account
Back to top







