简体   繁体   English

Visusal Studio 2010 Express 中忽略了 C# 预处理器指令?

[英]C# preprocessor directive ignored in Visusal Studio 2010 Express?

I have a section of code downloaded from codeProject .我从codeProject下载了一段代码。

The #if preprocessor directive doesn't appear to work like I would have expected it to work. #if预处理器指令似乎不像我预期的那样工作。

I have not defined DSHOWNET in MyProject >> Properties >> Build Tab >> Conditional compilation symbols (the dialog box is empty)我没有在 MyProject >> 属性 >> 构建选项卡 >> 条件编译符号中定义 DSHOWNET(对话框为空)

In the code below, an error DShowNET could not be found is shown when the project is built.在下面的代码中,在构建项目时会显示错误DShowNET could not be found Since DSHOWNET was never defined, I'm surprised that the 'using DShowNET' is even processed.由于 DSHOWNET 从未被定义,我很惊讶“使用 DShowNET”甚至被处理了。

using System;
using System.Collections;
using System.Runtime.InteropServices;
#if DSHOWNET
using DShowNET;
using DShowNET.Device;
#else
#if VS2003
#else
using System.Runtime.InteropServices.ComTypes;
#endif
using DirectShowLib;
#endif

Does the #if preprocessor directive work in the Visual Studio Express version? #if 预处理器指令是否适用于 Visual Studio Express 版本? Does DSHOWNET need to be explicitly 'undefined'? DSHOWNET 是否需要明确“未定义”? Or am I missing some other basic concept?还是我错过了其他一些基本概念?

I downloaded the sample grabber project and put it on my system.我下载了示例抓取器项目并将其放在我的系统上。 (I am using the Enterprise VS.) I opened the CaptureTest-2005 solution, converted it to a VS2010 solution, and loaded it. (我使用的是 Enterprise VS。)我打开CaptureTest-2005解决方案,将其转换为 VS2010 解决方案,然后加载它。 Upon loading the CaptureTest-2005 solution, I still saw files that had the same issue as you are seeing.加载CaptureTest-2005解决方案后,我仍然看到与您看到的问题相同的文件。

So, what I found was that, although the CaptureTest-2005 project did not have DSHOWNET defined on the Build page, the DirectX.Capture-2005 project did.所以,我发现,虽然CaptureTest-2005项目没有在 Build 页面上定义DSHOWNET ,但DirectX.Capture-2005项目却有。 So, for all the files in DirectX.Capture-2005 , the DSHOWNET directive evaluated to true, and thus the items inside the #if DSHOWNET directives were being processed.因此,对于DirectX.Capture-2005中的所有文件, DSHOWNET指令评估为真,因此正在处理#if DSHOWNET指令中的项目。

I am not sure whether the solution just requires that you build and use the DSHOWNET part of the CodeProject download, (eg I'm not sure whether DirectX.Capture is required) but I imagine, since the DirectX.Capture project has it defined, that you will have to build and use that assembly to run the project.我不确定该解决方案是否只需要您构建和使用 CodeProject 下载的DSHOWNET部分(例如,我不确定是否需要DirectX.Capture )但我想,因为DirectX.Capture项目已经定义了它,您将必须构建并使用该程序集来运行该项目。 (There may be a way around it, I have not gone that far into it. I would recommend checking the project page to see if there's information about what depends on what.) (可能有办法解决它,我还没有深入研究。我建议检查项目页面,看看是否有关于什么取决于什么的信息。)

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM