Calling dlls with Calldll/WinDll or Ctypes or...

T

Todd Gardner

Hello all,

Pardon my ignorance here. I would like to talk to someone that has
had success in calling ddls in Windows NT/2000/XP.

I am wondering where to dload any of these packages? Google searches
keep turning up articles similar to this.

Any pointers would be greatly appreciated!

Todd
 
F

Fredrik Lundh

Todd said:
Pardon my ignorance here. I would like to talk to someone that has
had success in calling ddls in Windows NT/2000/XP.

I am wondering where to dload any of these packages? Google searches
keep turning up articles similar to this.

similar to what?

google for ctypes and press "I feel lucky":

http://starship.python.net/crew/theller/ctypes/
which has a "downloads" section a bit down.

calldll is a bit harder; you have to add "python" to the search string
to make "I feel lucky" work:

http://www.nightmare.com/software.html

both distributions comes with enough demos and samples to get you
going. for details on available Win32 functions, see:

http://msdn.microsoft.com

</F>
 
M

Myles

Pardon my ignorance here. I would like to talk to someone that has
had success in calling ddls in Windows NT/2000/XP.

caldll works, but the more recent ctypes is easier to use.

The ctypes documentation has nice examples for calling functions
exported by standard Windows DLLs (i.e. Microsoft ones that are
supplied with Windows).
Below are a couple of examples of calling third-party DLLs.

Regards, Myles.

# ------------------ snip ------------------------

from ctypes import *
import time

# ------------------------------------------------

anotherdll = windll.AutoItDLL # loads AutoItDLL.dll (in same directory)

# AutoItDLL.dll exports a function AUTOIT_ClipPut
anotherdll.AUTOIT_ClipPut(c_char_p("something"))

# AutoItDLL.dll exports a function AUTOIT_ClipGet
s = c_buffer(16384) # size of clipboard buffer
time.sleep(2) # apparently it takes a while to create that buffer ?
anotherdll.AUTOIT_ClipGet(s)
print repr(s.value)

# ------------------------------------------------

somedll = windll.FreeImage # loads FreeImage.dll (in same directory)

# some DLLs export function names strangely
# (open the .dll in a capable text editor to read the function names)
GetVersion = getattr(somedll, "_FreeImage_GetVersion@0")
GetVersion.restype = c_char_p
print GetVersion()

GetFileType = getattr(somedll, "_FreeImage_GetFileType@8")
filename = "/temp/screen01.jpg"
imgtype = GetFileType(filename, 0)

Load = getattr(somedll, "_FreeImage_Load@12")
image_ptr = Load(imgtype, filename, 0)

GetWidth = getattr(somedll, "_FreeImage_GetWidth@4")
print GetWidth(image_ptr)

# --------------- snip ---------------------------
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top