如何阻止延迟加载的DLL从您的计算机中丢失“系统错误? [英] How do I stop a delay-loaded DLL from throwing a "missing from your computer" system error?

查看:236
本文介绍了如何阻止延迟加载的DLL从您的计算机中丢失“系统错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天在我的插件中设置了延迟加载:

I set up delay loading in my plugin yesterday:

#ifdef _WIN32
#pragma warning (disable : 4100)  /* Disable Unreferenced parameter warning */
#include <windows.h>
#include <delayimp.h>
#endif

...

// Configuration Properties / Linker / Input / Additional Dependencies: ./lib/libcurl.lib;./lib/libxml2.lib;./lib/iconv.lib;./lib/zlib1.lib;%(AdditionalDependencies)
// Configuration Properties / Linker / Input /Delay Loaded Dlls: libcurl;libxml2;iconv;zlib1;%(DelayLoadDLLs)

#include "curl.h"
#include "HTMLparser.h"
#include "xpath.h"

#ifdef _WIN32
#pragma comment(lib, "libcurl")
#pragma comment(lib, "iconv")
#pragma comment(lib, "libxml2")
#pragma comment(lib, "zlib1")
#endif

[ 1 ]

我正在初始化插件加载的DLL:

And I'm initializing the DLLs on plugin load:

#ifdef _WIN32
    SetDllDirectory(L"./plugins/ts3websitepreview/");
    if (FAILED(__HrLoadAllImportsForDll("libcurl.dll"))) {
        ts3Functions.logMessage("Could not load curl.", LogLevel_ERROR, "Plugin", 0);
        return 1;
    }
    if (FAILED(__HrLoadAllImportsForDll("libxml2.dll"))) {
        ts3Functions.logMessage("Could not load libxml.", LogLevel_ERROR, "Plugin", 0);
        return 1;
    }
    if (FAILED(__HrLoadAllImportsForDll("zlib1.dll"))) {
        ts3Functions.logMessage("Could not load zlib1.", LogLevel_ERROR, "Plugin", 0);
        return 1;
    }
    if (FAILED(__HrLoadAllImportsForDll("iconv.dll"))) {
        ts3Functions.logMessage("Could not load iconv.", LogLevel_ERROR, "Plugin", 0);
        return 1;
    }
#endif

[ 2 ]

这是添加pragma语句后的构建日志:

Here is my build log after adding the pragma statements:

1>------ Build started: Project: ts3websitepreview, Configuration: Debug Win32 ------
1>Build started 2016-06-15 06:35:23 PM.
1>InitializeBuildStatus:
1>  Creating "Debug\ts3websitepreview.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  plugin.c
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>Link:
1>     Creating library .\ts3websitepreview.lib and object .\ts3websitepreview.exp
1>LINK : warning LNK4199: /DELAYLOAD:libcurl ignored; no imports found from libcurl
1>LINK : warning LNK4199: /DELAYLOAD:libxml2 ignored; no imports found from libxml2
1>LINK : warning LNK4199: /DELAYLOAD:iconv ignored; no imports found from iconv
1>LINK : warning LNK4199: /DELAYLOAD:zlib1 ignored; no imports found from zlib1
1>Manifest:
1>  All outputs are up-to-date.
1>LinkEmbedManifest:
1>  All outputs are up-to-date.
1>  ts3websitepreview.vcxproj -> .\ts3websitepreview.dll
1>FinalizeBuildStatus:
1>  Deleting file "Debug\ts3websitepreview.unsuccessfulbuild".
1>  Touching "Debug\ts3websitepreview.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:01.60
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

立即更改为:

1>------ Build started: Project: ts3websitepreview, Configuration: Debug Win32 ------
1>Build started 2016-06-15 06:39:54 PM.
1>InitializeBuildStatus:
1>  Creating "Debug\ts3websitepreview.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1>  plugin.c
1>ManifestResourceCompile:
1>  All outputs are up-to-date.
1>Manifest:
1>  All outputs are up-to-date.
1>LinkEmbedManifest:
1>  All outputs are up-to-date.
1>  ts3websitepreview.vcxproj -> .\ts3websitepreview.dll
1>FinalizeBuildStatus:
1>  Deleting file "Debug\ts3websitepreview.unsuccessfulbuild".
1>  Touching "Debug\ts3websitepreview.lastbuildstate".
1>
1>Build succeeded.
1>
1>Time Elapsed 00:00:00.71
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========


$ b。

After another build with no changes to the code.

但是,在插件甚至初始化之前,仍然尝试加载DLL,给我一个:

But instead, it's still trying to load the DLL before the plugin even initializes, giving me a:

ts3client_win32.exe - System Error
The program can't start because libcurl.dll is missing from your computer. Try reinstalling the program to fix this problem.

我使用的教程这里 here 用于延迟加载。我还阅读了这里的问题, a href =https://stackoverflow.com/questions/173433/how-to-fix-dwmapi-dll-delay-load-dependency-under-winxp> here ,这里这里,但没有一个解决了我的问题。

I used the tutorials here and here for delayed loading. I've also read the questions here, here, here, and here but none have solved my problem.

推荐答案

不要忘记包含 *。dll 扩展名。在链接器选项中,您必须指定以下内容:

Don't forget to include the "*.dll" extension. In linker option you must specify the following:

libcurl.dll; libxml2.dll; zlib1.dll; iconv.dll;

如果您使用 #pragma comment(lib,libcurl),那么您没有在链接器选项中第二次指定它。

If you use #pragma comment(lib, "libcurl") then you don't have to specify it a second time in linker option.

SetDllDirectory(L./ plugins / ts3websitepreview /); 应该足够了您不需要 __ HrLoadAllImportsForDll

SetDllDirectory(L"./plugins/ts3websitepreview/"); should be sufficient. You don't need __HrLoadAllImportsForDll.

如果您想提前调用DLL的 DLL_PROCESS_ATTACH ,则使用 LoadLibrary

If you want to call DLL's DLL_PROCESS_ATTACH ahead of time, then use LoadLibrary instead.

这篇关于如何阻止延迟加载的DLL从您的计算机中丢失“系统错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