Code Monkey home page Code Monkey logo

wpdapi's Introduction

wpdapi's People

Contributors

duke-fleed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wpdapi's Issues

Exception when trying to use this library to write a file to android phone

I'm trying to use this library to read and write files to an Android phone, but when I make a call to device.TransferContentToDeviceFromStream, I get the following exception:
An unhandled exception of type 'System.AccessViolationException' occurred in PortableDevices.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Is there anything I need to do differently to make this work, or do you know what the issue might be?

Thanks

Function DownloadFile crashes on the second file of an iteration

When using the function DownloadFile in a loop with multiple PortableDeviceFile:

  1. It works fine on the first file
  2. It throws an exception on the second file

The exception:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in PortableDevices.dll

Additional information: The requested resource is in use. (Exception from HRESULT: 0x800700AA)

I thought that maybe sourceStream needed to be closed, but that does not seem feasible with the current. Here is the line of the exception, marked with // !!! EXCEPTION:

    public void DownloadFile(PortableDeviceFile file, string saveToPath)
    {
        IPortableDeviceContent content;
        this._device.Content(out content);

        IPortableDeviceResources resources;
        content.Transfer(out resources);

        PortableDeviceApiLib.IStream wpdStream;
        uint optimalTransferSize = 0;

        var property = new _tagpropertykey();
        property.fmtid = new Guid(0xE81E79BE, 0x34F0, 0x41BF, 0xB5, 0x3F, 0xF1, 0xA0, 0x6A, 0xE8, 0x78, 0x42);
        property.pid = 0;

        // !!! EXCEPTION (on the second file)
        resources.GetStream(file.Id, ref property, 0, ref optimalTransferSize, out wpdStream);

        var sourceStream = (System.Runtime.InteropServices.ComTypes.IStream)wpdStream;

        var filename = Path.GetFileName(file.Name);
        FileStream targetStream = new FileStream(Path.Combine(saveToPath, filename), FileMode.Create, FileAccess.Write);

        unsafe
        {
            var buffer = new byte[1024];
            int bytesRead;
            do
            {
                sourceStream.Read(buffer, 1024, new IntPtr(&bytesRead));
                targetStream.Write(buffer, 0, 1024);
            } while (bytesRead > 0);
            targetStream.Close();               
        }
    }

DownloadFile function keeps file locked after downloading in MSC mode

I have an Android 4.4.2 device that uses MSC to access files via usb (appears as a normal storage device in windows) however after I use the DownloadFile function I cannot delete or alter the file in any way until I unplug the device and plug it back in. The message I get in Explorer is "The action can't be completed because the file is open in WUDFHost.exe".

This has worked fine with an MTP device but I want to be able to use both interchangeably and this is the only issue stopping that.

Add LICENSE file

@Duke-fleed - I would like to use your library in our app. I don't see a LICENSE file in the repro and would like to know how I may use the library. Can you add a LICENSE file? Thank you. @bbending626

File Transfer with Android Device

I am trying to read and write files to an Android Device. I was hoping to use this api. Is there any example code on reading and writing files, seeing if a file exists, looking at directories beneath the root? Any he,p would be greatly appreciated.

al

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.