INNOBATE™ AntiVirus Client SDK AVClientComponent Windows Presentation Foundation Visual Basic Walkthrough
The following walkthrough example will demonstrate how to add the INNOBATE AntiVirus AVClient Component to any Windows Presentation Foundation Visual Basic Project. The example will lead you through the creation of a Visual Studio WPF project and using Visual Basic for its code write up.
Note: You can also get additional examples from our examples page with a C# example.
1. INNOBATE AntiVirus SDK Example Download
2. INNOBATE AntiVirus 2012 Standard download
3. Visual Basic 2010 Express Download or Visual Basic 2008 Express Edition
1. Download and install INNOBATE AntiVirus Basic if you have not done so on your development computer.
2. Download INNOBATE AntiVirus SDK Example on to the C:\ of development computer.
3. Unzip the contents INNOBATE AntiVirus SDK Example on your development computer. Windows will unzip the contents of the IAV SDK to the following location:- "C:\INNOBATE AntiVirus AVClient Demo"
Creating a Windows Presentation Foundation Project
1. Launch Visual Studio 2008 or Visual Basic 2008 Express or Visual Basic 2010 Express.
2. From the File menu select the New Project menu option.
3. From the Project types tree list, select Visual Basic. This should show the templates available for Visual Basic projects.
4. Make sure the target .NET Framework is set to .NET Framework 3.0 or greater, as you will not be able to see the WPF Application project template in visual studio. To change the target framework to 3.0, use the dropdown list combobox found at the top right corner of the New Project dialog window.
5. Select the WPF Application from the Templates pane on the New Project dialog window.
6. Now give the project a name using the Name field. In the Name field enter the following without the quotemarks, “INNOBATE AntiVirus AVClient Demo WPF”.
Click the OK button. Now an empty WPF Application project will be displayed with Visual Studio or Visual Basic Express IDE.
Adding the IAV SDK references
1. From the project menu select the Add Reference… menu option. This will open the Add Reference Dialog.
2. Select the Browse tab from the Add Reference dialog. Use the Look in drop down list to select C:\ drive. Navigate to theINNOBATE AntiVirus AVClient Demo Folder. Double click the INNOBATE AntiVirus AVClient Demo folder.
3. From the contents of the INNOBATE AntiVirus AVClient Demo select and open the AVClient folder by doubling clicking on it.
4. From the contents of the AVClient folder, double click on theINNOBATEAntiVirusAVClient.dll. At this point, a warning will be displayed stating that INNOBATEAntiVirusAVClient.dll or one of its dependances requires a later version of the .NET Framework than the one specified in the project.
5. Select the Yes button.
6. Select the OK button.
7. Toggle the Show All files toggle button in the Solution Explorer pane, until you can see the Reference folder icon displayed in the Solution Explorer.
8. Double click the Reference folder in the solution explorer pane to expand it. Now you should be able to see INNOBATEAntiVirusAVClient as an added reference to the project.
Adding Visual Elements to the project’s Window
1. From the View menu select the Toolbox menu option. This will show the Toolbox pane or window, depending on how your Visual Studio, or Visual Basic IDE is setup. If Window1.xaml is not displayed in the Code Pane of the IDE, double click on it from the Solution Explorer pane of the IDE. This should open it up in design view with the code pane of the IDE.
2. From the toolbox select the TextBox control from the controls tab of the toolbox and drop it onto the control grid of Window1.xaml. Drag the textbox control on the control grid until it is at the top left of the grid control.
3. Resize the textbox, by dragging its right edge with the mouse to right most edge of the grid control.
4. Resize the textbox, by dragging its bottom edge with the mouse to the middle of the control grid.
5. Select and drop a second Textbox control on the control grid of Window1.xaml. Drag the second textbox control on the control grid until it is at the bottom left of the grid control.
6. Resize the second textbox, by dragging its top edge with the mouse to cover the lower quarter the grid control.
7. Resize the second textbox, by dragging its right edge with the mouse to right most edge of the grid control.
8. Select and drop a third Textbox control onto the middle of the control grid of Window1.xaml.
9. From the toolbox, select and drop a button to the right of the third textbox.
10. From the toolbox, select and drop a second button to the right of the first button control. At this point you should have something like the diagram shown below.
You can at this stage move the controls that you have just added to the grid control around so that you get the desired effect. You may even have to resize the Window1 control, this can be done by dragging the edges of Window1 control in the design view. Once you are happy with the desired effect or placement of all the controls within Window1.xaml’s design pane, you can use the next section of this document to add some Visual Basic code.
Wiring up the Events of the Visual Elements.
1. Right click on Window1 visual element within the Design view of Window1.xaml. From the popup menu select the View Code option.
2. Now the Code Pane for the Window1 visual element will be displayed. Some skeleton code will be shown:-
Class Window1End Class
3. Just above the selekton code for Class Window1 add the following Imports statements to the code:-
Imports INNOBATE.AntiVirusImports Microsoft.Win32
And now you show have the following:-
Imports INNOBATE.AntiVirusImports Microsoft.Win32Class Window1End Class
Now we need to add the AvClientComponent and OpenFileDialog as variables (fields) to the Window1 Class.
4. With the skeleton code of Window1 Class add the following:-
Dim WithEvents AvClientComponent1 As New INNOBATE.AntiVirus.AVClientComponentDim WithEvents OpenFileDialog1 As New OpenFileDialog
You should now have something like this:-
Class Window1Dim WithEvents AvClientComponent1 As New INNOBATE.AntiVirus.AVClientComponentDim WithEvents OpenFileDialog1 As New OpenFileDialogEnd Class
Now some code needs to be added to handle the FileOK event of the OpenFileDialog. Add the following code under the variables just declared within the Class Window1:-
Private Sub OpenFileDialog1_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) _ Handles OpenFileDialog1.FileOk TextBox3.Text = OpenFileDialog1.FileName If AvClientComponent1.AutoScanFilePath Then AvClientComponent1.FilePathToScan = OpenFileDialog1.FileName End If End Sub
Now Event handler code for AvClientComponent1 needs to be added to handle when a virus is found within a file or a scanning error occurs while scanning a file. Add the following code:-
Private Sub AvClientComponent1_VirusFound(ByVal File As String, ByVal VirusName As String, _ ByVal FoundTime As Date, _ ByVal QurantineFileName As String) _ Handles AvClientComponent1.VirusFound Me.TextBox1.Text = VirusName & " :- Found in '" & File & "' and is now qurantined as " & QurantineFileName & " at the following time: " & FoundTime & vbCrLf & Me.TextBox1.TextEnd SubPrivate Sub AvClientComponent1_ErrorOccured(ByVal Ex As System.Exception) Handles AvClientComponent1.ErrorOccured Try TextBox2.Text = Ex.ToString & vbCrLf & Ex.Source & vbCrLf & Ex.StackTrace.ToString & vbCrLf & Ex.Source & vbCrLf & TextBox2.Text Catch ex As Exception My.Log.WriteException(Ex) End TryEnd SubPrivate Sub AvClientComponent1_NoVirusFound(ByVal File As String) Handles AvClientComponent1.NoVirusFound Me.TextBox1.Text = " No Virus Found in '" & File & "'" & vbCrLf & Me.TextBox1.TextEnd Sub
Now the Click events of both the button visual elements need to be handled so the following code needs to be added:-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click OpenFileDialog1.ShowDialog() End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click AvClientComponent1.ScanFilePath(TextBox3.Text)End Sub
Compiling the Application
The project can be compiled, using the Build menu, given below are the instructions on how to do this.
1. Select the Build INNOBATE AntiVirus AVClient Demo WPF menu option from the Build Menu. This will compile the project into an Application. Once the project has been compiled, the application can be located in the following path:- "C:\ INNOBATE AntiVirus AVClient Demo WPF\bin\release" and the executable is INNOBATE AntiVirus AVClient Demo WPF.exe.
2. Navigate to "C:\ INNOBATE AntiVirus AVClient Demo WPF\bin\release" on your development computer.
3. Double clicking on the INNOBATE AntiVirus AVClient Demo WPF.exe will run the application within Microsoft Windows.
4. To use the INNOBATE AntiVirus AVClient Demo WPF, Click the browse button. When the open file dialog is shown, use it to select any file on your computer system. Click the OK button. 5. Click the Scan File button, this will begin scanning of the file selected in step 4. After a few moments the application will tell you if the file is clean or infected with a virus.
Congratulations, you just successfully created a basic WPF application with integrated antivirus capabilities.