Accessing dll

Discussion in 'Python' started by Helpful person, Sep 6, 2012.

  1. I am a complete novice to Python. I wish to access a dll that has
    been written to be compatible with C and VB6. I have been told that
    after running Python I should enter "from ctypes import *" which
    allows Python to recognize the dll structure. I have placed the dll
    into my active directory (if that's the correct word, one on my path)
    for simplification.

    I tried: "import name.dll" but this just gave me an error telling me
    that there was no such module.

    Can someone please help?

    Richard
     
    Helpful person, Sep 6, 2012
    #1
    1. Advertising

  2. Am 06.09.2012 17:07, schrieb Helpful person:
    > I am a complete novice to Python.


    Welcome!

    > I wish to access a dll that has
    > been written to be compatible with C and VB6. I have been told that
    > after running Python I should enter "from ctypes import *" which
    > allows Python to recognize the dll structure. I have placed the dll
    > into my active directory (if that's the correct word, one on my path)
    > for simplification.


    Using ctypes, you can indeed load DLLs. Take a look at
    http://docs.python.org, which includes the documentation for the ctypes
    module but also general documentation and tutorials, which should be a
    starting point for you.

    > I tried: "import name.dll" but this just gave me an error telling me
    > that there was no such module.


    Like in VB or C, things are not that easy. You will always have to write
    some code that informs Python about the names and parameters of the
    functions in that DLL.

    Good luck!

    Uli
     
    Ulrich Eckhardt, Sep 6, 2012
    #2
    1. Advertising

  3. Helpful person

    Jerry Hill Guest

    On Thu, Sep 6, 2012 at 11:07 AM, Helpful person <> wrote:
    > I am a complete novice to Python. I wish to access a dll that has
    > been written to be compatible with C and VB6. I have been told that
    > after running Python I should enter "from ctypes import *" which
    > allows Python to recognize the dll structure. I have placed the dll
    > into my active directory (if that's the correct word, one on my path)
    > for simplification.
    >
    > I tried: "import name.dll" but this just gave me an error telling me
    > that there was no such module.
    >
    > Can someone please help?


    You should start by reading the ctypes documentation, here:
    http://docs.python.org/library/ctypes.html . It has a lot of examples
    that ought to get you started.

    When you run into more specific problems, you're going to have to
    provide a lot more information before we can help you, including the
    specific documentation of the DLL you're trying to wrap, your
    platform, and python version. If you are not permitted to share those
    things, we may not be able to give you much help. Ctypes is very
    specific to the actual library you are accessing, and requires that
    you understand the requirements of the underlying DLL.

    --
    Jerry
     
    Jerry Hill, Sep 6, 2012
    #3
  4. On Sep 6, 8:30 am, Jerry Hill <> wrote:
    > You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html.  It has a lot of examples
    > that ought to get you started.
    >
    > When you run into more specific problems, you're going to have to
    > provide a lot more information before we can help you, including the
    > specific documentation of the DLL you're trying to wrap, your
    > platform, and python version.  If you are not permitted to share those
    > things, we may not be able to give you much help.  Ctypes is very
    > specific to the actual library you are accessing, and requires that
    > you understand the requirements of the underlying DLL.
    >
    > --
    > Jerry


    Thanks Jerry, I'll read the reference you posted. Unfortunately I
    know almost nothing about the dll and Python is loaded in some strange
    framework.

    I'll post back after a thorough read about Ctypes.
     
    Helpful person, Sep 6, 2012
    #4
  5. FYI

    My Python version is 2.5.4
     
    Helpful person, Sep 6, 2012
    #5
  6. On Sep 6, 8:28 am, Ulrich Eckhardt <>
    wrote:
    > Am 06.09.2012 17:07, schrieb Helpful person:
    >
    > > I am a complete novice to Python.

    >
    > Welcome!
    >
    > > I wish to access a dll that has
    > > been written to be compatible with C and VB6.  I have been told that
    > > after running Python I should enter  "from ctypes import *" which
    > > allows Python to recognize the dll structure.  I have placed the dll
    > > into my active directory (if that's the correct word, one on my path)
    > > for simplification.

    >
    > Using ctypes, you can indeed load DLLs. Take a look athttp://docs.python.org, which includes the documentation for the ctypes
    > module but also general documentation and tutorials, which should be a
    > starting point for you.
    >
    > > I tried:   "import name.dll" but this just gave me an error telling me
    > > that there was no such module.

    >
    > Like in VB or C, things are not that easy. You will always have to write
    > some code that informs Python about the names and parameters of the
    > functions in that DLL.
    >
    > Good luck!
    >
    > Uli


    Thanks. I've been working my way through that page, so far without
    any luck. I'm still trying.

    It seems strange that there is no documented way to simply access the
    dll, even incorrectly! If I could get Python to recognize the dll as
    a module I would at least have a place to start debugging.
     
    Helpful person, Sep 6, 2012
    #6
  7. On Sep 6, 8:30 am, Jerry Hill <> wrote:
    >
    > You should start by reading the ctypes documentation, here:http://docs.python.org/library/ctypes.html.  It has a lot of examples
    > that ought to get you started.
    >


    The reference might help if I could get Python to recognize the dll as
    a module.
     
    Helpful person, Sep 6, 2012
    #7
  8. Helpful person

    Jerry Hill Guest

    On Thu, Sep 6, 2012 at 12:46 PM, Helpful person <> wrote:
    > The reference might help if I could get Python to recognize the dll as
    > a module.


    That's never going to happen. It's a DLL, not a python module. I
    think the documentation lays that out pretty explicitly. Have you
    experimented with the very first bit of example code in the
    documentation? What do you get if you do the following at the
    interactive interpreter?

    >>> from ctypes import *
    >>> print windll.<insert your dll name here, without the .dll extension>



    --
    Jerry
     
    Jerry Hill, Sep 6, 2012
    #8
  9. On Sep 6, 9:58 am, Jerry Hill <> wrote:
    What do you get if you do the following at the
    > interactive interpreter?
    >
    > >>> from ctypes import *
    > >>> print windll.<insert your dll name here, without the .dll extension>

    >
    > --
    > Jerry


    I get:

    <WinDLL '<my dll name without the dll extension> , handle 410000 at
    2ace070>
     
    Helpful person, Sep 6, 2012
    #9
  10. Helpful person

    MRAB Guest

    On 06/09/2012 17:58, Jerry Hill wrote:
    > On Thu, Sep 6, 2012 at 12:46 PM, Helpful person <> wrote:
    >> The reference might help if I could get Python to recognize the dll as
    >> a module.

    >
    > That's never going to happen. It's a DLL, not a python module. I
    > think the documentation lays that out pretty explicitly. Have you
    > experimented with the very first bit of example code in the
    > documentation? What do you get if you do the following at the
    > interactive interpreter?
    >
    >>>> from ctypes import *
    >>>> print windll.<insert your dll name here, without the .dll extension>

    >

    Or this:

    >>> import ctypes
    >>> dll_path = ...
    >>> libc = ctypes.CDLL(dll_path)
    >>> dir(libc)
     
    MRAB, Sep 6, 2012
    #10
  11. Helpful person

    Tim Williams Guest

    On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote:
    > I am a complete novice to Python. I wish to access a dll that has
    >
    > been written to be compatible with C and VB6. I have been told that
    >
    > after running Python I should enter "from ctypes import *" which
    >
    > allows Python to recognize the dll structure. I have placed the dll
    >
    > into my active directory (if that's the correct word, one on my path)
    >
    > for simplification.
    >
    >
    >
    > I tried: "import name.dll" but this just gave me an error telling me
    >
    > that there was no such module.
    >
    >
    >
    > Can someone please help?
    >
    >
    >
    > Richard


    I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows)

    pth = os.environ['path'].split(';')
    pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs'))
    os.environ['path'] = ';'.join(pth)
     
    Tim Williams, Sep 6, 2012
    #11
  12. Helpful person

    Tim Williams Guest

    On Thursday, September 6, 2012 4:21:56 PM UTC-4, Tim Williams wrote:
    > On Thursday, September 6, 2012 11:07:07 AM UTC-4, Helpful person wrote:
    >
    > > I am a complete novice to Python. I wish to access a dll that has

    >
    > >

    >
    > > been written to be compatible with C and VB6. I have been told that

    >
    > >

    >
    > > after running Python I should enter "from ctypes import *" which

    >
    > >

    >
    > > allows Python to recognize the dll structure. I have placed the dll

    >
    > >

    >
    > > into my active directory (if that's the correct word, one on my path)

    >
    > >

    >
    > > for simplification.

    >
    > >

    >
    > >

    >
    > >

    >
    > > I tried: "import name.dll" but this just gave me an error telling me

    >
    > >

    >
    > > that there was no such module.

    >
    > >

    >
    > >

    >
    > >

    >
    > > Can someone please help?

    >
    > >

    >
    > >

    >
    > >

    >
    > > Richard

    >
    >
    >
    > I'm new to using the ctypes module also, but what I did to find the library was I appended the location of the dll to my PATH like so: (this is Windows)
    >
    >
    >
    > pth = os.environ['path'].split(';')
    >
    > pth.append(os.path.join(os.environ['userprofile'],'My Documents','DLLs'))
    >
    > os.environ['path'] = ';'.join(pth)


    I should have also mentioned to look at LoadLibrary in the ctypes module. e.g.

    mylib=cdll.LoadLibrary('mylib.dll')
     
    Tim Williams, Sep 6, 2012
    #12
  13. On Fri, Sep 7, 2012 at 1:44 AM, Helpful person <> wrote:
    > FYI
    >
    > My Python version is 2.5.4


    You may wish to upgrade, that's quite an old version. Unless
    something's binding you to version 2.x, I would strongly recommend
    migrating to 3.2 or 3.3.

    ChrisA
     
    Chris Angelico, Sep 7, 2012
    #13
  14. On Sep 7, 5:16 am, Chris Angelico <> wrote:
    > On Fri, Sep 7, 2012 at 1:44 AM, Helpful person <> wrote:
    > > FYI

    >
    > > My Python version is 2.5.4

    >
    > You may wish to upgrade, that's quite an old version. Unless
    > something's binding you to version 2.x, I would strongly recommend
    > migrating to 3.2 or 3.3.
    >
    > ChrisA


    Upgrading is not possible due to the large number of programs using
    the early version.
     
    Helpful person, Sep 7, 2012
    #14
  15. On Sat, Sep 8, 2012 at 3:27 AM, Helpful person <> wrote:
    > On Sep 7, 5:16 am, Chris Angelico <> wrote:
    >> On Fri, Sep 7, 2012 at 1:44 AM, Helpful person <> wrote:
    >> > FYI

    >>
    >> > My Python version is 2.5.4

    >>
    >> You may wish to upgrade, that's quite an old version. Unless
    >> something's binding you to version 2.x, I would strongly recommend
    >> migrating to 3.2 or 3.3.
    >>
    >> ChrisA

    >
    > Upgrading is not possible due to the large number of programs using
    > the early version.


    Sure. At least you've considered it. :) Do look into moving up to 2.7,
    at least, though. And of course, you can have multiple Pythons
    installed simultaneously, allowing you to migrate only when you're
    ready.

    ChrisA
     
    Chris Angelico, Sep 8, 2012
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,807
  2. Weston Fryatt
    Replies:
    2
    Views:
    981
    Weston Fryatt
    Jan 1, 2005
  3. NGM
    Replies:
    0
    Views:
    2,324
  4. wpy
    Replies:
    1
    Views:
    370
    -=Chris=-
    Nov 11, 2003
  5. H. Simpson
    Replies:
    4
    Views:
    294
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page