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

Accessing a dll from Python

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

Oct 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

[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:
from ctypes import *
windll.user32.MessageBoxA(None, "Hello world", "ctypes", 0);


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

--
Richie Hindle
ri****@entrian.com
Oct 20 '05 #2

P: n/a
If you want you can also take a look at something I wrote a while
ago (before ctypes was really well known). It has worked for me
with .DLLS form Castelle and Expervision that both have extensive
APIs. It is located here:

http://aspn.activestate.com/ASPN/Coo.../Recipe/146847

Larry Bates

dcrespo wrote:
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

Oct 20 '05 #3

P: n/a
mku
I used ctypes. It works really fine with DLLs.
have a lool at http://starship.python.net/crew/theller/ctypes
Martin

Oct 20 '05 #4

P: n/a
"dcrespo" <dc*****@gmail.com> wrote:

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.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 21 '05 #5

P: n/a
On 2005-10-20, dcrespo <dc*****@gmail.com> wrote:
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.

--
Grant Edwards grante Yow! I have a VISION! It's
at a RANCID double-FISHWICH on
visi.com an ENRICHED BUN!!
Oct 21 '05 #6

P: n/a
On 21/10/05, Grant Edwards <gr****@visi.com> wrote:
Sorry, I've no clue about anything VB-related unless it's
Victoria Bitter.


+1 QOTW.

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Oct 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.