Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Type Array needed for communiction with dll
Message
 
À
17/02/2003 09:02:57
Albert Beermann
Piepenbrock Service Gmbh & Cokg
Osnabrück, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00754055
Message ID:
00754094
Vues:
13
An array is a memory buffer.

The simplest case is an array of bytes. If you need to pass an array of 64 bytes to an external function, first you have to assemble this array as a string from characters:

cArray = Repli(Chr(0), 64) && in case if all bytes are zeroes

or if this array is stuffed with some values
cArray = Chr(54) + Chr(2) + Chr(0) + ... + Chr(12) && 64 bytes in total

This parameter is to be declared as STRING @, for example:

DECLARE INTEGER SomeFunction IN lib.dll STRING @arr
= SomeFunction(@cArray)

* * *
For an array of DWORD (LONG, INT) values there is a difference. The DWORD occupies 4 consecutive bytes with lower bytes storing at the left.

For example, DWORD value 0x1234 (or 4660 in denary notation) is allocated in memory as [4] [3] [2] [1].

Use the following function to convert FoxPro numerics into 4-byte DWORDs:

FUNCTION num2dword (lnValue)
#DEFINE m0 256
#DEFINE m1 65536
#DEFINE m2 16777216
LOCAL b0, b1, b2, b3
b3 = Int(lnValue/m2)
b2 = Int((lnValue - b3 * m2)/m1)
b1 = Int((lnValue - b3*m2 - b2*m1)/m0)
b0 = Mod(lnValue, m0)
RETURN Chr(b0)+Chr(b1)+Chr(b2)+Chr(b3)

Now the array is assembled this way:
cArray = num2dword(54) + num2dword(2) + num2dword(0) + ... num2dword(12)

If you need to pass an array of all zeroes:
cArray = Repli(Chr(0), 64*4) && 64 times by 4 bytes

And the function is called same way:
DECLARE INTEGER SomeFunction IN lib.dll STRING @arr
= SomeFunction(@cArray)

* * *
For floating types I recommend an article of Peter Easson at FoxPro Wikis site:
http://fox.wikis.com/wc.dll?Wiki~VFPFloatingPointDataType~VFP
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform