[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

dll in project?

Alex Hall

3/15/2010 3:44:00 AM

Hi all,
I have a dll I am trying to use, but I get a Windows error 126, "the
specified module could not be found". Here is the code segment:
nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")

I have the specified dll file in the same directory as the file trying
to use said dll, and this is the only reference I make to the dll. Do
I need to register it somehow? If so, does this need to be done once,
or each time the application runs? If I need to register it, how would
I do so? Thanks!
--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.c...
6 Answers

Alf P. Steinbach

3/15/2010 4:20:00 AM

0

* Alex Hall:
> Hi all,
> I have a dll I am trying to use, but I get a Windows error 126, "the
> specified module could not be found". Here is the code segment:
> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>
> I have the specified dll file in the same directory as the file trying
> to use said dll, and this is the only reference I make to the dll. Do
> I need to register it somehow? If so, does this need to be done once,
> or each time the application runs? If I need to register it, how would
> I do so? Thanks!

If 'ctypes.windll.LoadLibrary' just calls the Windows API LoadLibrary function
without adding any path, then the directories considered will only be those
known to the Windows API, like e.g. the process' current directory (I'm not sure
if the current directory is considered, but the details aren't important).

And most likely your calling script file is not in any of those directories.

Probably it will work to specify the full path to the DLL. You can obtain the
path to the calling file's directory by using the __file__ variable and the
'os.path' functions.


Cheers & hth.,

- Alf

Ulrich Eckhardt

3/15/2010 10:15:00 AM

0

Alex Hall wrote:
> I have a dll I am trying to use, but I get a Windows error 126, "the
> specified module could not be found". Here is the code segment:
> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")

In addition to Alf's answer, this can also happen when the OS can't find
another DLL that this one depends on.

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Alex Hall

3/15/2010 11:28:00 AM

0

On 3/15/10, Ulrich Eckhardt <eckhardt@satorlaser.com> wrote:
> Alex Hall wrote:
>> I have a dll I am trying to use, but I get a Windows error 126, "the
>> specified module could not be found". Here is the code segment:
>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>
> In addition to Alf's answer, this can also happen when the OS can't find
> another DLL that this one depends on.

Well, os.getcwd() returns "c:\python26", not my program's directory.
However, I changed the reference to the dll to be
helpers.progdir+'\\nvdaControllerClient32.dll'
and still no luck! helpers.progdir is a var holding the top-level
directory of my project, using os.path. Again, using this more precise
reference still fails, triggering my except statement in my try/catch
loop.

Alf P. Steinbach

3/15/2010 11:38:00 AM

0

* Alex Hall:
> On 3/15/10, Ulrich Eckhardt <eckhardt@satorlaser.com> wrote:
>> Alex Hall wrote:
>>> I have a dll I am trying to use, but I get a Windows error 126, "the
>>> specified module could not be found". Here is the code segment:
>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>> In addition to Alf's answer, this can also happen when the OS can't find
>> another DLL that this one depends on.
>
> Well, os.getcwd() returns "c:\python26", not my program's directory.
> However, I changed the reference to the dll to be
> helpers.progdir+'\\nvdaControllerClient32.dll'
> and still no luck!

Are you sure you get a single directory separator backslash there?

I suggest using the os.path 'join' function, whatever it was called.


> helpers.progdir is a var holding the top-level
> directory of my project, using os.path.

But is that where the DLL resides, or is it in some subdirectory?


> Again, using this more precise
> reference still fails, triggering my except statement in my try/catch
> loop.

Try also checking the arguments & documentation of ctypes.windll.LoadLibrary. I
know, you probably already done that. But I mention it just in case (I'm not
familiar with that function at the Python level, so don't know about the args).


Cheers & hth.,

- Alf

Ulrich Eckhardt

3/15/2010 11:44:00 AM

0

Alex Hall wrote:
> On 3/15/10, Ulrich Eckhardt <eckhardt@satorlaser.com> wrote:
>> Alex Hall wrote:
>>> I have a dll I am trying to use, but I get a Windows error 126, "the
>>> specified module could not be found". Here is the code segment:
>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>>
>> In addition to Alf's answer, this can also happen when the OS can't find
>> another DLL that this one depends on.

Did you check if this could be the case?

> Well, os.getcwd() returns "c:\python26", not my program's directory.
> However, I changed the reference to the dll to be
> helpers.progdir+'\\nvdaControllerClient32.dll'
> and still no luck!

Generally, there is os.path.join() IIRC which does this portably. This
probably doesn't matter though. What I would check is firstly if this file
could be opened at all, e.g. using os.stat().

> helpers.progdir is a var holding the top-level directory of my
> project, using os.path.

Huh? In what way using os.path?

> Again, using this more precise reference still fails, triggering my
> except statement in my try/catch loop.

Same error? See my initial guess! As a tool for finding out if there are
missing dependencies, take a look at http://dependency...

BTW: No need to CC me, I read your initial request here, I can ready any
follow-ups here, too. ;)

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Alex Hall

3/15/2010 1:24:00 PM

0

Okay, I got a new copy and all seems well now. The dll is found and
loaded. The functions inside the dll are not working, but that is not
Python's fault. Thanks to everyone for your help and suggestions!

On 3/15/10, Ulrich Eckhardt <eckhardt@satorlaser.com> wrote:
> Alex Hall wrote:
>> On 3/15/10, Ulrich Eckhardt <eckhardt@satorlaser.com> wrote:
>>> Alex Hall wrote:
>>>> I have a dll I am trying to use, but I get a Windows error 126, "the
>>>> specified module could not be found". Here is the code segment:
>>>> nvdaController=ctypes.windll.LoadLibrary("nvdaControllerClient32.dll")
>>>
>>> In addition to Alf's answer, this can also happen when the OS can't find
>>> another DLL that this one depends on.
>
> Did you check if this could be the case?
>
>> Well, os.getcwd() returns "c:\python26", not my program's directory.
>> However, I changed the reference to the dll to be
>> helpers.progdir+'\\nvdaControllerClient32.dll'
>> and still no luck!
>
> Generally, there is os.path.join() IIRC which does this portably. This
> probably doesn't matter though. What I would check is firstly if this file
> could be opened at all, e.g. using os.stat().
>
>> helpers.progdir is a var holding the top-level directory of my
>> project, using os.path.
>
> Huh? In what way using os.path?
>
>> Again, using this more precise reference still fails, triggering my
>> except statement in my try/catch loop.
>
> Same error? See my initial guess! As a tool for finding out if there are
> missing dependencies, take a look at http://dependency...
>
> BTW: No need to CC me, I read your initial request here, I can ready any
> follow-ups here, too. ;)
>
> Uli
>
> --
> Sator Laser GmbH
> Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
>
> --
> http://mail.python.org/mailman/listinfo/p...
>


--
Have a great day,
Alex (msg sent from GMail website)
mehgcap@gmail.com; http://www.facebook.c...