Accessing a dll from Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dcrespo

    Accessing a dll from Python

    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

  • Richie Hindle

    #2
    Re: Accessing a dll from Python


    [Daniel][color=blue]
    > I tried the ctypes module.[/color]

    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:
    [color=blue][color=green][color=darkred]
    >>> from ctypes import *
    >>> windll.user32.M essageBoxA(None , "Hello world", "ctypes", 0);[/color][/color][/color]

    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
    richie@entrian. com

    Comment

    • Larry Bates

      #3
      Re: Accessing a dll from Python

      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:



      Larry Bates

      dcrespo wrote:[color=blue]
      > 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
      >[/color]

      Comment

      • mku

        #4
        Re: Accessing a dll from Python

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

        Comment

        • Tim Roberts

          #5
          Re: Accessing a dll from Python

          "dcrespo" <dcrespo@gmail. com> wrote:[color=blue]
          >
          >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.[/color]

          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, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • Grant Edwards

            #6
            Re: Accessing a dll from Python

            On 2005-10-20, dcrespo <dcrespo@gmail. com> wrote:
            [color=blue]
            > Can someone give me lights on how can I deal with dlls from python?[/color]

            Use the ctypes module.
            [color=blue]
            > 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.[/color]

            ctypes can call dll functions using either C or Pascal calling
            conventsions.
            [color=blue]
            > 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.[/color]

            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!!

            Comment

            • Simon Brunning

              #7
              Re: Accessing a dll from Python

              On 21/10/05, Grant Edwards <grante@visi.co m> wrote:[color=blue]
              > Sorry, I've no clue about anything VB-related unless it's
              > Victoria Bitter.[/color]

              +1 QOTW.

              --
              Cheers,
              Simon B,
              simon@brunningo nline.net,

              Comment

              Working...