Prev: How to change 7 to 07 in VB Script?
Next: Type Mismatch
From: Alain Dekker on 23 Feb 2010 06:46 I know how to privately declare a function exported from kernel32.dll as follows: Private Declare Function GetTickCount Lib "kernel32 as Long and then to use code like this: Dim lElapsed as Long lElapsed = (GetTickCount() - lPreviousTimeValue) ' etc but I'm curious. Why is the type Long? The VB.NET (2003.NET) documentation tells me that a Long is a 64-bit signed number. In my experience of all previous compilers (Delphi 7, Visual C++, etc), I'ce always known GetTickCount() to return a DWORD (unsigned 32-bit number). In fact, the MSDN documentation states that: DWORD WINAPI GetTickCount(void); http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx Why does VB return a signed 64-bit number? Why doesn't VB have a unsigned 32-bit integer data type anyway? Its got a 8-bit and 16-bit unsigned type, but no 32-bit unsigned. Also, what are the units of the VB GetTickCount version? Again, in all previous compilers it was in ms, is that still the case? Thanks, Alain
From: Armin Zingler on 23 Feb 2010 07:21 Alain Dekker schrieb: > I know how to privately declare a function exported from kernel32.dll as > follows: > Private Declare Function GetTickCount Lib "kernel32 as Long > > and then to use code like this: > Dim lElapsed as Long > lElapsed = (GetTickCount() - lPreviousTimeValue) > ' etc > > but I'm curious. Why is the type Long? Because your declaration is wrong. > The VB.NET (2003.NET) documentation > tells me that a Long is a 64-bit signed number. In my experience of all > previous compilers (Delphi 7, Visual C++, etc), I'ce always known > GetTickCount() to return a DWORD (unsigned 32-bit number). Yes, that's why the return value has to be UInteger (or UInt32) in VB 2005/2008. In VB 2003, you were able to declare it as Integer or Int32 which is at least the right bitness (32). UInt32 was already there in FW 1.1: http://msdn.microsoft.com/en-us/library/hfa3fa08%28VS.71%29.aspx However, the type wasn't "CLS compliant", and VB 2003 didn't have a mapped native type like UInteger yet. > In fact, the MSDN documentation states that: > DWORD WINAPI GetTickCount(void); > http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx > > Why does VB return a signed 64-bit number? Why doesn't VB have a unsigned > 32-bit integer data type anyway? Now it has. "What's new in VB 2005", read "Unsigned Types": http://msdn.microsoft.com/en-us/library/y17w47af%28VS.80%29.aspx > Its got a 8-bit and 16-bit unsigned type, > but no 32-bit unsigned. > > Also, what are the units of the VB GetTickCount version? It's not VB's version. It's a function in one of Windows' dlls (kernel32). > Again, in all > previous compilers it was in ms, is that still the case? As it's the same function you use from different languages, it is still ms. And, BTW, have a look here: http://msdn.microsoft.com/en-us/library/system.environment.tickcount.aspx -- Armin
From: Tom Shelton on 23 Feb 2010 08:33 On 2010-02-23, Alain Dekker <abdekker(a)NOSPAM.fsmail.net> wrote: > I know how to privately declare a function exported from kernel32.dll as > follows: > Private Declare Function GetTickCount Lib "kernel32 as Long > > and then to use code like this: > Dim lElapsed as Long > lElapsed = (GetTickCount() - lPreviousTimeValue) > ' etc > > but I'm curious. Why is the type Long? The VB.NET (2003.NET) documentation > tells me that a Long is a 64-bit signed number. In my experience of all > previous compilers (Delphi 7, Visual C++, etc), I'ce always known > GetTickCount() to return a DWORD (unsigned 32-bit number). > > In fact, the MSDN documentation states that: > DWORD WINAPI GetTickCount(void); > http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx > > Why does VB return a signed 64-bit number? Why doesn't VB have a unsigned > 32-bit integer data type anyway? Its got a 8-bit and 16-bit unsigned type, > but no 32-bit unsigned. > > Also, what are the units of the VB GetTickCount version? Again, in all > previous compilers it was in ms, is that still the case? > > Thanks, > Alain > > What Armin said... Plus, there is always System.Environment.TickCount which internally calls GetTickCount anyway :) -- Tom Shelton
From: Alain Dekker on 23 Feb 2010 09:41 Strange oversight not to include a unsigned integer as a native type in VB 2003.NET. I'll take the data type with the same bitness, thats fine. Thanks for thoe replies! Alain "Tom Shelton" <tom_shelton(a)comcastXXXXXXX.net> wrote in message news:uIRUTzItKHA.1440(a)TK2MSFTNGP06.phx.gbl... > On 2010-02-23, Alain Dekker <abdekker(a)NOSPAM.fsmail.net> wrote: >> I know how to privately declare a function exported from kernel32.dll as >> follows: >> Private Declare Function GetTickCount Lib "kernel32 as Long >> >> and then to use code like this: >> Dim lElapsed as Long >> lElapsed = (GetTickCount() - lPreviousTimeValue) >> ' etc >> >> but I'm curious. Why is the type Long? The VB.NET (2003.NET) >> documentation >> tells me that a Long is a 64-bit signed number. In my experience of all >> previous compilers (Delphi 7, Visual C++, etc), I'ce always known >> GetTickCount() to return a DWORD (unsigned 32-bit number). >> >> In fact, the MSDN documentation states that: >> DWORD WINAPI GetTickCount(void); >> http://msdn.microsoft.com/en-us/library/ms724408(VS.85).aspx >> >> Why does VB return a signed 64-bit number? Why doesn't VB have a unsigned >> 32-bit integer data type anyway? Its got a 8-bit and 16-bit unsigned >> type, >> but no 32-bit unsigned. >> >> Also, what are the units of the VB GetTickCount version? Again, in all >> previous compilers it was in ms, is that still the case? >> >> Thanks, >> Alain >> >> > > What Armin said... Plus, there is always System.Environment.TickCount > which > internally calls GetTickCount anyway :) > > -- > Tom Shelton
From: Patrice on 24 Feb 2010 04:17
As a side not the declaration you used was likely for VB6. In VB6 long was actually integer (likely because of its 16 bit past)... When picking a "declare" somewhere double check if it was intended for VB6. In this case it needs to be changed... -- Patrice |