Take the following steps to create and run a program that enumerates the available WIA devices on your machine.
Start Visual Studio .NET.
Choose File->New->Project… from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application" in the Templates List.
Type the project name as "Enumerate WIA Devices" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
In the "Solution Explorer" window, right-click on the "References" folder, and select "Add Reference…" from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and browse to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder and select the following DLLs:
Click the Select button and then press the OK button to add the above DLL to the application.
Go to the toolbox (View->Toolbox) and Drag and drop 1 instance of Button control to the top of the form and set the following properties for them:
Text | Name |
---|---|
Enumerate WIA Devices | btnEnumWiaDevices |
Switch to Form1 code view (right-click Form1 in the solution explorer then select View Code) and add the following lines at the beginning of the file:
Imports Leadtools.Wia
using Leadtools.Wia;
Declare the following private variable:
Private WithEvents session As WiaSession
private WiaSession session;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
session = new WiaSession
session.Startup(WiaVersion.Version1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
session = new WiaSession();
session.Startup(WiaVersion.Version1);
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Add an event handler to the Form1 Closing event and code it as follows:
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
session.Shutdown()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
session.Shutdown();
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Add an event handler to the session EnumDevicesEvent event and code it as follows:
Private Sub session_EnumDevicesEvent(ByVal sender As Object, ByVal e As WiaEnumDevicesEventArgs) Handles session.EnumDevicesEvent
Dim strMsg As String = String.Format("Device ID: {0}{1}Device Name: {2}{1}Device Description: {3}", e.DeviceID, Constants.vbLf, e.DeviceName, Constants.vbLf, e.DeviceDesc)
MessageBox.Show(strMsg, "Available WIA Devices")
End Sub
private void session_EnumDevicesEvent(object sender, WiaEnumDevicesEventArgs e)
{
string strMsg = string.Format("Device ID: {0}\nDevice Name: {2}\nDevice Description: {3}", e.DeviceID, e.DeviceName, e.DeviceDesc);
MessageBox.Show(strMsg, "Available WIA Devices");
}
Add an event handler to the btnEnumWiaDevices Click event and code it as follows:
Private Sub btnEnumWiaDevices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnumWiaDevices.Click
Try
session.EnumDevices()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
private void btnEnumWiaDevices_Click(object sender, System.EventArgs e)
{
try
{
session.EnumDevicesEvent += new EventHandler<WiaEnumDevicesEventArgs>(session_EnumDevicesEvent);
session.EnumDevices();
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET