Click here to Skip to main content
15,885,151 members
Articles / Programming Languages / Visual Basic

Using Microsoft Interoperability Libraries

Rate me:
Please Sign up or sign in to vote.
3.13/5 (4 votes)
18 Apr 20063 min read 57.4K   491   15  
How to use Visual C++ unmanaged code with VB.NET.
Imports DirectoryWrapperLibrary

Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim diary As New CContactDiary

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnAddContact As System.Windows.Forms.Button
    Friend WithEvents btnSearchContact As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents contactInfo As System.Windows.Forms.GroupBox
    Friend WithEvents lblFirstName As System.Windows.Forms.Label
    Friend WithEvents btnDeleteContact As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents lblEMail As System.Windows.Forms.TextBox
    Friend WithEvents lblFName As System.Windows.Forms.TextBox
    Friend WithEvents lblLName As System.Windows.Forms.TextBox
    Friend WithEvents lblAddress As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnAddContact = New System.Windows.Forms.Button
        Me.btnSearchContact = New System.Windows.Forms.Button
        Me.contactInfo = New System.Windows.Forms.GroupBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.lblFirstName = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.btnDeleteContact = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        Me.lblEMail = New System.Windows.Forms.TextBox
        Me.lblFName = New System.Windows.Forms.TextBox
        Me.lblLName = New System.Windows.Forms.TextBox
        Me.lblAddress = New System.Windows.Forms.TextBox
        Me.contactInfo.SuspendLayout()
        Me.SuspendLayout()
        '
        'btnAddContact
        '
        Me.btnAddContact.Location = New System.Drawing.Point(24, 64)
        Me.btnAddContact.Name = "btnAddContact"
        Me.btnAddContact.Size = New System.Drawing.Size(104, 23)
        Me.btnAddContact.TabIndex = 0
        Me.btnAddContact.Text = "Add Contact"
        '
        'btnSearchContact
        '
        Me.btnSearchContact.Location = New System.Drawing.Point(256, 64)
        Me.btnSearchContact.Name = "btnSearchContact"
        Me.btnSearchContact.Size = New System.Drawing.Size(104, 23)
        Me.btnSearchContact.TabIndex = 2
        Me.btnSearchContact.Text = "Search Contact"
        '
        'contactInfo
        '
        Me.contactInfo.Controls.Add(Me.lblEMail)
        Me.contactInfo.Controls.Add(Me.lblFName)
        Me.contactInfo.Controls.Add(Me.lblLName)
        Me.contactInfo.Controls.Add(Me.lblAddress)
        Me.contactInfo.Controls.Add(Me.Label3)
        Me.contactInfo.Controls.Add(Me.lblFirstName)
        Me.contactInfo.Controls.Add(Me.Label2)
        Me.contactInfo.Controls.Add(Me.Label4)
        Me.contactInfo.Location = New System.Drawing.Point(24, 104)
        Me.contactInfo.Name = "contactInfo"
        Me.contactInfo.Size = New System.Drawing.Size(352, 176)
        Me.contactInfo.TabIndex = 5
        Me.contactInfo.TabStop = False
        Me.contactInfo.Text = "Search Result"
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.Location = New System.Drawing.Point(24, 99)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(128, 23)
        Me.Label3.TabIndex = 7
        Me.Label3.Text = "Address"
        '
        'lblFirstName
        '
        Me.lblFirstName.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFirstName.Location = New System.Drawing.Point(24, 19)
        Me.lblFirstName.Name = "lblFirstName"
        Me.lblFirstName.Size = New System.Drawing.Size(128, 23)
        Me.lblFirstName.TabIndex = 6
        Me.lblFirstName.Text = "First Name"
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(24, 59)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(128, 23)
        Me.Label2.TabIndex = 7
        Me.Label2.Text = "Last Name"
        '
        'Label4
        '
        Me.Label4.Font = New System.Drawing.Font("Verdana", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.Location = New System.Drawing.Point(24, 139)
        Me.Label4.Name = "Label4"
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "EMail"
        '
        'btnDeleteContact
        '
        Me.btnDeleteContact.Location = New System.Drawing.Point(136, 64)
        Me.btnDeleteContact.Name = "btnDeleteContact"
        Me.btnDeleteContact.Size = New System.Drawing.Size(104, 23)
        Me.btnDeleteContact.TabIndex = 1
        Me.btnDeleteContact.Text = "Delete Contact"
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Verdana", 15.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(24, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(344, 40)
        Me.Label1.TabIndex = 7
        Me.Label1.Text = "Contact Diary"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'btnOK
        '
        Me.btnOK.Enabled = False
        Me.btnOK.Location = New System.Drawing.Point(32, 288)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(96, 23)
        Me.btnOK.TabIndex = 7
        Me.btnOK.Text = "OK"
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(144, 288)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(88, 23)
        Me.btnExit.TabIndex = 8
        Me.btnExit.Text = "Exit"
        '
        'lblEMail
        '
        Me.lblEMail.Enabled = False
        Me.lblEMail.Location = New System.Drawing.Point(168, 142)
        Me.lblEMail.Name = "lblEMail"
        Me.lblEMail.Size = New System.Drawing.Size(152, 20)
        Me.lblEMail.TabIndex = 6
        Me.lblEMail.Text = ""
        '
        'lblFName
        '
        Me.lblFName.Enabled = False
        Me.lblFName.Location = New System.Drawing.Point(168, 22)
        Me.lblFName.Name = "lblFName"
        Me.lblFName.Size = New System.Drawing.Size(152, 20)
        Me.lblFName.TabIndex = 3
        Me.lblFName.Text = ""
        '
        'lblLName
        '
        Me.lblLName.Enabled = False
        Me.lblLName.Location = New System.Drawing.Point(168, 62)
        Me.lblLName.Name = "lblLName"
        Me.lblLName.Size = New System.Drawing.Size(152, 20)
        Me.lblLName.TabIndex = 4
        Me.lblLName.Text = ""
        '
        'lblAddress
        '
        Me.lblAddress.Enabled = False
        Me.lblAddress.Location = New System.Drawing.Point(168, 102)
        Me.lblAddress.Name = "lblAddress"
        Me.lblAddress.Size = New System.Drawing.Size(152, 20)
        Me.lblAddress.TabIndex = 5
        Me.lblAddress.Text = ""
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 326)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.btnDeleteContact)
        Me.Controls.Add(Me.contactInfo)
        Me.Controls.Add(Me.btnSearchContact)
        Me.Controls.Add(Me.btnAddContact)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.contactInfo.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddContact.Click
        Me.lblFName.Enabled = True
        Me.lblLName.Enabled = True
        Me.lblAddress.Enabled = True
        Me.lblEMail.Enabled = True

        Me.lblFName.Text = ""
        Me.lblLName.Text = ""
        Me.lblAddress.Text = ""
        Me.lblEMail.Text = ""

        Me.btnOK.Enabled = True
        Me.btnOK.Text = "Add"

    End Sub

    Private Sub btnSearchContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchContact.Click
        Me.lblFName.Enabled = True
        Me.lblLName.Enabled = True
        Me.lblAddress.Enabled = False
        Me.lblEMail.Enabled = False
        Me.btnOK.Enabled = True
        Me.btnOK.Text = "Search"
    End Sub

    Private Sub btnDeleteContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteContact.Click
        Me.lblFName.Enabled = True
        Me.lblLName.Enabled = True
        Me.lblAddress.Enabled = False
        Me.lblEMail.Enabled = False
        Me.btnOK.Enabled = True
        Me.btnOK.Text = "Delete"
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If (Me.btnOK.Text = "Add") Then
            diary.AddContact(Me.lblFName.Text, lblLName.Text, lblAddress.Text, lblEMail.Text)
            Me.lblFName.Enabled = False
            Me.lblLName.Enabled = False
            Me.lblAddress.Enabled = False
            Me.lblEMail.Enabled = False
            Me.btnOK.Enabled = False
        ElseIf (Me.btnOK.Text = "Delete") Then
            diary.DeleteContact(Me.lblFName.Text + Me.lblLName.Text)
        ElseIf (Me.btnOK.Text = "Search") Then
            diary.SearchContactByName(Me.lblFName.Text + Me.lblLName.Text, Me.lblFName.Text, lblLName.Text, lblAddress.Text, lblEMail.Text)
            Me.lblFName.Enabled = False
            Me.lblLName.Enabled = False
            Me.lblAddress.Enabled = False
            Me.lblEMail.Enabled = False
        End If
        Me.btnOK.Enabled = False
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Pakistan Pakistan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions