Calling a VFP DLL from dotNet

[VFP Type Library in VB.Net] The first step is to add the VFP DLL to the resources of the dotNet project. Right-click on the Solution Explorer and pick Add Reference... from the menu. Select the COM tab on the References dialog and scroll down to find vfpcustomer Type Library. Click on the Show all files icon on the Solution Explorer toolbar to check that the reference has been added correctly.

Once you've added this reference to the project, VB's equivalent of Intellisense will recognise the new library and will suggest it as a type when you start writing the declarations in the program.

Write the program in VB.Net

This example uses a simple console application within Visual Basic. The program creates a customer object based on the VFP class, tells it to open a table then asks it to find the customer matching code "ANTON".

Sub Main()
   Dim intRecords As Integer
   Dim objCust As vfpcustomer.Customer

   '-- Create the customer and open the table.
   objCust = New vfpcustomer.Customer
   intRecords = objCust.OpenTable()
   Console.WriteLine(CStr(intRecords) & " records.")

   '-- Ask for the name of the custoemr coded as "Anton".
   If objCust.Getname("ANTON") Then
     Console.WriteLine(objCust.COMPANY)
   Else
     Console.WriteLine("Not found.")
   End If
  
   Console.ReadLine()
End Sub

The next steps

This short example has gone through the steps of writing a DLL in Visual FoxPro, testing it as a VFP class and then building it as a DLL before calling it from Visual Basic.

Doing this for a real project will be a much longer process but it might be easier than trying to convert FoxPro algorithms into a dotNet language. Many of our clients have been running Fox systems since the days of DOS. They are confident that the calculations embedded in these systems are correct. Using VFP DLLs as a halfway house on the way to developing a new dot Net system allows them time to make a gradual changeover to the new system.

Related Items

Alvechurch Data - Microsoft FoxPro and Access Database Development and Training

Alvechurch Data are based close to Birmingham and provide Microsoft Access and Visual FoxPro training, development and support.

Read More

Autocomplete in Visual Fox Pro

Autocomplete in Visual Fox Pro

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.

Read More

Access and Visual FoxPro Training

Microsoft Access and Visual FoxPro training courses and workshops offered by Alvechurch Data in Birmingham.

Read More

Geoff Franklin CV

Geoff Franklin - resume of education and experience in Access and Visual FoxPro programming.

Read More

Visual FoxPro Frequently Asked Questions

Frequently asked questions for Visual FoxPro

Read More