Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass array by reference to function in dll file
Message
From
17/06/2003 08:59:37
 
 
To
17/06/2003 05:50:04
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00800718
Message ID:
00800746
Views:
22
Hi Tao,

you mean a C Dll you wanna use with:
DECLARE INTEGER yourFunction IN yourDll INTEGER ...

you have to assemble the array in memory yourself ...
e.g. the C function is similar to this one:


int theFunction(int passedArray[], int lnLen)
{
int lnRetVal = 0;
int xj;
for(xj=0;xj {
lnRetVal = lnRetVal + theParameter[xj];
}
return lnRetVal;
}


you can do in FoxPro ..

&& you need clsheap.prg .. look in the download area if you don't have it ..

SET PROCEDURE TO clsheap.prg additive
&& Create a dummy array
DIMENSION laInts[20]
FOR xj = 1 TO ALEN(laInts)
laInts[xj] = xj
ENDFOR

&&then you have to create a string which would look like the C int Array in &&memory ..

lcArray = ''
FOR xj = 1 TO ALEN(laInts)
lcArray = lcArray + NumToDWORD(laInts[xj]) && NumToDWORD -> clsheap.prg
ENDFOR

&&now create a Heap object and put the string on the heap, whichs returns us &&a pointer to it ..

oHeap = CREATE('Heap')
lnPointerToArray = oHeap.AllocBlob(lcArray)

&&finally call your function ... e.g.

theFunction(lnPointerToArray,20)


that's it ..

Regards

Christian
Previous
Reply
Map
View

Click here to load this message in the networking platform