Can I use two incompatible versions of the same DLL in the same process?

前端 未结 7 1232
孤独总比滥情好
孤独总比滥情好 2020-12-31 11:45

I\'m using two commercial libraries that are produced by the same vendor, called VendorLibA and VendorLibB. The libraries are distributed as many DLLs that depend on the com

7条回答
  •  萌比男神i
    2020-12-31 11:57

    I had a similar problem. Specifically I wanted to use a PyQt from a Python interpreter embedded in an application that was using an incompatible version of Qt. There were two Qt DLLs used by the primary application: QtCore.dll and QtGui.dll.

    When I would load PyQt from the embedded Python interpreter, I would get an error:

    ImportError: DLL load failed: The specified procedure could not be found.
    

    This occured on the line:

    from PyQt4 import QtGui
    

    The problem is that the once an incompatible QtGui.dll is loaded into the main application's process space any references to QtGui.dll (e.g. from the file QtGui.pyd) are incorrect.

    What happened next, I am not proud of.

    First I renamed QtGui4.dll in the PyQt distribution to QtGuiX.dll and then renamed the QtCore4.dll to QtCoreX.dll. Notice that the renaming maintained the same number of characters, this is important.

    Next I opened the file QtGui.pyd in Notepad++, and replaced all plain-text references of QtGui4.dll to QtGuiX.dll and from QtCore4.dll to QtCoreX.dll. I repeated the process for the files: QtCore.pyd, QtGuiX.dll and QtCoreX.dll.

    Finally I checked that my PyQt test application still worked. It did! Then I tried running the PyQt test application from the embedded Python interpreter, and it worked as well.

    So, it seems to works in a couple of trivial cases. I expect that I need to repeat the process for all DLLs and PYDs in the PyQt distribution.

    This is probably not the right way to do things, but I can't think of any concrete reasons how it could blow up (other than if I change the length of the file name).

    Credit (or blame) to others on the thread for inspiring this terrible tale.

提交回复
热议问题