C# 此处的说明:替换为“实例无效GetDevices([in][out]string[]封送(lpwstr[])PPNPDeviceID”,而不是“实例无效GetDevices([in][out]string[]封送([])PPNPDeviceID”。如何防止

C# 此处的说明:替换为“实例无效GetDevices([in][out]string[]封送(lpwstr[])PPNPDeviceID”,而不是“实例无效GetDevices([in][out]string[]封送([])PPNPDeviceID”。如何防止,c#,.net,wpd,C#,.net,Wpd,此处的说明:替换为“实例无效GetDevices([in][out]string[]封送(lpwstr[])PPNPDeviceID”,而不是“实例无效GetDevices([in][out]string[]封送([])PPNPDeviceID”。如何防止互操作重建为旧的?@Jaran的注释帮助我解决了“封送器限制:过长的字符串”错误。我已经发布了我在这里结束的IL:关于WMI Win32ext_WPD的内容是什么?不是很好的文档搜索。唯一参考:对于我来说,不是编译,PortableDevice


此处的说明:替换为“实例无效GetDevices([in][out]string[]封送(lpwstr[])PPNPDeviceID”,而不是“实例无效GetDevices([in][out]string[]封送([])PPNPDeviceID”。如何防止互操作重建为旧的?@Jaran的注释帮助我解决了“封送器限制:过长的字符串”错误。我已经发布了我在这里结束的IL:关于WMI Win32ext_WPD的内容是什么?不是很好的文档搜索。唯一参考:对于我来说,不是编译,PortableDeviceApiLib;是COM吗?我需要在我的Windows 7 x64中安装什么?对于我来说,我尝试使用PortableDeviceApiLib(COM)但是没有编译,我也没有发现任何完整的源代码示例可以工作。我尝试使用Win32ext_WPD进行WMI,但这对我来说很困难。
PortableDeviceManagerClass deviceManager = new PortableDeviceManagerClass();
deviceManager.RefreshDeviceList();  

uint numberOfDevices = 1;            
deviceManager.GetDevices(null, ref numberOfDevices);

if (numberOfDevices == 0)
{
    return new string[0];
}

string [] deviceIds = new string[numberOfDevices];
deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices);

return deviceIds;
string[] deviceIDs = new string[cDevices];
devMgr.GetDevices(deviceIDs, ref cDevices);
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32ext_WPD Where strFriendlyName = 'SAMSUNG-SGH-I747'")
For Each objItem in colItems
Set objWMIWPDStatic = objWMIService.Get("Win32ext_WPD")
Set objInParam = objWMIWPDStatic.Methods_("EjectDevice").inParameters.SpawnInstance_()
objInParam.Properties_.Item("strObjectDeviceId") =  objItem.strId
Set objOutParams = objWMIService.ExecMethod("Win32ext_WPD", "EjectDevice", objInParam)
Exit For
Next
var oScope = new ManagementScope(@"\\" + MachineName + @"\root\cimv2");
    private IDictionary<string, string> GetDeviceIds()
    {
        var deviceIds = new Dictionary<string, string>();
        var devices = new PortableDeviceCollection();
        devices.Refresh();
        foreach (var device in devices)
        {
            device.Connect();
            deviceIds.Add(device.FriendlyName, device.DeviceId);
            Console.WriteLine(@"DeviceId: {0}, FriendlyName: {1}", device.DeviceId, device.FriendlyName);
            device.Disconnect();
        }
        return deviceIds;
    }
var contents = device.GetContents();