如何使用C#预处理器指令查找在64BitOperatingSystem上运行的32BitProcess
为了获得更多信息,我需要声明dll名称(基于位)来访问外部函数。我需要以下代码使用预处理器的方式。
public String WABDll;
if (64Bit)
{
WABDll = "Win-64.dll";
}
else if(32Bit Process on 64BitOS)
{
WABDll = "Win-32on64.dll";
}
else if(32Bit)
{
WABDll = "Win-32.dll";
}我尝试了下面的方法
#if _64BIT
public const String WABDll = "Win-64.dll";
#elif _32BIT
public const String WABDll = "Win-32on64.dll";
#else
public const String WABDll = "Win-32.dll";
#endif有什么建议吗。
发布于 2013-06-06 13:17:13
不要使用预处理器指令这样做;在运行时使用the Environment class确定环境。Is64BitOperatingSystem和Is64BitProcess属性应该为您提供所需的信息。
发布于 2013-06-06 13:16:08
你不能解决这个问题:
else if(32Bit Process on 64BitOS)
{
WABDll = "Win-32on64.dll";
}编译时间,因为编译器事先不知道程序将在哪里运行。我可以建议你创建更多的解决方案"paltform",声明一些自定义的编译器标志,并相应地使用它们。当然,您需要知道部署时间,哪些可执行文件必须在哪个平台上运行。
https://stackoverflow.com/questions/16954065
复制相似问题