Accessing a dll from Python

D

dcrespo

Hi to all,

Can someone give me lights on how can I deal with dlls from python?

My main purpose is to get access to a Unitech PT600 Bar Code system. I
have the dll that works fine through Visual Basic. But I'm migrating to
Python, so I need a way to use the same dll, or a C library.

I tried to access a dll created by myself on Visual Basic. The dll just
have one function. It works perfect when using it on a VB project just
including it in the references configuration. But I can't access it
from python. I tried the ctypes module.

Thank you

Daniel
 
R

Richie Hindle

[Daniel]
I tried the ctypes module.

ctypes is the right way to do it. You need to post your code and whatever
errors you received. Here's an example of using ctypes to call a DLL:

You use "windll" for stdcall functions (eg. the Windows API) and "cdll" for
cdecl functions. I don't know which one VB defaults to. If you get it
wrong, ctypes will give you an error talking about using the "wrong calling
convention".
 
T

Tim Roberts

dcrespo said:
Can someone give me lights on how can I deal with dlls from python?

My main purpose is to get access to a Unitech PT600 Bar Code system. I
have the dll that works fine through Visual Basic. But I'm migrating to
Python, so I need a way to use the same dll, or a C library.

I tried to access a dll created by myself on Visual Basic. The dll just
have one function. It works perfect when using it on a VB project just
including it in the references configuration. But I can't access it
from python. I tried the ctypes module.

Are you talking about VB6 or VB.NET? If you had to add a reference, then
it is either a COM interface or a managed code class. DLLs don't get in
through references -- they use the Declare statement.

COM interfaces are pretty easy to call in Python. Calling managed code is
almost impossible right now.
 
G

Grant Edwards

Can someone give me lights on how can I deal with dlls from python?

Use the ctypes module.
My main purpose is to get access to a Unitech PT600 Bar Code system. I
have the dll that works fine through Visual Basic. But I'm migrating to
Python, so I need a way to use the same dll, or a C library.

ctypes can call dll functions using either C or Pascal calling
conventsions.
I tried to access a dll created by myself on Visual Basic. The
dll just have one function. It works perfect when using it on
a VB project just including it in the references
configuration. But I can't access it from python. I tried the
ctypes module.

ctypes has always worked for me.

Sorry, I've no clue about anything VB-related unless it's
Victoria Bitter.
 
Joined
Sep 27, 2006
Messages
3
Reaction score
0
Mex dll

Hi All,

How do I interface with a MEX dll that was created in matlab? if I use ctypes then it says

Traceback (most recent call last):
File "<pyshell#15>", line 1, in -toplevel-
ctypes.cdll.load(file1)
File "F:\Python24\Lib\site-packages\ctypes\_loader.py", line 112, in load
return self._load(libname, mode)
File "F:\Python24\Lib\site-packages\ctypes\_loader.py", line 124, in _load
return self._dlltype(libname, mode)
File "F:\Python24\Lib\site-packages\ctypes\__init__.py", line 300, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Errno 126] The specified module could not be found

Thanks
Peter
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top