【问题标题】:Defining a preprocessor directive for windows 7为 Windows 7 定义预处理器指令
【发布时间】:2012-08-21 09:37:12
【问题描述】:

我正在使用 SetDllDirectory() 并想知道如何为 Windows 7 HP 64 位定义一个指令,我在想这样的事情:

在预处理器指令中:

 Add WIN7

在 .cpp 中,我想添加类似

的内容
#ifndef WIN7<- where the function is used
SetDllDirectory();
#endif

但只要我添加语句,SetDllDirectory 就会被注释掉。

这是我尝试过的,我在预处理器定义中添加了 WIN7 并添加了:

#if defined(__WIN7__)
if (regkeyExists) {
    if (regkey->HasValue("LibPath")) {
        regkey->QueryValue("LibPath", value);
        if (!value.empty()) {
            wxSetEnv("ABCLib", value);
            SetDllDirectory(value.c_str());
        }
    }

}
SetDllDirectory("C:\\Program Files\\ABC\\ABCProject\\lib");
#endif

这是声明windows 7的权利吗

谢谢

【问题讨论】:

  • SetDllDirectory becomes commented. 你到底是什么意思
  • SetDllDirectory() 不存在了,其实我是在代码里面使用#语句

标签: c++ compiler-errors preprocessor-directive


【解决方案1】:

您不想定义自己的宏来检测 Windows 7,请使用 ones provided by Microsoft - 将您的仅限 Win7 的代码包装在:

#ifdef _WIN32_WINNT_WIN7 
xyz()
#endif

如果您创建自己的,则必须在要为 Windows 7 编译时定义它,似乎您隐藏了 SelDllDirectory() 函数 - #ifndef 表示“如果未定义”,因此如果 WIN7 宏没有在任何地方定义,然后您就可以获得该功能。

【讨论】:

  • 我已经尝试过这个东西,正如你所说的将代码放在 ifdef 中是否意味着将整个源文件放入其中?
  • @LindaHarrison - 您需要 C 预处理器的初学者指南。 eskimo.com/~scs/cclass/notes/sx9c.html
【解决方案2】:

【讨论】:

    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多