Windows 64 bit or 32 bit preprocessor directives
Hi,
I want to connect to an SQL Server database using ADO with VC++.
In order to do that you need to import an external dll, like so:
#import "C:\\Program Files (x86)\\Common Files\\System\\ado\\msado15.dll"
What if the OS is not 64 bit? That would mean the (x86)-suffix would be incorrect.
Does anyone know how to work around this using certain preprocessor directives?
Something like this, maybe?:
#if 64bit
#import "C:\\Program Files (x86)\\Common Files\\System\\ado\\msado15.dll"
#else
#import "C:\\Program Files\\Common Files\\System\\ado\\msado15.dll"
#endif
Re: Windows 64 bit or 32 bit preprocessor directives
Just remove the path and let the compiler find it on its own.
http://support.microsoft.com/kb/169496
gg
Re: Windows 64 bit or 32 bit preprocessor directives
Re: Windows 64 bit or 32 bit preprocessor directives
but in case you have an actual code path that depends on 64 vs 32bit...
_M_X64 is defined for 64bit builds
_M_IX86 is defined for 32bit builds (the actual value will depend on what processor you're targetting)
_WIN64 is defined for Win64 builds
_WIN32 is defined for Win32 builds
the above is for Visual C++. Other compiler will have different macro's.
Re: Windows 64 bit or 32 bit preprocessor directives
>> the above is for Visual C++. Other compiler will have different macro's.
Indeed. Here is a good reference for several different compilers: http://sourceforge.net/p/predef/wiki/Home/
Those are generally for the target environment. There are no macro's for "what environment am I compiling on" in VC++, so it's best to let compiler options deal with import paths.
gg
Re: Windows 64 bit or 32 bit preprocessor directives
#import <msado15.dll>
does not work and the following error is generated
'fatal error C1083: Cannot open type library file: 'msado15.dll': No such file or directory'
Re: Windows 64 bit or 32 bit preprocessor directives
Quote:
Originally Posted by
danielmofo
#import <msado15.dll>
does not work and the following error is generated
'fatal error C1083: Cannot open type library file: 'msado15.dll': No such file or directory'
Read about The #import Directive and how it searchs for type library files...
Re: Windows 64 bit or 32 bit preprocessor directives
Ok, so do I need to add the following to Additional Include Directories to make it works for both 32 and 64 bit windows?
C:\Program Files (x86)\Common Files\System\ado
C:\Program Files\Common Files\System\ado
Will it also run on both 32 and 64 bit windows after compilation?
Re: Windows 64 bit or 32 bit preprocessor directives
The #import directive will take care of the required headers (in fact it generates one, the .tlh), so you never need to add anything to Additional Include Directories.
Re: Windows 64 bit or 32 bit preprocessor directives