Well, one thing I noticed is that Standard name is an array
WCHARs, not chars. WCHAR is defined in winnt.h:
        typedef unsigned short wchar_t;
        typedef wchar_t WCHAR;
So it is a fixed size (32 elements) array of shorts (16bits each).
You can't just specify a rebol string! in the structure.
(That's essentially just a pointer -> 4bytes)
So your structure is not big enough.
Afterwards you also have to convert the wchar array back to a string.
This will show you how I've done it.
I've got the routine doing filling the structure correctly, but
I am not giving you all the code necessary to print it all out :) yet...

(See bottom for code)

Anton.

> I am trying to find out if red-icon-problem of IOS is caused by Rebol
> incorrectly interpreting timezone info or it is OS who does it in
> strange way, but I would need following routine to function :-) Sadly
> enough, I get crashes ....

> It survives the function call, but I can't touch structure, or I get
> crash ...
>
> Thanks,
> -pekr-

lib: load/library %kernel32.dll

if error? set/any 'err try [

        personalize: func ["personalises the element names in a struct spec"
                blk [block!] "A struct spec."
                name [word! string!] "Root name for each element. This will be 
prefixed to
each element."
                /local result
        ][
                result: copy blk
                if blk/1 = [save] [result: next result]
                forskip result 2 [result/1: to-word rejoin [name "_" result/1]]
                head result
        ]

        C-array-to-struct-spec: func ["Creates a struct spec to hold n values of
type."
                type [word!] "datatype"
                name [word!] "root name for each element, eg. 'name -> name, 
name1, name2
.. namen"
                len [integer!] "length of the array"
                /save "Insert [save] to prevent the struct from being garbage 
collected."
                /local blk
        ][
                blk: copy []
                if save [insert/only blk [save]]
                repeat n len [append blk compose/deep [(to-word either n = 1 
[name][join
name n - 1]) [(type)]]]
                blk
                ;;blk: make struct! blk none
        ]

        _SYSTEMTIME: [ ; struct! specification
                Year            [short]
                Month           [short]
                DayOfWeek       [short]
                Day             [short]
                Hour            [short]
                Minute          [short]
                Second          [short]
                Milliseconds [short]
        ]

        _TIME_ZONE_INFORMATION: compose [
                Bias [long] ; difference, in minutes, between UTC and local time
                (C-array-to-struct-spec 'short 'StandardName 32) ;WCHAR[32];
                (personalize _SYSTEMTIME 'StandardDate) ;SYSTEMTIME; transition 
from
Daylight Savings to Standard time
                StandardBias [long] ; usually always zero
                (C-array-to-struct-spec 'short 'DaylightName 32) ;WCHAR[32];
                (personalize _SYSTEMTIME 'DaylightDate) ;SYSTEMTIME; transition 
from
Standard time to Daylight Savings
                DaylightBias [long] ; added to Bias to form the bias (in 
minutes) used
during daylight savings. Usually -60.
        ]
        ;new-line/all/skip _TIME_ZONE_INFORMATION true 2

        tz-info: make struct! _TIME_ZONE_INFORMATION none

        ;tz-info/DaylightBias: 1023
        ;dump-memory get-struct-address tz-info ((size-of-struct? first 
tz-info) /
4)

        GetTimeZoneInformation: make routine! compose/deep [
                LPTIME_ZONE_INFORMATION [struct! [(_TIME_ZONE_INFORMATION)]]
                return: [long] ; DWORD (unsigned long)
        ] lib "GetTimeZoneInformation"

        result: GetTimeZoneInformation tz-info

        print [
                "GetTimeZoneInformation returned:" mold result select [
                        0 TIME_ZONE_ID_UNKNOWN
                        1 TIME_ZONE_ID_STANDARD
                        2 TIME_ZONE_ID_DAYLIGHT
                ] result
                "^/Bias:" tz-info/Bias
        ]
        use [word][
                foreach type [Standard Daylight][
                        word: to-word join type "Name"
                        print rejoin [
                                word ": " wchar-array-to-string 
(get-struct-address tz-info)
                                        + (get-struct-element-offset tz-info 
word) 32
                        ]
                        foreach granularity [Year Month Day DayOfWeek Hour 
Minute Second][
                                word: to-word rejoin [type "Date_" granularity]
                                print rejoin [
                                        word ": " do to-path reduce ['tz-info 
word]
                                ]
                        ]
                        print rejoin [word: to-word join type "Bias" ": " do 
to-path reduce
['tz-info word]]
                ]
                print "----------------"
        ]

][
        free lib
        err
        ;print mold disarm err
]

free lib


-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to