#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    Importing kernel32


    With the following code written in VB6, can anyone show me how I would import kernel32?
    Code:
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Update: After searching for kernel32 on my computer, it seems to be a VB6/C++ only library. It was found it the following location,
    Code:
    C:\Documents and Settings\Master\Desktop\Ryan\Microsoft Visual C++ 6.0 Standard Edition\VC98\DEBUG
    So I'm guessing I could just have that file in my programs directory and use distutils to import it?
    Update: I've noticed that there is kernel32.dll and kernel32.dbg. Whic is the correct one?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    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
    (http://starship.python.net/crew/mham...Downloads.html
    follow the link to the Sourceforge download area, download and run the installer).

    Then you can use:

    Code:
    >>> import win32api
    >>> print "Uptime:", win32api.GetTickCount(), "Milliseconds"
    (Borrowed from http://mail.python.org/pipermail/pyt...er/254540.html )

    Or you could look at importing it with Thomas Heller's CTypes module:

    http://groups-beta.google.com/group/...=en&lr=&rnum=1

    Code:
    import time
    from ctypes import *
    
    kernel32 = windll.kernel32
    GetTickCount = kernel32.GetTickCount
    GetTickCount()
    Though the Win32all extension is more standard for using Windows-specific functionality.
    Last edited by sfb; February 17th, 2005 at 04:53 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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
    Code:
    int(time.clock()*1000)
    Dave - The Developers' Coach
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    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.
    Code:
    >>> int(time.clock()*5)
    32827
    >>> int(time.clock()*5)
    32984
    >>> int(time.clock()*5)
    33005

IMN logo majestic logo threadwatch logo seochat tools logo