Optimum way to help windows find the dll I'm linking to?

My code is using a library which is a static/implicitly linked DLL (let's call it DLLB) but on runtime it can't find it.

This is despite locating DLLB in the same directory as the code that calls it. (The calling code is itself a DLL, DLLA which is called from python, which is called from arcpy. I'm not quite sure why the python finds DLLA fine but DLLA doesn't find DLLB, despite them being in the same directory).

If I put the library DLL somewhere on the system path, everything works just fine.

But what's the best approach for deployment? Add an entry to the system path on the client machine, at install time? Modify the system path at runtime, from python, before loading the DLL? Something else?


Python must be specifying the full path to the DLL in the LoadLibrary call. This is recommended practice. If you specify only a module name, there is a risk of loading the wrong DLL, possibly introducing a binary planting vulnerability.

Note that although the default search path includes the directory the executable was loaded from, it does not include the directory other DLLs were loaded from. So the behaviour you're seeing is as expected.

If you can use dynamic loading, you can look up the path to DLLA and use it to construct the path to DLLB.

To get a module handle for DLLA, call GetModuleHandleEx. To get the full path to DLLA from the module handle, call GetModuleFileName. Check that the last element is DLLA.dll and replace it with DLLB.dll. You can then call LoadLibrary.

链接地址: http://www.djcxy.com/p/44548.html

上一篇: Windows如何加载DLL

下一篇: 最佳方式来帮助Windows找到我链接到的DLL?