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.