views:

124

answers:

2
import mymodule, ctypes
#import pygame

foo = ctypes.cdll.MyDll.foo

print 'success'

if i uncomment the import pygame this fails with WindowsError: [Errno 182] The operating system cannot load %1. the stack frame is in ctypes python code, trying to load MyDll. win32 error code 182 is ERROR_INVALID_ORDINAL. if the pygame import is not there, the script runs successfully.

Update: If I run it outside the debugger, the %1 is filled with 'libpng13.dll', which is in the working directory and referenced by MyDll, and pygame is certainly loading some version of libpng. I have no idea how I would resolve this.

+2  A: 

This sounds like a dll conflict. It seems that import pygame loads some dll that is not compatible with a dll that MyDll needs. You should try to debug this with sysinternals ProcessExplorer, it can show which dlls a process has loaded; look for different dlls in both cases.

Another usefull tool to debug dll problems is the dependencywalker, from www.dependencywalker.com

theller
Sounds promising, but I'm not sure what I'm looking for in ProcessExplorer.
Dustin Getz
In ProcessExplorer, you select the process that you want to examine. Then you hit 'Ctrl+L' (View->Show Lower Pane). Configure the lower pane so that it shows DLLs with 'Ctrl+D' (View->Lower Pane View->DLLs) and examine the dlls that the process has loaded.
theller
sorry i was unclear: i understand how to use the tool, but I don't understand what I'm using it to look for.
Dustin Getz
Ok, I didn't see that you edited your question. Does pygame load a different version of libpng than your MyDll loads or needs?Does it make a difference if you first load MyDll, and then import pygame?
theller
+2  A: 

Update for the record: I believe there were multiple versions of libpng being loaded by different modules (pygame, and mydll). I used multiprocessing to separate the two modules and everything's dandy.

Dustin Getz