February 16th, 2005, 03:48 PM
With the following code written in VB6, can anyone show me how I would import kernel32?
Update: After searching for kernel32 on my computer, it seems to be a VB6/C++ only library. It was found it the following location,
Private Declare Function GetTickCount Lib "kernel32" () As Long
So I'm guessing I could just have that file in my programs directory and use distutils to import it?
C:\Documents and Settings\Master\Desktop\Ryan\Microsoft Visual C++ 6.0 Standard Edition\VC98\DEBUG
Update: I've noticed that there is kernel32.dll and kernel32.dbg. Whic is the correct one?
February 17th, 2005, 05:51 PM
You should also have kernel32.dll in c:\windows\system32 as it's a Windows system file. You can't directly import it from Python like VB can, but there are ways around it:
Install Mark Hammond's Win32all extensions
follow the link to the Sourceforge download area, download and run the installer).
Then you can use:
(Borrowed from http://mail.python.org/pipermail/pyt...er/254540.html )
>>> import win32api
>>> print "Uptime:", win32api.GetTickCount(), "Milliseconds"
Or you could look at importing it with Thomas Heller's CTypes module:
Though the Win32all extension is more standard for using Windows-specific functionality.
from ctypes import *
kernel32 = windll.kernel32
GetTickCount = kernel32.GetTickCount
Last edited by sfb; February 17th, 2005 at 05:53 PM.
February 18th, 2005, 03:56 AM
Both of the solutions that sfb gives are good in general, but in this case are not needed. On Windows the time.clock() function in the standard library has a resolution of a microsecond, so is far more accurate than GetTickCount. It returns system time in seconds as a floating point, so you can replace GetTickCount with
Dave - The Developers' Coach
February 18th, 2005, 08:16 PM
Thanks for the help the both of you, I decided to stick with time.clock(). My only question is, what exactly do the numbers I receive mean? I don't know much about microseconds.