Calling DLLs from Python [Windows]

Discussion in 'Python' started by Georgy Pruss, Oct 8, 2003.

  1. Georgy Pruss

    Georgy Pruss Guest

    Hi all,

    How can I call a function which is in a Windows DLL? For example,

    import win32api
    lib_hnd = win32api.LoadLibrary( "user32.dll" )
    if lib_hnd:
    fn_addr = win32api.GetProcAddress( lib_hnd, "MessageBeep" ) # returns int(2010532466)
    if fn_addr:
    # Here I'd like to call fn_addr. In C it would be plain fn_addr()
    win32api.FreeLibrary( lib_hnd )

    Google didn't help on this.

    Thank you,
    Georgy Pruss
    E^mail: 'ZDAwMTEyMHQwMzMwQGhvdG1haWwuY29t\n'.decode('base64')
     
    Georgy Pruss, Oct 8, 2003
    #1
    1. Advertising

  2. "Georgy Pruss" <> writes:

    > How can I call a function which is in a Windows DLL? For example,


    ctypes is your friend
    from ctypes import *

    If you have t.dll exporting INCREMENT

    # load dll
    inc = windll.LoadLibrary("t.dll")

    # Initiate c-variable for the dll
    n=c_int(1)

    # Call the dll one
    inc.INCREMENT(byref(n))
    print "The integer is now: %d" % n.value

    # And a few times more:
    for i in range(5):
    inc.INCREMENT(byref(n))
    print "The square of the integer is now: %d" % n.value**2

    > Google didn't help on this.


    ???????

    http://groups.google.com/groups?hl=...=off&q=external dll python&btnG=Google Search



    --
    Brian (remove the sport for mail)
    http://www.et.dtu.dk/staff/be
     
    Brian Elmegaard, Oct 8, 2003
    #2
    1. Advertising

  3. Georgy Pruss

    Georgy Pruss Guest

    Georgy Pruss, Oct 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fas
    Replies:
    2
    Views:
    315
  2. Todd Gardner
    Replies:
    3
    Views:
    470
    Myles
    Jan 14, 2004
  3. Fernando
    Replies:
    1
    Views:
    405
  4. DE
    Replies:
    3
    Views:
    397
    Trent Mick
    Jun 9, 2005
  5. Jack Wright
    Replies:
    3
    Views:
    256
    Emil Kvarnhammar
    Jul 30, 2004
Loading...

Share This Page