469,117 Members | 1,589 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,117 developers. It's quick & easy.

Calling DLLs from Python [Windows]

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('base6 4')
Jul 18 '05 #1
2 27226
"Georgy Pruss" <SE************@hotmail.com> 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=e...=Google+Search

--
Brian (remove the sport for mail)
http://www.et.dtu.dk/staff/be
Jul 18 '05 #2

"Brian Elmegaard" <br***@rk-speed-rugby.dk> wrote in message news:un***********@mail.afm.dtu.dk...
"Georgy Pruss" <SE************@hotmail.com> writes:
How can I call a function which is in a Windows DLL? For example,
ctypes is your friend


Thank you!
Google didn't help on this.
???????

http://groups.google.com/groups?hl=e...=Google+Search


Sure. The right question is half of the answer :)
Thanks!

Georgy.


--
Brian (remove the sport for mail)
http://www.et.dtu.dk/staff/be

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Todd Gardner | last post: by
9 posts views Thread by F. GEIGER | last post: by
3 posts views Thread by Brian Elmegaard | last post: by
reply views Thread by Dave.NET | last post: by
reply views Thread by kim d | last post: by
10 posts views Thread by notejam | last post: by
5 posts views Thread by momobear | last post: by
14 posts views Thread by TheFlyingDutchman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.