-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hi,
I've just posted the same question in StackOverflow, but since it concerns your project I wanted to know if you have any solution for this.
My problem: the "friendly name" of the device is always empty. Windows shows a friendly name under "This PC", so it should be feasible.
I have checked similar solutions like this one here based on the same source, but they have the same issue.
This is how your project tries to retrieve the friendly name (from the file WindowsPortableDevice.cs):
var WPD_DEVICE_FRIENDLY_NAME = new PortableDeviceApiLib._tagpropertykey();
WPD_DEVICE_FRIENDLY_NAME.fmtid = new Guid(0x26D4979A, 0xE643, 0x4626, 0x9E, 0x2B, 0x73, 0x6D, 0xC0, 0xC9, 0x2F, 0xDC);
WPD_DEVICE_FRIENDLY_NAME.pid = 12;
string friendlyName;
propertyValues.GetStringValue(ref DevicePropertyKeys.WPD_DEVICE_FRIENDLY_NAME, out friendlyName);
As stated before, the result of friendlyName is always empty.
What I have tried so far:
In this post I found this other possible solution, which uses the PortableDeviceManagerClass instead of the PortableDeviceClass:
string RetrieveFriendlyName(
PortableDeviceApiLib.PortableDeviceManagerClass PortableDeviceManager,
string PnPDeviceID)
{
uint cFriendlyName = 0;
ushort[] usFriendlyName;
string strFriendlyName = String.Empty;
// First, pass NULL as the LPWSTR return string parameter to get the total number
// of characters to allocate for the string value.
PortableDeviceManager.GetDeviceFriendlyName(PnPDeviceID, null, ref cFriendlyName);
// Second allocate the number of characters needed and retrieve the string value.
usFriendlyName = new ushort[cFriendlyName];
if (usFriendlyName.Length > 0)
{
PortableDeviceManager.GetDeviceFriendlyName(PnPDeviceID, usFriendlyName, ref cFriendlyName);
// We need to convert the array of ushorts to a string, one
// character at a time.
foreach (ushort letter in usFriendlyName)
if (letter != 0)
strFriendlyName += (char)letter;
// Return the friendly name
return strFriendlyName;
}
else
return null;
}
The problem here is that I seem to have a different signature of GetDeviceFriendlyName (different Interop.PortableDeviceApiLib.dll?). This is mine:
void GetDeviceFriendlyName(string pszPnPDeviceID, ref ushort pDeviceFriendlyName, ref uint pcchDeviceFriendlyName);
It does not accept null or ushort[].
I tested the following, just to see how it behaved:
var pDeviceFriendlyName = default(ushort);
var pcchDeviceFriendlyName = default(uint);
GetDeviceFriendlyName(pszPnPDeviceID, ref pDeviceFriendlyName, ref pcchDeviceFriendlyName);
...but it threw an exception: "The data is invalid. (Exception from HRESULT: 0x8007000D)".