INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Classes and Objects

Build a .NET DLL and use it in VFP by craigsboyd
Posted: 6 Jul 03 (Edited 22 Jul 03)

Slighthaze = NULL
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)

Back to Microsoft: Visual FoxPro FAQ Index
Back to Microsoft: Visual FoxPro Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close