Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide to Clip-4-Win version 3.0 - <b>a2bin()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
A2Bin()
Convert a Clipper array to binary
------------------------------------------------------------------------------

Syntax
A2Bin( <aData>, <cInfo> )   -->   cData

Arguments

<aData> is the array to convert; its elements must be fully
described by <cInfo>.  If <aData> contains any sub-arrays,
they must also be fully described by <cInfo>.

<cInfo> is a string specifying the type each array element is
to be converted to in the result.  The <cInfo> string should
be a comma-separated list of C-like data types (see below).
Any sub-arrays should be enclosed in braces ("{" and "}").
Repeated types may be reduced to the type followed by the
count in square brackets (e.g. "int[5]").  Each type must be
one of (case is ignored):

     type                     converted size

     byte                     (8 bits)
     integer, or short        (16 bits)
     uint, ushort, or word    (16 bits)
     handle, or hwnd          (16 bits)
     long, or dword           (32 bits)
     string                   (8 bits per character)
     bool                     (16 bits)
     float, or real           (32 bits floating point)
     double                   (64 bits floating point)

You only need enough characters to make the type unique.

Returns
If successful, a character string is returned.  If an error is
detected, NIL is returned.

Description
This function is intended to help convert a Clipper array to
an equivalent C data structure, which may then be passed to
the CallDLL() function, or used with DDE (dynamic data
exchange).

If speed is important, or you have a particularly complex C
structure, you should consider using the Clipper Extend
System.

Example

// Windows GetTextMetrics(), via DLL
//
//  GetTextMetrics( <hDC>, <@aTextMetric> )  -->  lSuccess

function GetTextMetrics( hDC, aTM )
local     hLib, cGetTM, cTM, lSuccess
// NOTE: This example can be simplified because it uses a function in one
//       of the DLL's searched automatically by GetProcAddress()
if ( hLib := LoadLibrary("GDI.EXE") )  <  32                            ;
    .or. ( cGetTM := GetProcAddress( hLib, "GetTextMetrics", "Pascal",  ;
                                     "bool", "int,str" ) ) == nil
     return .f.
endif
// make an empty TEXTMETRIC structure
cTM = a2bin( { 0, 0, 0, 0, 0, 0, 0, 0,                  ;
               0, 0, 0, 0, 0, 0, 0, 0, 0,               ;
               0, 0, 0 },                               ;
             "int[8], BYTE[9], int[3]" )
// same as replicate(chr(0), 31), in this case, as each int is 2 bytes

// Remember to pass cTM by reference (@cTM), so it can be changed
if  ( lSuccess := CallDLL( cGetTM, hDC, @cTM ) )
     aTM = bin2a( cTM, "int[8], BYTE[9], int[3]" )
endif
FreeLibrary( hLib )
return lSuccess


See Also: Bin2A() CallDLL() FreeLibrary() LoadLibrary()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson