C # preprocessor directive ignored in Visusal Studio 2010 Express?

I have a section of code loaded from codeProject .

The #if preprocessor #if does not work, as if I expected it to work.

I did not define DSHOWNET in MyProject -> Properties -> Assembly Tab -> Conditional Compilation Symbols (dialog box is empty)

In the code below, when creating a project, a DShowNET error is displayed. Since DSHOWNET has never been detected, I am surprised that "using DShowNET" is even handled.

 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 Visual Studio Express? Should DSHOWNET be explicitly "undefined"? Or did I miss some other basic concept?

+4
source share
1 answer

I downloaded the sample grabber project and put it into my system. (I am using Enterprise VS.) I opened the CaptureTest-2005 solution, converted it to the VS2010 solution, and downloaded it. After downloading the CaptureTest-2005 solution, I still saw the files that had the same problem as you.

So, I found that although the CaptureTest-2005 project did not have the DSHOWNET defined on the build page, the DirectX.Capture-2005 project did. Thus, for all files in DirectX.Capture-2005 DSHOWNET directive is evaluated as true and, therefore, elements inside the #if DSHOWNET directives are #if DSHOWNET .

I'm not sure the solution just requires you to build and use the DSHOWNET part of CodeProject's download (for example, I'm not sure if DirectX.Capture is DirectX.Capture ), but I suppose, since the DirectX.Capture project determined that you would need to create and use this assembly to run the project. (Perhaps there is a way around this, I havenโ€™t gone that far. I would recommend checking the project page to see if there is information about what depends on it.)

Hope this helps!

+5
source

All Articles