Microsoft KB Archive/119636

{| = How to Pass an Array to a Routine in an LCK Library =
 * width="100%"|

ID: Q119636

The information in this article applies to:


 * Microsoft FoxPro Library Construction Kit for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
 * Microsoft FoxPro Library Construction Kit for Windows, versions 2.5, 2.5a, 2.5b, 2.6

SUMMARY
When you are writing libraries using the FoxPro Library Construction Kit (LCK), you can pass variables or array elements to a function in the library. You can also pass an array by reference into an library function. Once the reference is passed, each element can be accessed from within the library routine. The code to do this is shown below.

MORE INFORMATION
/* C code that creates the DLL. */

#include   #include 

/* The Putback function is optional. It sends the element of the array back to the FoxPro screen so you can see that the routine has found the array element. */

void Putback(long arr_element) {       Value val;

val.ev_type = 'I'; val.ev_width =10; val.ev_long = arr_element; _PutStr("\nThe current value is -"); _PutValue(&val); }

void FAR load_array(ParamBlk FAR *parm) {       int     start;         /* Starting value of Loop. */       long    array[50];     /* Create array to hold FoxPro array. */       Value   val;           /* Create Value structure. */       Locator loc;           /* Create Locator structure. */

start=0; loc = parm->p[0].loc; /* Store the contents of the FoxPro array in the Locator structure. */

/* Get the number of elements from the FoxPro array. */

loc.l_subs = (int)_ALen(parm->p[0].loc.l_NTI, AL_ELEMENTS);

/* FOR loop to get the array elements. */

for(start=0;start != loc.l_subs ; start ++){ loc.l_sub1=(start+1);

/* Store the contents of the FoxPro array in a Value Structure. */          _Load(&loc,&val);

/* Copy the contents of the FoxPro array to the function array.*/ array[start]=val.ev_long;

Putback(array[start]); /* Calls the structure Putback. */  }   }

FoxInfo myFoxInfo[]={ {"LOAD_ARRAY",(FPFI)load_array,1,"R"}, };

FoxTable _FoxTable={ (FoxTable FAR*)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo };

/* End of C code. */ This code is used in FoxPro: SET LIBRARY TO lckarray.dll DIMENSION foxarray(5) foxarray(1)=10 foxarray(2)=20 foxarray(3)=30 foxarray(4)=40 foxarray(5)=50 ? load_array(@foxarray) There will be a .T. at the end of the elements listed. This should not cause a problem since passing the elements back to FoxPro is not necessary. Additional reference words: FoxWin FoxDos LCK 2.00 2.50 2.50a 2.50b 2.60 KBCategory: kbprg kbcode KBSubcategory: FxtoolLck
 * }