Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: "Bad DLL calling convention" - Help!

104| Sun, 02 Dec 2007 22:02:00 GMT| cjqp| Comments (5)
I'm using the GetSystemTime API how the API viewer said to. I've also consulted my API book...any ideas?
cjqp

Keywords & Tags: bad, dll, calling, convention, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/168/
 
«« Prev - Next »» 5 helpful answers below.
Is this how u are doing:

This can be used in a form:

Public Sub GetTime()
Dim st As SYSTEMTIME
GetSystemTime st
Debug.Print "Year - " & st.wYear
Debug.Print "Month - " & st.wMonth
Debug.Print "DayOfWeek - " & st.wDayOfWeek
Debug.Print "Day - " & st.wDay
Debug.Print "Hour - " & st.wHour
Debug.Print "Minute - " & st.wMinute
Debug.Print "Second - " & st.wSecond
Debug.Print "Milliseconds - " & st.wMilliseconds
End Sub


This code goes into a module:

Declare Sub GetSystemTime Lib "kernel32.dll" (lpSystemTime As SYSTEMTIME)
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

apps_tech | Mon, 03 Dec 2007 19:47:00 GMT |

No, I'm defining the API call and the Type declare in a module.
Upon loading the form:
Dim myTime As SYSTEMTIME
GetSystemTime myTime

cjqp

cjqp | Mon, 03 Dec 2007 19:48:00 GMT |

Ok..here is what I found when I made a search in google:

This API can be used on the following O/S:
Windows 95
Windows 98
Windows NT starting from version 3.1
Windows 2000
Windows ME

This is how it is declared:

Declare Sub GET system time Lib "kernel32.dll" ( lpSystemTime As SYSTEM TIME )

And here is an example:

Private Declare Sub GET system time Lib "kernel32.dll" ( lpSystemTime As SYSTEM TIME )
Private Declare Function LocalFileTimeToFileTime Lib "kernel32.dll" ( lpLocalFileTime As FILE TIME , lpFileTime As FILE TIME ) As Long
Private Declare Function SystemTimeToFileTime Lib "kernel32.dll" ( lpSystemTime As SYSTEM TIME , lpFileTime As FILE TIME ) As Long
Private Declare Function CompareFileTime Lib "kernel32.dll" ( lpFileTime1 As FILE TIME , lpFileTime2 As FILE TIME ) As Long
Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" ( lpFileTime As FILE TIME , lpSystemTime As SYSTEM TIME ) As Long
Private Declare Function FileTimeToLocalFileTime Lib "kernel32.dll" ( lpFileTime As FILE TIME , lpLocalFileTime As FILE TIME ) As Long

Private Type FILE TIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Private Type SYSTEM TIME
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


' determining whether
Private Sub Command1_Click ()
Dim local time As FILE TIME , GMT time As FILE TIME , Retval As Long
Dim STimeLocal As SYSTEM TIME , STimeGMT As SYSTEM TIME , TmpTime As FILE TIME

' determine system time (without the addition of the time belts information e.g. in Berlin +1 Std.)
Call GET system time ( STimeLocal )

' system time into a file time structure convert
Retval = SystemTimeToFileTime ( STimeLocal , TmpTime )

' adding/subtracting of the time belts difference to our system time
Retval = FileTimeToLocalFileTime ( TmpTime , local time )

' UTC/CGmt time belts format of the system time provide
Retval = LocalFileTimeToFileTime ( local time , GMT time )

' copying the file time structures in system time structures
Call FileTimeToSystemTime ( GMT time , STimeGMT )
Call FileTimeToSystemTime ( local time , STimeLocal )

' times compare
Retval = CompareFileTime ( local time , GMT time )
SELECT Case Retval
Case -1
MsgBox "the current system time is in former times as the GMT time"
Case 0
MsgBox "the times are identical"
Case 1
MsgBox "the current system time is later than the GMT time"
End SELECT
With STimeLocal
Label1.Caption = wHour & ": " & wMinute & ": " & wSecond & "(restaurants)"
End With
With STimeGMT
Label1.Caption = Label1.Caption & vbCrLf & wHour & ": " & wMinute & ": " & wSecond & "(GMT)"
End With
End Sub

I hope this might help u a little

apps_tech | Mon, 03 Dec 2007 19:49:00 GMT |

Whoever made that was on crack. The spaces are all wrong. Use what was posted earlier instead.

jemidiah | Mon, 03 Dec 2007 19:50:00 GMT |

This is very weird...it suddenly started working, I tried the code that was 1st posted and it worked, so I tried my orrigenal code, which suddenly worked...very weird indeed. aha, just found it, I was declaring it as a function as apposed to a sub.
Thank you all for your help!

cjqp

cjqp | Mon, 03 Dec 2007 19:51:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories