开发者

Use two different versions of a .lib file in one C++ project?

开发者 https://www.devze.com 2023-03-18 01:11 出处:网络
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 Window

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 cal开发者_StackOverflow社区l 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?


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消