CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2012
    Posts
    6

    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

  2. #2
    Join Date
    Nov 2003
    Posts
    1,902

    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

  3. #3
    Join Date
    Aug 2012
    Posts
    6

    Re: Windows 64 bit or 32 bit preprocessor directives

    thnx

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    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.

  5. #5
    Join Date
    Nov 2003
    Posts
    1,902

    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

  6. #6
    Join Date
    Aug 2012
    Posts
    6

    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'

  7. #7
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Windows 64 bit or 32 bit preprocessor directives

    Quote Originally Posted by danielmofo View Post
    #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...
    Victor Nijegorodov

  8. #8
    Join Date
    Aug 2012
    Posts
    6

    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?
    Last edited by danielmofo; July 17th, 2013 at 05:06 AM.

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    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.
    Best regards,
    Igor

  10. #10
    Join Date
    Aug 2012
    Posts
    6

    Re: Windows 64 bit or 32 bit preprocessor directives

    Also when using angle-bracket-form?

    http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx
    says it does

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured