I'm currently having interop problems between a proprietry library and pyembree.
Problem
I have two mostly identical conda enviroments. Both contain this in-house library. The only difference is that I installed pyembree via these instructions in one environment. Now in this environment, the in-house library cannot load a DLL which it has no problem loading in the other. The absolute (correct) path is even supplied to the ctypes.WinDLL object:
On module level (in a module of the proprietatry library):
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
kernel32.AddDllDirectory(os.path.abspath(os.path.dirname(__file__)))
On import this is called (where name
is the correct absolute path and mode
is 4096
):
handle = kernel32.LoadLibraryExW(name, None, mode)
Which raises a ctypes.WinError
with the message 'OSError: [WinError 127] The specified procedure could not be found.'
.
Tracking overwritten DLLs
I tried working with that error message based on https://stackoverflow.com/a/2603386/5409315 . That answer says that the error message means that a DLL is loaded, but in the wrong version. Initially, that made a lot of sense - the install of pyembree could have overwritten a dependency of the proprietry lib. (Although I don't understand why that message would be triggered on load as compared to when the procedure is supposed to be used.)
However, what I found with Process Monitor was that in both environments two dozen DLLs are searched but not found (e.g. OPENGL32.dll) and that the only DLL that is successfully loaded in both environments (vcomp140.dll) does not differ between the two environments.
I cross-checked this with Dependency Walker, where I found a lot more depended DLLs but had the same ultimate result: In both environments, the depended libraries are either literally identical or bytewise identical.
The PATH
environment variable is also equivalent (that is, where a path contains the environment directory, it differs in exactly that regard between the environments).
Minimal reproducible example
I can't provide a minimally reproducible example because the proprietary library is not publicly available.
Another approach
I'd like to dump all global variables just before the attempt to load the DLL in both environments, diff the output and thus find the crucial difference. Is this possible in VS Code? Is this possible in some other context (pdb, ...)?