Access to Visual FoxPro Variables and Fields
You can access Visual FoxPro variables or field values in your ActiveX control or FLL function, either to read them or to set them. In addition, you can create new variables that can be accessed from within Visual FoxPro.
Variables and fields are made available in Visual FoxPro in a name table, which is an array containing the names of all currently defined variables and fields. You can access an individual element in the array using a name table index (NTI). A special API function, _NameTableIndex( ), returns the index of an existing variable or field based on a name that you provide. After you've determined the NTI for a given variable, you can read it using the _Load( ) API function or set it using the _Store( ) API function. To create a new variable, you can call the API function _NewVar( ).
To access Visual FoxPro variables or fields, you use the Value and Locator structures defined in Pro_ext.h. If you're creating an FLL library, you can use the same technique you used to access parameters passed to your functions. For details about the Value and Locator structures, see Parameters in External Libraries.
The following example illustrates how you can use the Value and Locator structures in an ActiveX control to access Visual FoxPro variables.
long CFoxtlibCtrl::TLGetTypeAttr(long pTypeInfo, LPCTSTR szArrName)
{
int nResult = 1;
TYPEATTR *lpTypeAttr;
Locator loc;
Value val;
OLECHAR szGuid[128];
char *szBuff;
__try {
if (_FindVar(_NameTableIndex(( char *)szArrName),-1,&loc)) {
((ITypeInfo *)pTypeInfo)->GetTypeAttr(&lpTypeAttr);
if (_ALen(loc.l_NTI, AL_ELEMENTS) < 16) {
_Error(631); //Array argument not of proper size.
}
//1 = Guid
StringFromGUID2(lpTypeAttr->guid, (LPOLESTR )&szGuid,sizeof(szGuid));
OLEOleToAnsiString(szGuid,&szBuff);
val.ev_type = 'C';
val.ev_length = strlen(szBuff);
val.ev_handle = _AllocHand(val.ev_length);
_HLock(val.ev_handle);
_MemMove((char *) _HandToPtr( val.ev_handle ), szBuff, val.ev_length);
OLEFreeString((void **)&szBuff);
_HUnLock(val.ev_handle);
loc.l_sub1 = 1;
_Store(&loc,&val);
_FreeHand(val.ev_handle);
//2 = LCID
loc.l_sub1 = 2;
val.ev_type = 'I';
val.ev_long = lpTypeAttr->lcid;
_Store(&loc,&val);
// code for values 3 - 16 here
((ITypeInfo *)pTypeInfo) -> ReleaseTypeAttr(lpTypeAttr);
}
} __except (EXCEPTION_EXECUTE_HANDLER) {
nResult = 0;
}
return nResult;
See Also
Tasks
How to: Build and Debug Libraries and ActiveX Controls
Reference
Passing Parameters to Visual FoxPro API Functions
_NameTableIndex( ) API Library Routine