Dan, your patch works fine on XP. I was in error in thinking that some other version of FreeImage.dll was compiled as cdecl. (Long story...) Zach On May 23, 2011, at 11:33 AM, Zachary Pincus wrote:
Dan, if you could check that the relevant binaries (x64 and i386) of the latest version of FreeImage available online are stdcall, then that fix should be good.
Otherwise (or perhaps in any case) we could add a "sniff_function" parameter to load_library, which would be the name of a symbol to look for in the library, and if not present, try to open the library with the other convention. Something like:
if sys.platform == 'win32': windll = ctypes.windll(libpath) if sniff_function is not None and not hasattr(dll, sniff_function): cdll = ctypes.cdll(libpath) if hasattr(cdll, sniff_function): return cdll else: raise AttributeError("Could not find function %s in %s"%(sniff_function, libpath)) return windll
On May 23, 2011, at 11:16 AM, Dan Farmer wrote:
Zach's essentially got it. It has to do with the different x86 calling conventions that are available. Most compilers use cdecl, but Microsoft's compilers sometimes use something called stdcall (which, looking at the symbols from FreeImage.dll, appears to be the case there). So ctypes.cdll loads a dll using cdecl convention and ctypes.windll loads a dll using stdcall.
The unfortunate thing is that you're not guaranteed to always get stdcall dlls on windows and cdecl everywhere else. MSVC++ can compile cdecl exe's also, it's just a flag. Since this particular code is for the freeimage bindings though my hope is that if it passes the "download the latest freeimage binary, unzip and run" test then maybe we can call it good?
-Dan
On Mon, May 23, 2011 at 5:12 AM, Zachary Pincus <zachary.pincus@yale.edu> wrote:
Strange that it worked at all then. Does anybody know the difference between cdll and windll?
It's to do with how the symbols are declared in the library, and how the arguments are pushed to the stack (or something similar). Not all dlls on windows seem to be compiled with the windll calling convention, though I don't know why or in what circumstances you see that.
Anyway, I'll test further when I get a chance (sorry, very busy here).