Fpole.dll

Examples

With Fpole.dll, you can run Visual FoxPro commands and evaluate Visual FoxPro expressions from applications that allow API calls but do not support Automation.

Fpole.dll contains six the following functions.

To See
Run a Visual FoxPro command. FoxDoCmd( )
Evaluate a Visual FoxPro expression FoxEval( )
Specify whether error messages are displayed in message boxes. SetErrMode( )
Specify the OLE class that FoxDoCmd( ) and FoxEval( ) create. SetOleObject( )
Close the OLE object created when you use FoxDoCmd( ) or FoxEval( ). CloseIt( )
Retrieve the last error that occurred. GetLastErr( )

FoxDoCmd( ) Function

Runs a Visual FoxPro command from an application that allows API calls.

Syntax

nSuccess = FoxDoCmd(cFoxCommand, cOptions)

Returns

Integer

Arguments

cFoxCommand

Specifies the Visual FoxPro command to run.

cOptions

One or more of the following.

Setting Description
  (Blank) Runs the specified command without activating the main Visual FoxPro window.
a Activates the main Visual FoxPro window and runs the specified command.
i If Visual FoxPro is not running, activates Visual FoxPro without making the Visual FoxPro window visible.
t If another program is already running in Visual FoxPro, displays an error message rather than executing cFoxCommand.

Remarks

Returns 0 if the Visual FoxPro command is successfully executed; -1 otherwise.

If Visual FoxPro is already running, FoxDoCmd( ) sends the command to Visual FoxPro. If Visual FoxPro is not already running, FoxDoCmd( ) runs Visual FoxPro and sends the command.

Example

*In Visual FoxPro
DECLARE integer FoxDoCmd in "FPOLE.DLL" string,string
=FoxDoCmd("SELECT * FROM customer","at")

FoxEval( ) Function

Evaluates a Visual FoxPro expression from an application that allows .dll calls.

Syntax

nExprLen = FoxEval(cExpression, cBuffer, nLen)

Returns

Integer

Arguments

cExpression

The Visual FoxPro expression to evaluate.

cBuffer

Where to store the value of the Visual FoxPro expression.

nLen

The length of cBuffer.

Remarks

Returns the length of the string stored in cBuffer if successful; -1 otherwise.

You need to pass the cBuffer argument by reference rather than by value for Visual FoxPro to be able to store a value in the buffer. In Visual FoxPro, for example, declare the function with @ after the second string. Arguments are passed by reference by default in Word Basic.

Because there is no way to create and read a buffer in a Help file macro, this function is not useful as a registered routine in Help.

Example

*In Visual FoxPro
DECLARE integer FoxEval in (MYDLL) ;
   string, string @, integer 
cBuff = SPACE(100)
=FoxEval("TTOC(DATETIME())", @cBuff, 100)
?cBuff

SetErrMode( ) Function

Specifies whether or not error messages from Fpole.dll are displayed in message boxes.

Syntax

nSuccess = SetErrMode(nErrMode)

Returns

Integer

Arguments

nErrMode

One of the following.

Setting Description
0 Error messages are not displayed in message boxes.
1 (Default) Error messages are displayed in message boxes.

Remarks

Returns 0 if the mode was successfully set; -1 otherwise.

SetOLEObject( ) Function

Specifies the OLE class that calls to FoxDoCmd( ) and FoxEval( ) create.

Syntax

nSuccess = SetOleObject(cOLEClass)

Returns

Integer

Remarks

Returns 0 if the class was specified successfully; -1 otherwise.

Specify your application in SetOLEObject( ) to allow Automation from applications that don’t natively support Automation.

Example

DECLARE integer SetOLEObject in (MYDLL) string 
=SetOleObject("visualfoxpro.application")

CloseIt( ) Function

Closes the OLE object created when you use FoxDoCmd( ) or FoxEval( ).

Syntax

nSuccess = CloseIt( )

Returns

Integer

Remarks

Returns 0 if the object was removed successfully; -1 otherwise.

GetLastErr( ) Function

Retrieves the last error that occurred.

Syntax

nErrLen = GetLastErr(cBuffer, nLen)

Returns

Integer

Arguments

cBuffer

Where to store the error message.

nLen

The length of cBuffer.

Remarks

Returns the length of the string stored in cBuffer if successful; -1 otherwise.

