C# WPD (windows portable devices) 检测WPD设备 获取设备信息

本文档展示了如何使用C#的WPD API来检测连接的便携式设备,获取设备信息,以及进行文件传输。通过PortableDeviceApiLib,实现了获取设备ID、设备友好名,并递归枚举设备中的文件ID。还介绍了如何创建对象并将其数据传输到设备上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近用c#写过一个WPD的列子,主要是参考 c++的实例, 在 windows sdk 中 ( C:/Program Files/Microsoft SDKs/Windows/v7.0/Samples/multimedia/wpd/wpdapisample   ) 由于 没有学习过 c++ ,所以看的不是很懂,在数据传输这里卡住了, 传输的时候是用 IStream 但是我不知道 这个 IStream 怎样实例化, c++ 里面是用的 (hr = SHCreateStreamOnFile(szFilePath, STGM_READ, &pFileStream)) ,希望请路过的大侠能指教一下。谢谢了。。。

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PortableDeviceApiLib;

namespace MobileIntelligentPlatforms.WPDAPI
{
    public class WPDAPP
    {
        private PortableDeviceManagerClass devMgr;
        private PortableDeviceApiLib.PortableDeviceClass ppDevice;

        /// <summary>
        /// 获得设备ID,用于检查是否有设备接入
        /// </summary>
        /// <returns></returns>
        public string[] getDeviceInfo()
        {
            devMgr = new PortableDeviceManagerClass();
            uint cDevices = 1;
            devMgr.GetDevices(null, ref cDevices);
            if (cDevices > 0)
            {
                string[] deviceIDs = new string[cDevices];
                devMgr.GetDevices(deviceIDs, ref cDevices);
                return deviceIDs;
            }
            return null;
        }

        /// <summary>
        /// 获得设备信息
        /// </summary>
        /// <param name="deviceID"></param>
        /// <returns></returns>
        public List<string> getFriendlyName(string deviceID)
        {
            List<string> msgs = new List<string>();
            uint nameLength = 0;
            devMgr.GetDeviceFriendlyName(deviceID, null, ref nameLength);
            ushort[] nameBuffer = new ushort[nameLength];
            devMgr.GetDeviceFriendlyName(deviceID, nameBuffer, ref nameLength);
            string friendlyName = "";
       &nbs

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值