如何对导出 C++ 类的 DLL 使用延迟加载

How to use delay loading with a DLL that exports C++ classes(如何对导出 C++ 类的 DLL 使用延迟加载)

本文介绍了如何对导出 C++ 类的 DLL 使用延迟加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DLL one.dll,它使用通过 class __declspec(dllexport) 从 two.dll 导出的类 TwoClass.我希望 one.dll/delayload 用于 two.dll,但出现链接错误:

I have a DLL one.dll that uses a class TwoClass exported from two.dll via class __declspec(dllexport). I'd like one.dll to use /delayload for two.dll, but I get a link error:

LINK : fatal error LNK1194: cannot delay-load 'two.dll' due to import
of data symbol '"__declspec(dllimport) const TwoClass::`vftable'"
(__imp_??_7TwoClass@@6B@)'; link without /DELAYLOAD:two.dll

这是在发布版本中;在调试版本中它可以工作.(我不知道 Release 和 Debug 在 vtable 导出方面有什么区别,也找不到任何编译器开关或 pragma 来控制它.)

That's in a Release build; in a Debug build it works. (I don't know what the difference is between Release and Debug in terms of vtable exports, nor can I find any compiler switches or pragmas to control it.)

如何将 /delayload 与在发布版本中导出此类的 DLL 一起使用?

How can I use /delayload with a DLL that exports classes like this in a Release build?

推荐答案

看看 这里,看来此人遇到了完全相同的问题并找到了解决方法

Have a look here, seems that the person had exactly the same problem and found a workaround

我设法延迟加载通过禁用对发布版本的优化来工作使用 SomeClass 类的翻译单元 - 不知何故它带走了对导出的 vtable 的依赖.

I managed to get the delay loading to work in release build by disabling the optimizations on the translation unit that was using SomeClass class - somehow it took away the dependency on exported vtable.

这篇关于如何对导出 C++ 类的 DLL 使用延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何对导出 C++ 类的 DLL 使用延迟加载

基础教程推荐