By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,699 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,699 IT Pros & Developers. It's quick & easy.

Calling DLLs from Python [Windows]

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a

"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.