.NET IMAPI2 Code samples  
Author Message
AlexFeinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Here you will find code samples for the April 18th MSDN Webcast on IMAPI v2. The samples will be posted shortly after the webcast




Software Development for Windows Vista16  
 
 
AlexFeinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Here is a VBScript sample that shows how to erase a disc.

REM -
REM - Erases the current media in the recorder
REM -
FUNCTION fnEraseMedia( byRef recorder )
  DIM eraser
  REM the second argument hooks up the events with prefix "fnErase_"
  SET eraser = WScript.CreateObject("IMAPI2.MsftDiscFormat2Erase", "fnErase_")
  eraser.Recorder = recorder
  eraser.EraseMedia
END FUNCTION

REM -
REM - The event callback that occurs during an erase operation
REM -
FUNCTION fnErase_ProgressUpdate( byRef object, byRef elapsed, byRef estimated )
  WScript.Echo "Elapsed/Total Time: " & (elapsed \ 1000) & "/" & (estimated \ 1000)
END FUNCTION

DIM Master
set Master = WScript.CreateObject("IMAPI2.MsftDiscMaster2")
DIM Recorder
set Recorder = WScript.CreateObject("IMAPI2.MsftDiscRecorder2")
DIM id
id = Master.Item(0) ' first drive -- Master supports Count() and Item()
Recorder.InitializeDiscRecorder(id)
fnEraseMedia(Recorder)




 
 
AlexFeinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Are you building it on a Vista machine

If so, could you remove a reference to IMAPI2 and re-add it using COM tab



 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

I readded the references - same run time result.

What do you think of all the warnings though...

------ Rebuild All started: Project: Demo3, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.ReadDvdStructure' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetAdapterDescriptor' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetDeviceDescriptor' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetDiscInformation' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetTrackInformation' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetFeaturePage' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetModePage' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetSupportedFeaturePages' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetSupportedProfiles' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftDiscRecorder2.GetSupportedModePages' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.ReadDvdStructure' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetAdapterDescriptor' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetDeviceDescriptor' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetDiscInformation' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetTrackInformation' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetFeaturePage' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetModePage' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetSupportedFeaturePages' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetSupportedProfiles' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IDiscRecorder2Ex.GetSupportedModePages' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'MsftStreamPrng001.get_ExtendedSeed' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets : warning : At least one of the arguments for 'IStreamPseudoRandomBased.get_ExtendedSeed' cannot be marshaled by the runtime marshaler. Such arguments will therefore be passed as a pointer and may require unsafe code to manipulate.
C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:..\..\Lib\ImapiHelperLib.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:obj\Debug\Interop.IMAPI2.dll /reference:obj\Debug\Interop.IMAPI2FS.dll /debug+ /debug:full /optimize- /out:obj\Debug\Demo3.exe /target:exe Program.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
Demo3 -> C:\chris\SampleApp3\Demo3\Demo3\bin\Debug\Demo3.exe
Done building project "Demo3.csproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========


 
 
AlexFeinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Here are three more samples:

SampleApp1 and SampleApp2: demonstrate (VB.NET), how to obtain recorder and media information. Command line.

SampleApp3: demonstrates (C#) how to add files to a filesystem image, burn the disk and receive events.

There are some minor complications with using IMAPI2 autogenerated interop libraries with .NET languages, so some of this projects use helper classes to deal with it. Hopefully, but RTM we would see the interop libraries shipped with the OS.



 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

No - I'm building on XPsp2

(Are you successful in doing most of your dev work on Vista Is there a dog food eating mandate going on there at Microsoft )


 
 
Alex Feinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

The warnings are expected - the IDiscRecorder2Ex interface uses some wicked data structures. Again, are you running your test on a Vista box

 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Yes, building and running on Vista (5384)


 
 
AlexFeinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

On XP you can compile (if you copy over the IMAPI2.dll and IMAPI2FS.dll and update references), but you cannot test, since currently IMAPI2 is only supported on the Vista platform.

I am quite successful in doing my development on Vista, although for the resasons of convenience I tend to turn off UAC first :) I've done some driver work recently and even used a Vista build 5308 machine to show my demos during MEDC 2006. Basically the only development-related problem with Vista that I am aware of is that there is no Activesync, so you can't deploy to/debug on attached mobile devices (emulator works).

