在 Visual Studio 2008 中,是否有标识 64 位 Windows 操作系统的宏?

发布于 2024-10-10 11:44:48 字数 855 浏览 5 评论 0原文

问题是:

为了为我的 32 位程序导入正确版本的 ADO,我需要知道我是在 32 位 Windows 操作系统(意味着该文件位于 Program Files 中)还是 64 位操作系统上进行编译。位操作系统(意味着该文件位于 Program Files (x86) 中)。但我找不到告诉我这一点的宏,甚至找不到告诉我处理器是 64 位的宏。

当我在运行 Visual Studio 2008 Express 的 64 位 Windows 7 上测试它时,定义了以下相关宏:

_M_IX86
X86

但是似乎没有定义任何 *64 宏,我想如果它们引用的是 /target/ 体系结构而不是当前机器的体系结构,情况就会如此。

是否有一个预处理器宏可以告诉我是否正在运行 64 位 Windows 操作系统?

如果是,它是什么?我什至愿意选择一个能够告诉我是否使用 64 位处理器的工具。

(ps我已经知道此列表)

更新

到目前为止,人们似乎认为没有这样的宏,复制 DLL 或使用环境变量是更好的做法。

因此,根据环境变量提示,我通过将两个文件夹——Program Files (x86) 和 Program Files——放在包含路径上并使用 #import 的尖括号语法,为开发人员解决了这个问题。但是,我怀疑我需要为每个版本的操作系统构建发布版本,因为 ADO DLL 现在是操作系统的一部分并且不可重新分发。对此进行调查。

Here's the problem:

In order to #import the correct version of ADO for my 32-bit program, I need to know whether I'm compiling on a 32-bit Windows OS (meaning the file is in Program Files) or a 64-bit OS (meaning the file is in Program Files (x86)). But I can't find a macro that tells me this, or even a macro that tells me that the processor is 64-bit.

When I test it on 64-bit windows 7 running Visual Studio 2008 Express, the following pertinent macros are defined:

_M_IX86
X86

But none of the *64 macros appear to be defined, which I suppose would be the case if they are referring to /target/ architectures and not the current machine's architecture.

Is there a preprocessor macro that will tell me whether I am running a 64-bit Windows OS?

And if so, what is it? I'd even settle for one that will tell me whether I'm using a 64-bit processor.

(p.s. I am already aware of this list)

Update

So far, people seem to think that there is no such macro, and copying the DLLs or using environment variables is a better thing to do.

So taking the environment variable hint, I have worked around the problem for developers by putting both folders -- Program Files (x86) and Program Files -- on the include path and using the angle-bracket syntax of #import. However, I suspect that I will need to build release versions for each version of the OS because the ADO DLLs are now part of the OS and are not redistributable. Looking into that.

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

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

发布评论

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

评论(3

南渊 2024-10-17 11:44:48

检查这一点:_WIN64

此处描述:

http://msdn.microsoft.com/en -us/magazine/cc300794.aspx

我使用这个并且它有效。

您的情况更加复杂,因为您想了解操作系统而不是编译类型。我一直使用 Windows x64,但我同时编译 32 位和 64 位应用程序。 _WIN64 仅在我编译 64 位应用程序时定义,而不是在编译 32 位应用程序时定义,即使我始终在 Windows x64 计算机上。

我认为你应该以不同的方式设置包含目录来隐藏这种复杂性。最好假设包含目录在不同的机器上会有很大差异,因此从长远来看,使路径检测完全自动化可能过于聪明,不利于您自己。

Check for this: _WIN64

Described here:

http://msdn.microsoft.com/en-us/magazine/cc300794.aspx

I use this and it works.

Your situation is more complex in that you want to know the OS rather than the type of compilation. I use Windows x64 all the time but I compile both 32 bit and 64 bit applications. _WIN64 is only defined when I am compiling a 64 bit application and not when I am compiling a 32 bit application even though I am always on a Windows x64 machine.

I think you should just set up your include directories differently to hide this complexity. It is good to assume that include directories will vary widely across different machines, thus making the path detection fully automated is likely trying to be too smart for your own good in the long run.

美胚控场 2024-10-17 11:44:48

我不知道宏,但您可以使用环境变量 PROCESSOR_ARCHITECTURE。请注意,您可以使用 $(PROCESSOR_ARCHITECTURE) 表示法从 Visual Studio 设置对话框访问环境变量。

此外,针对您的情况的解决方法是定义一个环境变量(例如 ADO_LIB_DIR),将其设置为正确的程序文件目录,然后导入 lib 或添加包含目录,并使用 $(ADO_LIB_DIR) 变量的表示法。这样,当您在新机器上编译时,您所要做的就是设置环境变量。

更新:我看到还有 $(ProgramFiles) 和 $(ProgramFiles(x86)) 环境变量,所以你最好的选择可能是使用它们。

I'm not aware of a macro, but you can use the environment variable PROCESSOR_ARCHITECTURE. Note you can access environment variables from visual studio settings dialog boxes by using the $(PROCESSOR_ARCHITECTURE) notation.

Also, a workaround for your case would be to define an environment variable such as ADO_LIB_DIR, set it to the correct program files directory, and then import the lib or add an include directory with a notation that uses the $(ADO_LIB_DIR) variable. This way all you will have to do when you compile on a new machine is to set the environment variable.

Update: I see there are also $(ProgramFiles) and $(ProgramFiles(x86)) environment variables, so your best bet is probably to use them.

猫腻 2024-10-17 11:44:48

我也遇到了同样的问题,但不仅是 ado,还有其他库(ESRI)。所以解决方案如下:
在项目设置中-> C/C++->预处理器-> “预处理器定义”:添加了以下文本: COMPILATION_PLATFORM=$(PROCESSOR_ARCHITECTURE)

在代码中我可以做出决定,只是一个示例,它是如何工作的:

#if ((COMPILATION_PLATFORM == AMD64) && (_WIN64))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS64, Generated code = x64 (64bit)" )
#elif ((COMPILATION_PLATFORM == AMD64) && (_WIN32))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS64, Generated code = x86 (32bit)" )
#elif ((COMPILATION_PLATFORM == x86) && (_WIN64))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS32, Generated code = x64 (64bit)" )
#elif ((COMPILATION_PLATFORM == x86) && (_WIN32))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS32, Generated code = x86 (32bit)" )
#endif

我希望它可以帮助您。
马雷克

I had the same problem, but not only with ado, but also with other libraries (ESRI). So the solution was the following:
In Project Setting -> C/C++ -> Preprocessor -> "Preprocessor Definitions": Added following text: COMPILATION_PLATFORM=$(PROCESSOR_ARCHITECTURE)

And in code I can make a decision just an example how it works:

#if ((COMPILATION_PLATFORM == AMD64) && (_WIN64))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS64, Generated code = x64 (64bit)" )
#elif ((COMPILATION_PLATFORM == AMD64) && (_WIN32))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS64, Generated code = x86 (32bit)" )
#elif ((COMPILATION_PLATFORM == x86) && (_WIN64))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS32, Generated code = x64 (64bit)" )
#elif ((COMPILATION_PLATFORM == x86) && (_WIN32))
#pragma message( "StdAfx.cpp  >> COMPILATION HOST IS RUNNING on WINDOWS32, Generated code = x86 (32bit)" )
#endif

I hope it could help you.
Marek

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