You need to pass the cBuffer argument by reference rather than by value for Visual FoxPro to be able to store a value in the buffer. In Visual FoxPro, for example, declare the function with @ after the second string. Arguments are passed by reference by default in Word Basic.

Because there is no way to create and read a buffer in a Help file macro, this function is not useful as a registered routine in Help.

Fpole.dll Examples

The following examples demonstrate using functions in Fpole.dll from Visual FoxPro, a Help file, and Word Basic.

Visual FoxPro Example

MYDLL = "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll

DECLARE integer SetOleObject in (MYDLL) string 
DECLARE integer FoxDoCmd in (MYDLL) string,string 
DECLARE integer FoxEval in (MYDLL) ;
   string, string @,integer 

=SetOleObject("visualfoxpro.application") 
?FoxDoCmd("wait wind 'test' timeout 2","") 
?FoxDoCmd("modi proj xx2 nowait ","") 
?FoxDoCmd("close all","") 

CLEAR DLLS 

Help File Example

  1. In the [CONFIG] section of a help project, register the DLL:
    RegisterRoutine("fpole.dll","FoxDoCmd","SS")
    
  2. In your .RTF file, call the function the same way you would call a native Help macro:
    HotSpotText!FoxDoCmd("DO (HOME() + 'myprg')","at")
    
  3. Compile and run the help file.

Simple Word Basic Example

Declare Sub FoxDoCmd Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll" (cCommand As String, cOptions As String) 

Sub MAIN 
FoxDoCmd "USE (HOME(2) + 'Data\Customer')", "i" 
FoxDoCmd "_CLIPTEXT = customer.company", "i" 
EditPaste 
End Sub 

Another Word Basic Example

This example presents a dialog box so that a user can choose a customer ID from a list. The associated company name and contact are then inserted into the Word document.

'Declare the Fpole.dll functions.
'--------------------------------
Declare Sub SetOleObject Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cApp As String)

Declare Sub FoxDoCmd Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cCommand As String, BringToFront As String)

Declare Sub FoxEval Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll(cExpression As String, cBuff As String, nLen As Integer)

Declare Sub CloseIt Lib "C:\Program Files\Microsoft Visual Studio\Vfp98\Fpole.dll

Sub MAIN

Dim cBuffer$
cBuffer$ = String$(50, " ")
Dim aCustID$(5)
aCustID$(0) = "BLONP"
aCustID$(1) = "CHOPS"
aCustID$(2) = "ISLAT"
aCustID$(3) = "LETSS"
aCustID$(4) = "SEVES"
cboCustID = 0'1st element in the array

Begin Dialog UserDialog 404, 150, "Calling Visual FoxPro with Fpole.dll"
   DropListBox 44, 33, 160, 108, aCustID$(), .cboCustID
   Text 15, 14, 268, 13, "Choose a Customer ID from the list.", .Text2
   Text 15, 61, 231, 13, "Then Choose OK to insert the ", .Text4
   Text 15, 78, 215, 13, "Company Name and Contact", .Text5
   Text 15, 95, 141, 13, "into your document.", .Text6
   OKButton 298, 76, 88, 21
   CancelButton 299, 111, 88, 21
End Dialog

Dim dlg As UserDialog
nButtonChoice = Dialog(dlg)

' If the user presses "Cancel"...
'--------------------------------
If nButtonChoice = 0 Then
   Goto EndOfSub
End If

' Automate Visual FoxPro
'-----------------------
Print "Opening Visual FoxPro"
SetOleObject "visualfoxpro.application"
FoxDoCmd "USE (HOME(2) + 'Data\Customer')", "i"
FoxDoCmd "LOCATE FOR cust_id = " + Chr$(39) + aCustID$(dlg.cboCustID) + Chr$(39), "i"

Insert "Customer ID" + Chr$(9)
FoxEval "cust_id", cBuffer$, 50
Insert RTrim$(cBuffer$)
InsertPara

Insert "Company:" + Chr$(9)
FoxEval "company", cBuffer$, 50
Insert RTrim$(cBuffer$)
InsertPara

FoxEval "contact", cBuffer$, 50
Insert "Contact: " + Chr$(9) + RTrim$(cBuffer$)
InsertPara

Print "Closing Visual FoxPro"
CloseIt
Print " "

EndOfSub:
End Sub