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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using .Net DLLs in FoxPro 6 1

Status
Not open for further replies.

davewelsh

Programmer
Jun 26, 2001
71
CA
Has anyone successfuly made a .Net Class Library and used it in FoxPro? If so can you provide the code needed in both FoxPro and in the .Net language of your choice?

I made a Class Library that compiles and can be used in other .Net projects, but I can't seem to register it for use in FoxPro.
 
VFP 6.0 was developed before .NET. Consider upgrading to 7.0 or better yet 8.0 - it's been out 4 months now!

Rick
 
Either way, the DLLs made with a .Net language can supposedly be used in COM languages, whether it's Visual FoxPro 6 or 600. I just can't find out the proper syntax.
 
davewelsh,

What syntax are you using now that isn't working in VFP 6?

Slighthaze = NULL
 
davewelsh,

Ok I just finished doing it with C# for VFP 6 or 7.

Using Visual Studio .NET create a C# Class Library project and name it "VFPMath" and I used "E:\Temp\NETDLLFORVFP6 for my location...

C# code for the Class1.cs file:

Code:
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 and create a random key pair and stores it in VFPMath.snk You can use the Strong Name tool to do this:

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

..now I copied VFPMath.snk in next 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)

ok, back into C# and over in your Solutions Explorer 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, you could use something relative or in the path

ok now build your dll and then 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 then it's finally time to 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)



Slighthaze = NULL
 
The real key to all of this is the creation of the .snk file and setting the AssemblyKeyFile to sign the assembly.

Slighthaze = NULL
 
Thanks everyone. I got it to work just before leaving work yesterday. I didn't do the RegSvcs, but I did RegAsm. Then in FoxPro I was getting the error that it couldn't find the dll (error 0x801-somthing) even though I had the dll in the GAC. After rebooting it worked fine.

Although, it might have been because I made some changes to the project in the IDE and revbuilding the project before the reboot. Maybe the IDE did the RegSvcs--I thought it was just doing RegAsm again.
 
davewelsh,

It seems you've found another way to do it other than what I outlined above. Could you post the process so I could reproduce it? Thanks.

Slighthaze = NULL
 
Craig,
You are right - sometimes I forget the "obvious". It's certainly the first place I check when something new comes up in the "web" world. Thanks for the reminder.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top