jaalex
asked on
API Question
I am using the following entry out of the win32api
Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
I have the following type set up
Type TIME_ZONE_INFORMATION
zone As Long
End Type
Then in my sub I am doing this
Dim TimeZone As TIME_ZONE_INFORMATION
GetTimeZoneInformation TimeZone it is this line that is causing the problem
Every time I try to run this it kills VB. What am I doing wrong. I have called into the API this way before.
Declare Function GetTimeZoneInformation Lib "kernel32" Alias "GetTimeZoneInformation" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
I have the following type set up
Type TIME_ZONE_INFORMATION
zone As Long
End Type
Then in my sub I am doing this
Dim TimeZone As TIME_ZONE_INFORMATION
GetTimeZoneInformation TimeZone it is this line that is causing the problem
Every time I try to run this it kills VB. What am I doing wrong. I have called into the API this way before.
The normal declaration TIME_ZONE_INFORMATION should be:
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
jaalex,
Have you ever call this API in this way in VB? Or in C/C++? What GetTimeZoneInformation's parameter required is a pointer to TIME_ZONE_INFORMATION structure. If you just pass a long type variable into the API with byref, it will cause unpredicted result(who knew what would the memory address from that long variable!). That why you'll get GPF when you run it in VB.
Have you ever call this API in this way in VB? Or in C/C++? What GetTimeZoneInformation's parameter required is a pointer to TIME_ZONE_INFORMATION structure. If you just pass a long type variable into the API with byref, it will cause unpredicted result(who knew what would the memory address from that long variable!). That why you'll get GPF when you run it in VB.
Your declarations should look like this
Option Explicit
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Put the following code on a form, run the prog, and click the form, and get a message box showing weekday
Option Explicit
Private Sub Form_Click()
Dim TimeZone As TIME_ZONE_INFORMATION
GetTimeZoneInformation TimeZone
MsgBox CStr(TimeZone.StandardDate .wDayOfWee k)
End Sub
Option Explicit
Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type
Declare Function GetTimeZoneInformation Lib "kernel32" (lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Put the following code on a form, run the prog, and click the form, and get a message box showing weekday
Option Explicit
Private Sub Form_Click()
Dim TimeZone As TIME_ZONE_INFORMATION
GetTimeZoneInformation TimeZone
MsgBox CStr(TimeZone.StandardDate
End Sub
raygibbins,
Anythings different between your "answer" and my comments???
Anythings different between your "answer" and my comments???
yowkee,
Not really, but it works, so why is it not accepted yet?
Not really, but it works, so why is it not accepted yet?
raygibbins,
Please look carefully! I am not the one to ask the question. And you should not post an answer which same as my comment.
It just like taking other comment and post as answer.
Please look carefully! I am not the one to ask the question. And you should not post an answer which same as my comment.
It just like taking other comment and post as answer.
ASKER
Sorry I posted the question and I have been out of town. I belive that you raygibbins has copied the same thing that yowkee said. That is why I am rejecting you answer. Yowkee please answer and I will award you points
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for talking so long on grading this. I
Bought This Question.
ASKER