Using Windows Portable Devices from c#



Hi Folks -

Does anyone know what MS's current position is on using the WPD API
from C# via COM interop?

I've found a few resources, three out of four MS resources:

http://blogs.msdn.com/dimeby8
http://code.google.com/p/zenses/
http://www.codeplex.com/WpdTempSensor
http://blogs.msdn.com/wpdblog/default.aspx

The blog postings all drop off around the beginning of 2008. What
happened?

I'm going to have to go to C++, because I can't get a transfer to the
device happening via the IStream returned by
CreateObjectWithPropertiesAndData. For posterity, here's as far as
I've gotten - maybe someone else has gotten stuck at the same spot and
can lend a hand:
<snip>
PortableDeviceClass dev = dm.GetDevice(LastDevice.Id);
if (dev != null)
{
IPortableDeviceContent contentRef = null;
dev.Content(out contentRef);
Stream streamToFile = new FileStream(destinationFile,
FileMode.Open, FileAccess.Read);
PortableDeviceValuesClass props = new PortableDeviceValuesClass();
SetProps(ref props, destinationFile, size);
PortableDeviceApiLib.IStream objStream = null;
uint bufSize = 0;
string cookie = string.Empty;

contentRef.CreateObjectWithPropertiesAndData((PortableDeviceApiLib.IPortableDeviceValues)props,
out objStream,
ref bufSize,
ref cookie);// last
param cookie - null in c++ sample

System.Runtime.InteropServices.ComTypes.IStream myStream =
(System.Runtime.InteropServices.ComTypes.IStream)objStream;
bool bRetry = false;
try
{
int bytesWritten =
StreamCopy(destinationStream,
myStream,
bufSize);
</snip>
....and so on. There is a Write operation on myStream in the
StreamCopy() method which throws a COMException:

System.Runtime.InteropServices.COMException (0x8007007A): The data
area passed to a system call is too small. (Exception from HRESULT:
0x8007007A).

I hope this helps anyone else looking into using WPD API interop. The
dimeby8 blog mentioned above hints at success in moving resources FROM
a device using the api, and I can iterate over connected devices and
get device properties just fine, so it's not entirely useless.

Ben McAllister
http://www.listenfaster.com
.



Relevant Pages

  • Re: C# ASP.Net interop with MsWord
    ... You do not want to run run Word interop (for creating and modifying ... etc.) and this is why you couldnt find any resources regarding using Word ... > I have no problem in creating or modifying a word document in ASP.Net, ... > MSWord, given in the ASP.Net and C# environment. ...
    (microsoft.public.dotnet.languages.csharp)
  • Memory leak with this code
    ... I understand cleaning up your resources, but usually I am using a VS generated interop library, or primary interop assemblies. ...
    (microsoft.public.dotnet.framework.interop)