C + + calls different dynamic-link libraries based on the operating system version

Source: Internet
Author: User

a problem was encountered when manipulating the database: Win7 SP1 on the Win7 SP1 the following versions of the ADO program are not running . (The dynamic file required under the WIN7 system is not the same as the dynamic link library required by the XP system.) dynamic-link libraries need to be loaded based on the version of the system. )

Under the Win7 system:

Required dynamic-link libraries

#import "MSADO15. DLL "rename_namespace (" Adowe ") Rename (" EOF "," Endoffile ")

Win XP under

#import "Msado60.tlb" Rename_namespace ("Adowe") Rename ("EOF", "adoeof")


Add the following statement before defining the class to implement versioning:

#if ((_win32_winnt) = = (_WIN32_WINNT_WINXP))
#import "Msado60.tlb" rename_namespace ("Adowe") rename ("EOF", "adoeof")
#elif ((_win32_winnt) = = (_win32_winnt_win7))
#import "MSADO15. DLL "rename_namespace (" Adowe ")
#endif


So that the program can be copied from the Win7 system into the XP system can open the database normally.



To test version control directives in the console environment:

#include <windows.h>
#include <iostream>
using namespace Std;




#if ((_win32_winnt) = = (_WIN32_WINNT_WINXP))
int version=1; //precompilation defines a global variable outside of precompilation and then assigns a value in the precompiled statement//. Assigning values to variables occurs during the compilation process, and precompilation is just a simple replacement.
#elif ((_win32_winnt) = = (_win32_winnt_win7))
int version=2;
#else
int version=3;
#endif
/*

Error wording:

int Version;

#if ((_win32_winnt) = = (_WIN32_WINNT_WINXP)) BR style= "font-size:24px" > version=1; //Unrecognized version   type   causes the global variable in the program to always be 0.
#elif ((_win32_winnt) = = (_WIN32_ winnt_win7))
version=2; //unrecognized version   type
#else
VERSION=3; //unrecognized version   type
#endif

*/

void Main ()
{
if (version==1)
cout<< "Window xp!" <<endl;
else if (version==2)
cout<< "Window 7" <<endl;
Else
cout<< "Undefined operating system" <<endl;

}


Running the program output under the Win7 system: Window 7



C + + calls different dynamic-link libraries based on the operating system version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.