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

How to create VFP DLL and call from Excel with VBA

Status
Not open for further replies.

mikeopolo

Technical User
May 25, 2003
54
NZ
Hi:

I have written some custom functions in Excel VBA to read a VFP database, which I have saved as an .XLA file. For various reasons, I now want to convert this code to a VFP DLL.

My question is not about converting the code; what I need are some guidelines, links, suggestions if possible, about creating a DLL from VFP, and then calling it indirectly from an Excel function and passing various parameters as required by each function.

Many thanks for any ideas or suggestions!
Regards
Mike
 

Mike,

The information you need is right there in the VFP Help file. Start with the topic, "How to: Build Automation Servers " and follow the links from there.

To give you a quick summary:

- Write your code entirely as a VFP class. Put all your functionality into the methods of that class.

- Flag the class as OLEPUBLIC (do that in the DEFINE CLASS command if you are writing the class programmatically, or in the Class Properties dialogue in the Class Designer).

- Place the class in a project on its own.

- Click the Build Button. Select the option for COM Server DLL, and go ahead and do the build.

- From Excel, do a CREATEOBJECT() to instantiate the class. Something like oMyVFPApp = CREATEOBJECT("MyLib.MyClass"), where MyLib is the name of the DLL and MyClass is the class within the DLL.

- Still in Excel, call your method with something like oMyVFPApp.MyMethod. Pass parameters in the usual way (but pass them by position, rather than using named parameters).

Finally, if you want to deploy your DLL on a different computer (other than the one you did the build on), you will have to register it on the target sytem.

The above is just a quick overview, but I hope it will put you on the right lines.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
That's really helpful Mike, this being the first attempt for me. I'll read, digest, and hopefully put into effect.

Many thanks
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top