duke-fleed / wpdapi Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
@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
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
_deviceManager.GetDevices(ref deviceIds[0], ref count); returns just 1 device every time. https://code.msdn.microsoft.com/windowsdesktop/Portable-Devices-COM-API-fd4a5f7d/view/SourceCode here i get 2 devices instead of 1.
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
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.
When using the function DownloadFile
in a loop with multiple PortableDeviceFile
:
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();
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.