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!
  • Students Click Here

*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.

Students Click Here

Microsoft: FoxPro FAQ

Classes and Objects

How to create a DLL in VFP by Mike Gagnon
Posted: 26 Mar 03 (Edited 4 Nov 03)

Please note that Foxpro DLLs DO NOT support interfaces of any kind (Including wait windows). If you require interface support, create a COM Server instead.

1. Step-by-step example of creating a DLL COM server.

  1. Create a project (Not with the wizard)

  2. Add a library in the project. (Call it myclass)

  3. So you create a custom class (call it functions)

  4. Add a method to the custom class (call it returnvalue)
    In it put something like:
    LPARAMETERS val1,val2
    val3 =val1+val2
    RETURN val3

  5. Save that. Load the class library in the class browser, select the class (functions) right-mouse on it and select OLEPublic.

  6. Make sure your library is set to main.

  7. Compile the project, by selecting Multi Threaded COM server DLL.

  8. You will note that VFP self-registers the DLL on the development box, but it needs to be registered on any other machine.

  9. To call your DLL from VFP for example use somethign like:
    oFunc = CREATEOBJECT("proj1.functions")  &&Proj1 was the name of my project (and the DLL)
    ? myValue

  10. The value of myValue should give you 3.

2. How to create a DLL COM server from a program

Note: Create a program, copy the code below and call it "myclass.prg".

   ?"this file MUST BE NAMED 'myclass.prg'"
IF FILE("myclass.dll")
   DECLARE integer DllUnregisterServer IN myclass.dll
BUILD PROJECT myserver FROM myclass
BUILD DLL myserver from myserver recomp
*now test this COM server:
ox = CreateObject("myserver.myclass")    && create the server object
ox.mydocmd("USE home(1)+'samples\data\customer'")    && use a table
?ox.myeval("RECCOUNT()")    && get the record count

   PROCEDURE MyDoCmd(cCmd as String) as Variant ;
         helpstring "Execute a VFP cmd"
      &cCmd    && just execute parm as if it were a fox command
   FUNCTION MyEval(cExpr as String) ;
         helpstring "Evaluate a VFP expression"
      RETURN &cExpr    && evaluate parm as if it were a fox expr
   FUNCTION Error(nError, cMethod, nLine)
      COMreturnerror(cMethod+'  err#='+str(nError,5)+;
         '  line='+str(nline,6)+' '+message(),_VFP.ServerName)
      && this line is never executed

Mike Gagnon

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

My Archive

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