Enumerating Windows Portable Devices in C#

后端 未结 6 1035
半阙折子戏
半阙折子戏 2020-12-14 04:09

I am attempting to enumerate connected portable devices on Windows using the Windows Portable Devices API and the PortableDeviceManager provided by this API.

I have

6条回答
  •  一个人的身影
    2020-12-14 05:00

    Maybe I'm wrong, but the line deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices); does not makes sense to me. If you want fill the array of string, you should pass whole array, not only one string.

    I found a post on blgs.msdn.com where is passed the whole array.

    string[] deviceIDs = new string[cDevices];
    devMgr.GetDevices(deviceIDs, ref cDevices);
    

    However it's only guess. I hope, it will help you.

    EDIT: I found several code samples, where is passed whole array instead of first item: For example: http://social.msdn.microsoft.com/forums/en-US/vbgeneral/thread/22288487-caf3-4da5-855f-6447ad9fa48d

    And I found the Importing PortableDeviceApiLib generates incorrect Interop in VB.NET issue - it looks like the default interop assembly is not correct. Maybe the successfull way is getting correct interop assembly from someone and use it. Or use some another bridge between managed code (C#/VB.NET/...) and native code. The C++\CLI could be good way if you are good enough in C++.

    I found Portable Device Lib project on CodePlex - maybe it is the correct bridge.

提交回复
热议问题