简体   繁体   中英

Calling single third-party function causes regsvr32 to fail, even as admin

I am running Visual Studio as an Admin, as you can see in this image here:

以管理员身份运行的 Visual Studio

My project creates a COM .dll that gets registered after the build. Ordinarily, everything gets built and registered properly:

成功输出

The other day I decided I'd like to use another library in my project. It happens to be the poppler PDF library. I have downloaded what appears to be the x64 version of that library for Windows, from here .

I added the poppler header directory to Properties > C/C++ > General > Additional Include Directories , and then included the necessary headers in the code like so:

#include <poppler/cpp/poppler-document.h>
#include <poppler/cpp/poppler-page.h>

Then I added the directory containing the poppler .lib files to Properties > Linker > General > Additional Library Directories , and I added the name of the .lib file, poppler-cpp.lib , to Properties > Linker > Input > Additional Dependencies .

Finally, I added just one line of poppler code to the project:

poppler::document* doc = poppler::document::load_from_file("C:\\test.pdf");

The code appears to compile and link properly. I do not receive any compilation or linking errors. So I believe the headers and libraries have been set up properly.

However, after including that single line of poppler code, Visual Studio is no longer able to register the output .dll . I receive this error:

MSBuild Error MSB8011: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.

Please recall that I am running Visual Studio as an Admin, and I am able to successfully register the .dll output when NOT calling the poppler function. If I comment out that single line of poppler code, registration is successful.

I have tried disabling output registration in Visual Studio, and then manually registering the .dll from a command prompt using regsvr32 with Admin privileges, but then I receive this error:

The module "ShExt.dll" failed to load. Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent.DLL files. The specified module could not be found.

Could anyone assist with this problem?

In addition, I have placed the poppler Dlls into my project output Dll folder, like so:

Picture of output directory

Nonetheless, I continue to receive the error: Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions. Failed to register output. Please try enabling Per-user Redirection or register the component from a command prompt with elevated permissions.

Most likely, the PDF library's .lib file is an import lib for functions implemented in another DLL, and when your DLL is loaded, the loader can't find that other DLL to satisfy the calls your DLL makes to the PDF DLL's functions.

This is even hinted at in the regsvr32 error message:

The module "ShExt.dll" failed to load. Make sure the binary is stored at the specified path or debug it to check for problems with the binary or dependent.DLL files . The specified module could not be found.

If this is the case, make sure the PDF library's DLL is either in the same folder as your DLL, or is in a folder on the OS's search path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM