tags:

views:

175

answers:

3

Can anyone tell me the best way to call FoxPro 9 code from a .Net 3.51 application?

I have a legacy production application that is written in Fox 9. I want to expose as much of the logic and business processes as I can so that I can reuse it from .Net. Ideally I want to do this in a way which makes it invisible to the .Net application so that I can switch out the Fox code and replace it with .Net code later.

I was thinking that I could just build a COM DLL in Fox and then reference it from my .Net project but I'm not having any joy with that (various errors in Visual Studio when I compile). Am I missing a trick here or do I need to do something like build a Fox web service?

+2  A: 

Have a look at this article on VFP Conversion - Calling VFP COM components from .Net and ASP.Net - it should get you started.

Stuart Dunkeld
+2  A: 

I've had luck in the past by taking the foxpro class I wan to expose and making it inherit from the Session object -

DEFINE CLASS B AS SESSION OLEPUBLIC

Then build the foxpro DLL and register it with the RegSvr32 command. Then in Visual Studio the COM object should show up under the COM tab when you add references to your project.

kragan
+1  A: 

Many moons ago, I used to create FoxPro classes as a Com. As Kragan has suggested make them OLEPUBLIC and it will expose the methods. For permission purposes I used to add them to Com+ (in Vista/Windows 7 this is under C:\Windows\System32\comexp.msc)

Then in .Net using FoxProCom; (point to the com in Com+)

//Connect to Com (using FoxPro Com (Project Name - see Project Information) and Class Name Type ObjectType = Type.GetTypeFromProgID("FoxProComProj.FoxProComClass",Environment.MachineName.ToString(),true);

//Activate Com Object oDComObject = Activator.CreateInstance(ObjectType);

//Instantiate Com FoxProCom.FoxProComClass oFoxCom = (FoxProCom.FoxProComClass) oDComObject;

oFoxCom.UseaOLEClass()

//Clear Com oFoxCom = null;

SwissJonese