Importing a 3rd Party windows DLL for use within th Python

Robert Kern robert.kern at gmail.com
Fri Apr 4 19:29:33 EDT 2008


lee.walczak at gmail.com wrote:
> Hi,
> 
> I have recently started learing how to code/script in Python which I
> am realy enjoying. I am new to this game as my background is RF/HW
> design engineer so coding is not my first skillset , so please bare
> with me!
> 
>  I am a little lost with how to procede on this problem. I need to
> write a python script enabling me to comunnicate routines to a pico
> ADC212 oscilloscope. I have been provided with a windows DLL & a
> header filefrom the manufacturer.
> Is it possible for someone to provide the information on the steps
> necessary to access this DLL and treat it like any other pyd library?
> Maybe there is already a tutorial available for performing this task?
> Is this task straight forward?

It depends on how complicated the library is. For a first stab, I recommend 
using ctypes. ctypes lets you load the DLL and call its functions in pure Python 
without having to write an extension module (pyd) first. ctypes comes with 
Python 2.5 already; if you have Python 2.4, you can install it separately.

   http://python.net/crew/theller/ctypes/

You may eventually want to write an extension module. Here is the tutorial:

   http://docs.python.org/ext/ext.html

There are a couple of tools to make this task easier. I happen to like Cython 
for things like this:

   http://cython.org/

One large benefit of using ctypes instead of building an extension is that you 
do not have to compile anything. When wrapping binary-only DLLs on Windows, 
compiling and linking correctly are often the largest hurdles.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list