Microsoft KB Archive/216055

= How To Pass an Array by Reference to LCK and Return Changes =

Article ID: 216055

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q216055



SUMMARY
This article demonstrates how to pass an array of real numbers to a FoxPro Library Construction Kit (LCK) routine in Visual C, manipulate the array in the LCK routine, and return the changed array to Visual FoxPro.



MORE INFORMATION
Create a Visual FoxPro FLL in Visual C++ using the following C code:


 * 1) include 
 * 2) include 

void FAR ByRef_array(ParamBlk FAR *parm) {  int     start;         /* Starting value of Loop. */   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.*/ /* Test array contents and manipulate accordingly */ if (val.ev_type == 'N') {        if (val.ev_real < 10) val.ev_real = val.ev_real * 1; else if (val.ev_real < 20) val.ev_real = val.ev_real * 2; else if (val.ev_real < 30) val.ev_real = val.ev_real * 3; else val.ev_real = val.ev_real * 4; }     else MessageBox(NULL,"Wrong Data type","Should be a number.",MB_OK); /* Copy the contents of Locator Structure into Value Structure.*/ _Store(&loc, &val); }       }

FoxInfo myFoxInfo[]={ {"ByRef_ARRAY",(FPFI)ByRef_array,1,"R"}, };

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

To test that the array has changed, create a program and enter the following FoxPro code:

CLEAR cfixed=SET('FIXED') SET FIXED ON

cdecimal=SET('DECIMALS') SET DECIMAL TO 4

SET LIBRARY TO "D:\visual c 6\MyProjects\by_ref\Debug\by_ref.dll"
 * Point to the DLL built in Visual C

PUBLIC by_reftest(10)
 * Populate array with random values then print to see original values

?"Array before LCK routine..." FOR i = 1 TO ALEN(by_reftest) by_reftest(i)= 60 * RAND ?by_reftest(i) ENDFOR

=ByRef_array(@by_reftest)
 * Call the LCK function and pass the array by reference

?"Array after LCK routine..." FOR i = 1 TO ALEN(by_reftest) ?by_reftest(i) ENDFOR

SET FIXED &cfixed SET DECIMALS TO &cdecimals SET LIBRARY TO

