gpt4 book ai didi

c++ - 在cpp文件中用#pragma指定延迟加载dll

转载 作者:可可西里 更新时间:2023-11-01 18:37:51 46 4
gpt4 key购买 nike

我有一个静态链接库,它使用我需要延迟加载的 dll 中的一些函数。因此,在我的可执行文件的属性中,我在 Linker/Input/Delay Loaded DLLs 下添加了这个 dll。我无法在库本身中添加此选项,因为它没有 Linker 属性页(因为它是静态库)
所以现在每当我在另一个可执行工具中使用这个库时,我都需要一遍又一遍地添加延迟加载选项,我想避免这种情况。我知道曾经有一个 pragma 用于此

#pragma comment(linker, "/DELAYLOAD:mydll.dll")

但是它对我不起作用,因为它说

warning LNK4229: invalid directive '/DELAYLOAD:mydll.dll' encountered; ignored

除了LoadLibrary,还有别的出路吗?

最佳答案

在谷歌上做了一些研究(你猜),因为我一直对这些事情很感兴趣。明显的链接是:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/807606af-f7d7-4d9b-a9f3-062b23fddb2b/using-the-delayload-linker-switch-with-a-custom-dll

不幸的是,它是从 2004 年开始的,那是九年之前的一些 VS 版本。

但它变得更糟,我还发现了这个:

http://bytes.com/topic/net/answers/280580-delayload-pragma-fixed-whidbey

晚了一年,听起来很合理:

No, this never worked reliably. It was a bug to allow it in 6.0. One that we fixed later by adding the warning.

Ronald Laeremans

Visual C++ team

我知道,除了你的三个建议之外,别无他法。

关于c++ - 在cpp文件中用#pragma指定延迟加载dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18659208/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com