1

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]

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]

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 ==========

Which immediately changed to:

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 ==========

After another build with no changes to the code.

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.

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
NobleUplift
  • 5,631
  • 8
  • 45
  • 87
  • In Visual Studio, "Project Properties -> Linker -> Input -> Delay Loaded Dll" you should set "libcurl.dll;iconv.dll" etc. – Barmak Shemirani Jun 13 '16 at 00:04
  • @BarmakShemirani I've already done that as you can see on line 10 of my first code example or line 21 or my actual code. – NobleUplift Jun 13 '16 at 16:37
  • You have to change project properties, it's not a line of code. I can't see that anywhere in your question or the links. You have put too many links, I am not sure what you are referring too. Changing Project Properties option is all you need. – Barmak Shemirani Jun 13 '16 at 16:43
  • @BarmakShemirani I put the Project Properties in a comment to easily show within the question that I had already set that Linker property. You can see my linker properties [here](https://github.com/NobleUplift/TeamSpeak3WebsitePreview/blob/master/ts3websitepreview/ts3websitepreview.vcxproj#L102). – NobleUplift Jun 14 '16 at 20:04
  • It looks like you didn't add `*.dll` extension. VS should give you a linker warning. Make sure you set warning level to 4. By the way, I don't know what `__HrLoadAllImportsForDll` is for. I think it's used in connection with some other functions. You shouldn't need it. You might start another question if you that's important to your project (use the `WinAPI` tag in your question) – Barmak Shemirani Jun 14 '16 at 23:25

1 Answers1

2

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

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

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/"); should be sufficient. You don't need __HrLoadAllImportsForDll.

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

Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77
  • Thanks. I'll try this when I get home. – NobleUplift Jun 15 '16 at 14:41
  • Well that was probably my worst case of misreading the documentation ever. I'm getting `LINK : fatal error LNK1194: cannot delay-load 'libxml2.dll' due to import of data symbol '__imp__xmlFree'; link without /DELAYLOAD:libxml2.dll` but that might be another question altogether. Funny thing is if I comment it out, my DLL compiles and works fine... it will just memory leak. – NobleUplift Jun 16 '16 at 00:26