Erik,
>DECLARE INTEGER GetSystemTime IN win32api STRING @
>cBuff=SPACE(40)
>=GetSystemTime(@cBuff)
>
>
>Well. I'm a bit confused here how they got that
cBuff has to be of size 40, when each word is only a size 2 and there is only 8 words, which I see as size 8*2 = 16. It says that you must create a 40-byte string buffer. Why?
16 bytes is plenty, it's just sloppy code on the sample. As long as the buffer is allocated the correct size or larger it'll work.
>But back to my function in the DLL and its structure, which looks like this
>
>typedef struct _INITDATA
>{
> DWORD dwSize;
> DWORD dwVersionMajor;
> DWORD dwVersionMinor;
> DWORD dwVersionBuild;
> DWORD dwOptions;
> DWORD dwReserved1;
> DWORD dwReserved2;
> char szDescription[MAXDESCRIPTIONLENGTH+1];
>
>} INITDATA, FAR* LPINITDATA;
>
>
>All I need is to make sure that
dwSize is the value of the size of the structure. Since it is a Double Word I would imagine the have size of 4 so I tried following (MAXDESCRIPTIONLENGTH is 128) strings
>
>chr(157)+chr(0)+chr(0)+chr(0)+replicate(chr(0), 153)
>chr(0)+chr(157)+chr(0)+chr(0)+replicate(chr(0), 153)
>chr(0)+chr(0)+chr(157)+chr(0)+replicate(chr(0), 153)
>chr(0)+chr(0)+chr(0)+chr(157)+replicate(chr(0), 153)
>
>Or chr(156) and 152 replicated chr(0)'s or chr(32)'s.
Use these functions to convert your data around for structs like these:
function ToWord( pnNumber )
local lnMSB, lnLSB
lnMSB = int( pnNumber / 256 )
lnLSB = pnNumber % 256
return chr( lnLSB ) + chr( lnMSB )
function ToLong( pnNumber )
local lnMSW, lnLSW
lnMSW = int( pnNumber / 65536 )
lnLSW = pnNumber % 65536
return ToWord( lnLSW ) + ToWord( lnMSW )
function FromWord( pcBuffer )
return asc( substr( pcBuffer, 2, 1 ) ) * 256 + asc( left( pcBuffer, 1 ) )
function FromLong( pcBuffer )
local lnNegative
if ( bitand( 0x80, asc( substr( pcBuffer, 3, 1 ) ) ) = 0x80 )
lnNegative = -1
pcBuffer = left( pcBuffer, 2 ) + chr( bitand( asc( substr( pcBuffer, 3, 1 ) ), 0x7f ) ) + right( pcBuffer, 1 )
else
lnNegative = 1
endif
return lnNegative * FromWord( substr( pcBuffer, 3, 2 ) ) * 65536 + FromWord( left( pcBuffer, 2 ) )
Then you'd simply:
szDescription = replicate( 0, MAXDESCRIPTIONLENGTH+1 )
lcBuffer = ToLong( dwSize ) + ;
ToLong( dwVersionMajor ) + ;
ToLong( dwVersionMinor ) + ;
ToLong( dwVersionBuild ) + ;
ToLong( dwOptions ) + ;
ToLong( dwReserved1 ) + ;
ToLong( dwReserved2 ) + ;
szDescription
And pass lcBuffer to your DLL.