Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build a .NET DLL and use it in VFP

Classes and Objects

Build a .NET DLL and use it in VFP

by  craigsboyd  Posted    (Edited  )
Slighthaze = [color blue]NULL[/color]
Using Visual Studio .NET create a C# Class Library project and name it "VFPMath" (I used "E:\Temp\NETDLLFORVFP6 for my location)

C# code for the Class1.cs file:

using System;

namespace VFPMATH {

public class MathFunctions : System.EnterpriseServices.ServicedComponent {
public Int32 Add(Int32 x, Int32 y) { return(x + y);}
public Int32 Subtract(Int32 x, Int32 y) { return(x - y);}
public Int32 Multiply(Int32 x, Int32 y) { return(x * y);}
public Int32 Divide(Int32 x, Int32 y) { return(x / y);}
}
}


...next in your Solution Explorer add a reference to "System.EnterpriseServices"

...then from a DOS command prompt, create a random key pair and store it in VFPMath.snk (You can use the Strong Name tool to do this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfstrongnameutilitysnexe.asp)

Here is what my DOS command looked like for creating the VFPMath.snk file:

E:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin>SN -k VFPMath.SNK

..next I copied VFPMath.snk into the folder where my dll was going to be built (I just used the "debug" folder in "bin", since I wasn't looking to release this)

Then back in your Solutions Explorer (in C#) select the AssembliesInfo.cs and look for the line that reads:

[assembly: AssemblyKeyFile("")]

...and change it to...
[assembly: AssemblyKeyFile("E:\\Temp\\NETDLLFORVFP6\\VFPMATH\\bin\\Debug\\VFPMath.SNK")]

...as you can see I am using the fullpath, but you could use something relative or in the search path.

Then build your dll and go back to the DOS command prompt to register it. (I used the following command to register mine (modify your's to suit):

E:\Temp\NETDLLFORVFP6\VFPMATH\bin\Debug>C:\WINNT\Microsoft.NET\Framework\v1.0.37
05\RegSvcs VFPMath.dll
)

Once the assembly is installed go into VFP and run the following from the command window:

oVFPMath = CreateObject("VFPMath.MathFunctions")
?oVFPMath.add(5,4)
?oVFPMath.subtract(5,4)
?oVFPMath.multiply(5,4)
?oVFPMath.divide(5,4)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top