Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Accessing dll

Reply
Thread Tools

Accessing dll

 
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
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
 
Reply With Quote
 
 
 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      09-06-2012
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

 
Reply With Quote
 
 
 
 
Jerry Hill
Guest
Posts: n/a
 
      09-06-2012
On Thu, Sep 6, 2012 at 11:07 AM, Helpful person <(E-Mail Removed)> 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
 
Reply With Quote
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
On Sep 6, 8:30*am, Jerry Hill <(E-Mail Removed)> 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.
 
Reply With Quote
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
FYI

My Python version is 2.5.4

 
Reply With Quote
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
On Sep 6, 8:28*am, Ulrich Eckhardt <(E-Mail Removed)>
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.
 
Reply With Quote
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
On Sep 6, 8:30*am, Jerry Hill <(E-Mail Removed)> 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.
 
Reply With Quote
 
Jerry Hill
Guest
Posts: n/a
 
      09-06-2012
On Thu, Sep 6, 2012 at 12:46 PM, Helpful person <(E-Mail Removed)> 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
 
Reply With Quote
 
Helpful person
Guest
Posts: n/a
 
      09-06-2012
On Sep 6, 9:58*am, Jerry Hill <(E-Mail Removed)> 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>
 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      09-06-2012
On 06/09/2012 17:58, Jerry Hill wrote:
> On Thu, Sep 6, 2012 at 12:46 PM, Helpful person <(E-Mail Removed)> 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)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory Allication (Managed VC++ DLL to Unmanaged DLL) [Second Try] Weston Fryatt ASP .Net 2 01-01-2005 11:31 AM
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
Why does Ruby use both tcl83.dll and tk83.dll (instead of just tk83.dll)? H. Simpson Ruby 4 08-03-2004 04:45 PM
mprapi.dll --> samlib.dll --> ntdll.dll issue. Some1 Computer Support 4 04-05-2004 02:02 AM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments