在一个 C++ 中使用 .lib 文件的两个不同版本项目?

发布于 2024-11-18 17:00:50 字数 509 浏览 8 评论 0原文

我正在开发卷影复制程序。我刚刚发现我需要使用一组不同的 .h 文件 (vsbackup.h) 和关联的 .lib 文件 (vssapi.lib) 来编译 Windows XP 项目(与 Vista 和 7 相比)。这是由于 .h 文件中的一系列细微变化造成的:在 XP 中,诸如 CreateVssBackupComponents() 之类的调用是对 API 的调用(只有 vsbackup.h 中的声明);最近的 vsbackup.h 将其更改为 CreateVssBackupComponents() { CreateVssBackupComponentsInternal();当我使用较新的 .h 和 .lib 文件编译我的项目并在 XP 下运行该程序时,它说

在 DLL“vssapi.dll”中找不到过程入口点“CreateVssBackupComponentsInternal”。

是否有可能将这两个不同的 lib 文件合并到一个项目中,这样我就不必编译该程序的两个不同版本?

I'm working on a Volume Shadow Copy program. I have just found out that I need to use a different set of .h files (vsbackup.h) and associated .lib files (vssapi.lib) to compile the project for Windows XP (in comparison to Vista and 7). This is due to a series of subtle changes in the .h files: in XP, a call such as CreateVssBackupComponents() was a call into the API (there was only the declaration in vsbackup.h); the more recent vsbackup.h changes this into CreateVssBackupComponents() { CreateVssBackupComponentsInternal(); } and when I compile my project with the newer .h and .lib files and run the program under XP, it says

The procedure entry point "CreateVssBackupComponentsInternal" was not found in DLL "vssapi.dll".

Is there any possibility to incorporate these two different lib files in one project, so that I don't have to compile two different versions of the program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

〗斷ホ乔殘χμё〖 2024-11-25 17:00:50

如果您需要使用两个不同版本的 dll(因为如果我理解正确的话,问题就在那里,不同的 lib/标头只是冰山一角),您应该使用 LoadLibrary 动态加载它,使用 GetProcAddress 检查您需要的入口点是否存在,并使用它返回的函数指针调用您需要的函数。

If you need to work with two different versions of the dll (because if I understood correctly the problem lies there, the different lib/headers are just the tip of the iceberg) you should dynamically load it with LoadLibrary, check the presence of the entrypoints you need with GetProcAddress and call the functions you need with the function pointer that it returned.

素染倾城色 2024-11-25 17:00:50

您还可以创建两种项目配置,一种用于 XP,另一种用于较新的 Windows 版本。然后将这两个文件添加到安装程序中,让安装程序检查安装的 Windows 版本并选择正确的程序版本。
(这基本上就是我遇到你的问题时所做的)

更合适的解决方案是将其放入 DLL 中,创建该 DLL 的两个版本,然后运行时检查并加载正确的 DLL。这样 Windows 更新就不会造成问题。

You can also create two project configurations one for XP and one for newer Windows versions. Then add both files to your installer and let the installer check which Windows version it is installing at and select the right version of your program.
(That's basically what I did when I had your problem)

The more proper solution though would be putting it in a DLL, create two versions of that DLL and then runtime check and load the right DLL. That way a Windows update wouldn't cause problems.

忱杏 2024-11-25 17:00:50

就个人而言,当库开始变得有点/疯狂/时,我开始考虑为有问题的库提供自己的进程,并使用某种 RPC 与它们交互。

Personally, when libraries start to get a bit /crazy/, I start looking into giving the problematic libraries their own process, and use some sort of RPC to interact with them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文