Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find programmatically if under C++ or C++/CLI

I would like my C++/CLI headers to compile even when under another platform. Of course I am not expecting to compile them but just ignore them.

Would this be appropriate ? (_MSC_VER)

#ifdef _MSC_VER

    using namespace System;

        namespace ENMFP {

            public ref struct Data {
            };
        }

#endif

Thanks !

like image 994
aybe Avatar asked Apr 02 '12 12:04

aybe


People also ask

What is CLR in Visual C++?

The Common Language Runtime (CLR), the virtual machine component of Microsoft . NET Framework, manages the execution of . NET programs. Just-in-time compilation converts the managed code (compiled intermediate language code) into machine instructions which are then executed on the CPU of the computer.

Does .NET include C++?

The . NET framework can work with several programming languages such as C#, VB.NET, C++ and F#.

How do I enable CLR in Visual Studio?

In the Visual Studio IDE, the /clr compiler option can be individually set on the Configuration Properties > C/C++ > General page of the Property Pages dialog.

How do I create a CLR project in Visual Studio 2022?

To create a CLR console app projectOn the menu bar, choose File > New > Project. In the New Project dialog box, select the Installed > Templates > Visual C++ > CLR node, and then select the CLR Console Application template.


1 Answers

You can use the __cplusplus_cli predefined macro documented here:

#ifdef __cplusplus_cli

using namespace System;

namespace ENMFP
{
    public ref struct Data
    {
        // ...
    };
}

#endif  // __cplusplus_cli
like image 159
Frédéric Hamidi Avatar answered Oct 18 '22 23:10

Frédéric Hamidi