sizeof(structure)
[1/7] from: ptretter::charter::net at: 18-Sep-2003 19:59
Anyone know how to determine the "sizeof" a structure!. I'm trying to pass OSVERSIONINFO
structure to GetVersionEx and for some reason I think I'm not getting the sizeof portion
right to set dwOSVersionInfoSize.
Paul Tretter
[2/7] from: brett:codeconscious at: 19-Sep-2003 11:12
I haven't used it but from the library interface doco....
;- returns the number of elements in the structure.
length? second a-struct
;- returns the size, in bytes, of the structure.
length? third a-struct
Regards,
Brett.
----- Original Message -----
From: "Paul Tretter" <[ptretter--charter--net]>
To: <[rebol-list--rebol--com]>
Sent: Friday, September 19, 2003 10:59 AM
Subject: [REBOL] sizeof(structure)
> Anyone know how to determine the "sizeof" a structure!. I'm trying to
pass OSVERSIONINFO structure to GetVersionEx and for some reason I think I'm
not getting the sizeof portion right to set dwOSVersionInfoSize.
[3/7] from: ptretter:charter at: 18-Sep-2003 20:42
Yeah I actually tried that thinking the same but had no luck with it. I get
a return value of 0 which denotes failure of the GetVersionEx function.
I'll tinker some more though.
Paul Tretter
[4/7] from: greggirwin:mindspring at: 18-Sep-2003 22:48
Hi Paul,
PT> Yeah I actually tried that thinking the same but had no luck with it. I get
PT> a return value of 0 which denotes failure of the GetVersionEx function.
The fixed char array will give you grief, if you haven't already dealt
with them in structs. Here's a very quick hack for you, with credit to
Pekr and Cyphre for the nifty trick of generating elements dynamically
to emulate char arrays in structs.
-- Gregg
make-elements: func [name count type /local result][
if not word? type [type: type?/word type]
result: copy "^/"
repeat i count [
append result join name [i " [" type "]" newline]
]
to block! result
]
kernel.dll: load/library %kernel32.dll
OSVERSIONINFOEXA: make struct! OSVERSIONINFOEXA-def: compose/deep [
dwOSVersionInfoSize [integer!] ; DWORD
dwMajorVersion [integer!] ; DWORD
dwMinorVersion [integer!] ; DWORD
dwBuildNumber [integer!] ; DWORD
dwPlatformId [integer!] ; DWORD
(make-elements 'szCSDVersion 128 #"@") ; TCHAR
] none
OSVERSIONINFOEXA/dwOSVersionInfoSize: length? third OSVERSIONINFOEXA
GetVersionEx: make routine! compose/deep/only [
lpVersionInformation [struct! (OSVERSIONINFOEXA-def)] ;LPOSVERSIONINFO
return: [integer!] ;BOOL
] kernel.dll "GetVersionExA"
get-version: has [res] [
res: GetVersionEx OSVERSIONINFOEXA
either 0 = res [none][OSVERSIONINFOEXA]
]
res: get-version
print [
"Major:" res/dwMajorVersion newline
"Minor:" res/dwMinorVersion newline
"Build:" res/dwBuildNumber newline
"Version:" to-string copy/part at third OSVERSIONINFOEXA 21 128
]
free kernel.dll
[5/7] from: rebol:techscribe at: 18-Sep-2003 22:55
Hi Gregg.
Nice. Doesn't this belong in the Cookbook? I know, it's "simple examples
for new users." But "new REBOL users" could be veteran C programmers ...
And from the p.o.v. of a Windows programmer, this example is simple enough.
Take Care,
Elan
Gregg Irwin wrote:
[6/7] from: ptretter:charter at: 19-Sep-2003 6:41
This is great to know Gregg and works well. I wouldn't have figured this
out. They should probably update the library doc on how to handle this
type.
Paul Tretter
[7/7] from: greggirwin:mindspring at: 19-Sep-2003 9:39
Hi Elan,
E> Nice. Doesn't this belong in the Cookbook? I know, it's "simple examples
E> for new users." But "new REBOL users" could be veteran C programmers ...
E> And from the p.o.v. of a Windows programmer, this example is simple enough.
Hmmm. I guess it isn't too long. I have a few other things I want to
write up for it, so I'll add this to the list.
-- Gregg