DVBViewer & C# – Getting Started

27 09 2008

I do all my development within Virtual PC which I recommend, it allows you to test software without worrying that it’ll cause problems with your main windows installation.

I’m starting this series on posts (don’t expect them to be regular) to document my learning curve in trying to program in C# using dvbviewer and hopefully get other dvbviewer users interested and hopefully create a english knowledge base

So to start of you’ll need to download/install the free Visual C# version of Visual Studio Express 2008 (recommend doing offline install), then follow the next steps:-

Launch DVBViewer (this needs to be left open as this is what your C# program will comunicate with)

Launch Visual C# and start a new project [File], [New Project…]

select ‘Windows Forms Application’ as your template and give it a name (eg MyDemo), then [OK]

You should now see a form like below,

next we need to set a reference to DvbViewer, select menu [Project], [Add Reference…], Tab ‘COM’, scroll down to DVBViewer COM, highlight and click [OK]

You should now see DVBViewerServer appear in references on the Solution Explorer (right side of screen)

From your toolbox on the left drag onto your Form1 a ‘Label’ and a ‘Button’ as shown below

Double click on [button1], you’ll be taken to the code behind the button, we’re going to write some code here to pull some data from DVBViewer when the button is clicked.

First at the top of our code we need to declare that we’ll be using the dvbviewer reference we added earlier by added the following line

using DVBViewerServer;

Then within our button1_Click sub we add the following lines, first binds the dvbviewer object to a variable type name (saves us having to retype), and the second line will set lablel1 to a value from dvbviewer when the button is pressed :-

DVBViewer dvb = (DVBViewer)System.Runtime.InteropServices.Marshal.GetActiveObject("DVBViewerServer.DVBViewer");

label1.Text = dvb.TimerManager.Count.ToString(); 

This is all the coding we’re going to do so it’s now time to test our simple application, click the start debugging button [>] or press F5

Click [button1] and your label1 will change to a number that represents the number of timers you got waiting in your Dvbviewer timer.  Go into dvbviewer and add another timer, save it and the click [button1] again, it should increase.