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>bin2a()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Bin2A()
Convert binary data to a Clipper array
------------------------------------------------------------------------------

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

Arguments

<cData> is the binary data (stored as a Clipper string, e.g.
corresponding to a C data structure) to convert; its contents
must be fully described by <cInfo>.  If <cData> contains any
sub-structures, they must also be fully described by <cInfo>.

<cInfo> is a string specifying the type each part of <cData>
is to be converted to in the result array.  The <cInfo> string
should be a comma-separated list of C-like data types (see
below).  Any sub-structures you want converting to 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]"), except that any strings must have
their length specified, and may not have a repeat count as
well.  Each type must be one of (case is ignored):

     type                     converted size    Clipper data type

     byte                     (8 bits)          numeric (0 - 255)
     integer, short           (16 bits)         numeric (-32768 - 32767)
     uint, ushort, or word    (16 bits)         numeric (0 - 65535)
     handle, or hwnd          (16 bits)         numeric (same as integer)
     long, or dword           (32 bits)         numeric
     string[ <n> ]            ( <n> * 8 bits)   character (length n)
     bool                     (16 bits)         numeric (0 or 1)
     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, an array is returned.  If an error is detected,
NIL is returned.  If you're having problems, check for NIL,
and worry whether the length of <cData> corresponds to <cInfo>.

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