Share via


How to: Return Values from ActiveX Controls and FLL Libraries

You can return values from ActiveX controls or Visual FoxPro dynamic-link libraries (FLL) to Visual FoxPro.

To return values from ActiveX controls to Visual FoxPro

  • Use the RETURN statement in the control and pass a single value.

The following example returns uses a RETURN statement to return the version number stored in VERSION:

#define VERSION 101

// other code here

long CPyCtrl::GetVersion()
{
   // set the version number here in variable fVersion
   return VERSION;
}

Returning Values from FLL Libraries

When you want to return values from FLL libraries, use API functions, not native C or C++ commands.

Note

When return values from an ActiveX control (.ocx) file, do not use the API functions for returning values from FLL libraries. Instead, use the RETURN statement.

To return values from an FLL library

  • Use the API functions listed in the following table.

The following API functions should be used only for FLL libraries.

Function

Description

_RetChar(char *string)

Sets the function return value to a null-terminated string.

_RetCurrency(CCY cval, int width)

Sets the function return value to a currency value.

_RetDateStr(char *string)

Sets the function return value to a date. The date is specified in mm/dd/yy[yy] format.

_RetDateTimeStr(char *string)

Sets the function return value to a date and time specified in mm/dd/yy[yy] hh:mm:ss format.

_RetFloat(double flt, int width, int dec)

Sets the function return value to a float value.

_RetInt(long ival, int width)

Sets the function return value to a numeric value.

_RetLogical(int flag)

Sets the function return value to a logical value. Zero is considered FALSE. Any non-zero value is considered TRUE.

_RetVal(Value *val)

Passes a complete Visual FoxPro Value structure; any Visual FoxPro data type except for memo can be returned. You must call _RetVal( ) to return a string that contains embedded null characters or to return a .NULL. value.

Note

To return the value of an object data type, use the _RetVal() function, filling in the ev_object field in the Value structure.

The following example, Sum, accepts a reference to a numeric field in a table and uses _RetFloat to return the sum of the values in the field:

#include <Pro_ext.h>

Sum(ParamBlk *parm)
{
// declare variables
double tot = 0, rec_cnt;
int i = 0, workarea = -1; // -1 is current workarea
Value val;

// GO TOP
_DBRewind(workarea);

// Get RECCOUNT( )
rec_cnt = _DBRecCount(workarea);

// Loop through table
for(i = 0; i < rec_cnt; i++)
{ 
   //Place value of the field into the Value structure
   _Load(&parm->p[0].loc, &val);

   // add the value to the cumulative total
   tot += val.ev_real;

   // SKIP 1 in the workarea
   _DBSkip(workarea, 1);
} 

// Return the sum value to Visual FoxPro
_RetFloat(tot, 10, 4); 
}
// The Sum function receives one Reference parameter
FoxInfo myFoxInfo[] = {
   {"SUM", Sum, 1,"R"} 
};
FoxTable _FoxTable = {
   (FoxTable *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

Assuming there's a numeric field named amount in the currently open table, the following line of code in a Visual FoxPro program calls the function:

? SUM(@amount)

See Also

Concepts

Parameters in External Libraries

Access to Visual FoxPro Variables and Fields

Reference

Passing Parameters to Visual FoxPro API Functions

Other Resources

Accessing the Visual FoxPro API

Extending Visual FoxPro with External Libraries

API Library Construction