Click here to Skip to main content
Click here to Skip to main content

vbBurnMedia v1.0

, 14 May 2011
Rate this:
Please Sign up or sign in to vote.
Using the Image Mastering API in VB.NET
vbBurnMedia_image003.png

Introduction

I needed the ability to burn data to optical media in several VB.NET applications.

As a starting point, I reviewed Eric Haddan’s CodeProject article that provided a C# application to burn optical media. Please take a look at his article titled “Burning and Erasing CD/DVD/Blu-ray Media with C# and IMAPI2”. Eric’s article provided a great learning tool, thank you Eric. However it was not usable in a VB.NET project. From his work, I developed a plan with two goals:

  1. Convert Eric’s C# application to a VB.NET application.
  2. Refactor the application such that the optical recording code was encapsulated into its own project.

With two goals tasked for this, it was decided to create two separate versions of vbBurnMedia. In version 1.0, Eric’s code would be converted to VB.NET without modification. Once this version was working correctly, a second version, 1.1, would implement the second goal of refactoring the project.

Conversion to VB.NET

The first step was to create a new VB.NET windows project and copy all of Eric’s code and windows layout to the new project. My focus was on the conversion of C# syntax to VB and not on the overall task of what I was doing. As the first step, I added a reference to Imapi2 and Imapi2FS. Changing C# syntax to VB.NET went pretty quickly without any problems. With syntax converted, I began testing and debugging vbMediaBurn. I started with the simple tasks such as DetectMedia and FormatMedia. Everything went smoothly until I got to the last piece of code to test, BurnMedia. When I attempted to burn data to a CD, I received an exception:

Unable to cast object of type 'IMAPI2FS.FsiStreamClass' to type 'IMAPI2.IStream'. 

I had fallen into the first problem that Eric had warned about in his article. After some thought, I realized I had two choices:

  1. Convert Interop.cs to a VB.NET file (Interop.vb)
  2. Use Interop.cs without modification in a separate C# project

After some review of what it would entail to convert Interop.cs to VB.NET class, I quickly decided that was a very bad choice. That left the option of placing Interop.cs in its own C# project. This looked fairly simple to implement. I removed the Imapi2 references and added a new C# project to my project for Interop.cs, I began testing and debugging the code and things looked good, the conversion had gone very smoothly. That was until I found that the _Update handlers were never processing. After many, many, many hours of frustration trying to figure out the problem, I stumbled across a Google discussion that pointed out the problem (I lost the reference to this web page, but would like to thank the author anyway). You must check the “Make assembly COM visible” checkbox in the Interop project. Go to project Properties, select the Application tab, then select the Assembly Information button.

vbBurnMedia_image001.png

That fixed the problem. At this point, version 1.0 was operational and the first goal of the project was successfully completed. Total time was about 20 hours of effort which was much more effort than I expected, but still less than starting from scratch.

Points of Interest

I would like to thank Eric for his work, it provided a great starting point and saved an enormous amount of time. As payback to the community, my hope is that vbBurnMedia will save others time as well.

History

  • 2011.May.09; version 1.0 Completed conversion of C# application to VB.NET

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Bruce Ellsworth

United States United States
No Biography provided

Comments and Discussions

 
GeneralExcellent Job PinmemberKimbo_Lacool3-Aug-11 1:32 
GeneralYou made my day ... Pinmemberus471116-May-11 21:49 
GeneralMy vote of 5 Pinmemberrspercy6015-May-11 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 14 May 2011
Article Copyright 2011 by Bruce Ellsworth
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid