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

How to create a DLL in VFP by mgagnon
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=oFunc.returnvalue(1,2)
    ? 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".

IF PROGRAM() != "MYCLASS"
   ?"this file MUST BE NAMED 'myclass.prg'"
   return
ENDIF
IF FILE("myclass.dll")
   DECLARE integer DllUnregisterServer IN myclass.dll
   DllUnregisterServer()
   CLEAR DLLS
ENDIF
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

DEFINE CLASS myclass AS session OLEPUBLIC
   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
ENDDEFINE


Mike Gagnon

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