As for dogfood, yes, as far as I know (I am not a Microsoft employee).



 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Ok, thanks Alex. For some reason, I thought I had read that IMAPI2 was going to support XP also. (I think m$ leaving xp behind in a way on this and the sidebar and who knows what else will hurt them.)

So I copied those files from a Vista Beta2 system onto my dev machine.

Then I regsvr32 them and it built fine.

So I moved the release build (the entire directory) over to the Vista machine and try running it.

After it finally dawning on me that it isn't a gui lol I made a directory to match yours in the source c:\users\alexf\data\ and put some stuff in it. I try running demo3.exe.

Then it crashes...

crash

I haven't gotten a chance to try and debug it yet (machine is shared with others), but it is a Sony Vaio desktop computer with a dvd r/rw drive (with no network access - so much for remote debug)


 
 
venki99





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Hi foobar,

Is this issue resolved, I am also facing similar issue, if have found the solution/solved it... Please let me know.

I am trying to automate the build and when i ran the team build i got the below error

Solution: Net2.sln, Project: Net2.Business.csproj, Compilation errors and warnings

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(0,0): warning MSB3287: Cannot load type library for reference "ADDRESSOBJECTLib". Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).

Solution: , Project: Net2.sln, Compilation errors and warnings

(0,0): warning MSB3021: Unable to copy file "D:\NetTeamBuild\BuildLocation\NET2\Testbuild\Net\CommonFiles\Assemblies\Ajax.dll" to "Phly.PathNet2.Presentation\\Bin\Ajax.dll". Could not find a part of the path 'D:\NetTeamBuild\BuildLocation\NET2\Testbuild\Net\CommonFiles\Assemblies\Ajax.dll'.

(0,0): warning MSB3021: Unable to copy file "D:\NetTeamBuild\BuildLocation\NET2\Testbuild\Sources\Program Files\Obout\Component\NET2.0\obout_Splitter2_Net.dll" to "Net2.Presentation\\Bin\obout_Splitter2_Net.dll". Could not find a part of the path 'D:\NetTeamBuild\BuildLocation\NET2\Testbuild\Sources\Program Files\Obout\Component\NET2.0\obout_Splitter2_Net.dll'.

Any help or pointer regarding this is deeply appreciated.

Thanks,

Venki


 
 
Alex Feinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Yes, please run it under de****. Unfortunately oh so helpful windows error reporting (WER) is a pain if you are in development mode. I suggest turning it off so that you see more informative error messages

 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Didn't get a chance to get a de**** on it yet...

But, with (good ) old-fashioned "printf" debugging - I do know that it fails on the last line:

fmt.Write((System.Runtime.InteropServices.ComTypes.IStream)stm);

with a nice HRESULT: E_FAIL (0x80004005)

(I'm not sure how useful an app de**** is going to be at this point...)

Another datapoint, burning a UDF worked on that system (the prompt you get from explorer when you put a blank dvd in) - I assume that is using IMAPI2


 
 
Alex Feinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

How big was the image at that point I.e. what is the total size of the directory that you were burning I might have forgot to set the correct filesystem type if this were a DVD-sized image, although I would expect a different error code.

 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Relatively tiny!

84 files, 7 folders, 346KB

(For some reason, I thought that the new APIs like IMAPIv2 were going to be managed APIs grrrr)


 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

C# demo3 still not working...

The msdn sample works...

"C:\Program Files\Microsoft SDKs\Windows\v1.0\samples\winbase\storage\optical\imapi2sample"


 
 
Alex Feinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

I'm looking into it

 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

I've got VS2005 on that vista machine now.

I rebuilt there, made sure a blank dvd-r was in the drive, and ran, stepping over each step.

But it hangs indefinitely on Program.cs, line 34

string recorderID = new MsftDiscMaster2Class()[0];


 
 
Alex Feinman





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Could you separate the MsftDiscMasterClass creation and the array access to see which exactly part hangs

 
 
foobarX





PostPosted: Optical Platform Discussion, .NET IMAPI2 Code samples Top

Sorry, that was my mistake - no hang (some instrumentation I had put in was blocking)

From the IDE it behaves exactly like the binaries I had built on XP.

(E_FAIL on the Write() call)

I thought I might be able to glean something by stopping on _com_error, but it didn't reveal anything.