开发者

C++ DLL fails to load after linking another DLL to project

开发者 https://www.devze.com 2023-02-27 06:19 出处:网络
I\'m using Visual Studio 2010 to create a 32-bit DLL as a plug-in to a 3rd party a开发者_运维百科pp (AviSynth).The DLL was being correctly loaded by the 3rd party app until I tried to use the FFTW (ht

I'm using Visual Studio 2010 to create a 32-bit DLL as a plug-in to a 3rd party a开发者_运维百科pp (AviSynth). The DLL was being correctly loaded by the 3rd party app until I tried to use the FFTW (http://fftw.org) DLL. I took the 32-bit FFTW DLL, ran "lib /def:libfftw3-3.def" to create a .lib file, added that as a resource in the project. Made some calls to the functions. It compiles fine, but when I try to load it in the third party tool, it fails.

I've tried putting the FFTW DLL alongside my DLL, and I've also tried using LoadLibrary from inside my DllMain, but it's still not working.

I am able to stop the debugger in the DllMain function and in the function called by AviSynth (AvisynthPluginInit2), but AviSynth claims to be unable to load the DLL after that, and breakpoints at the tops of functions that were called before are no longer hit.

The AviSynth error message is: LoadPlugin: unable to load "C:\Program Files (x86)\AviSynth 2.5\plugins\xxxMYPLUGINxxx.dll"

Thanks for your help.


The first thing I try when I get something like this is Dependency Walker:

http://www.dependencywalker.com/

It won't catch every possible problem, but it's very quick to check for simple problems (missing DLLs, missing exports). You can also set it to open any number of file-extensions by double-clicking them. I usually set .dll, .ax, .ocx, .sys, .exe.

IMO one of the essential tools for any Windows developer.

ps: if Dependency Walker doesn't find any problems, try to load your DLL with LoadLibrary() and see what GetLastError() returns.


BTW:

and I've also tried using LoadLibrary from inside my DllMain, but it's still not working.

You cannot call LoadLibrary() from DllMain().

The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order.

(The entry-point function is your DllMain)


Turns out that the FFTW DLL had to be in the same directory as the AVS script, not the AVISynth plugin directory. I guess that's the working directory for Virtual Dub.

Anyway, it works now. Thanks for the help!

0

精彩评论

暂无评论...
验证码 换一张
取 消