Questions tagged [c++-cli]

C++/CLI is based on C++, modified to allow compilation of a mixture of native code and code for Microsoft's Common Language Infrastructure (CLI). It replaces Microsoft's Managed Extensions for C++, which aimed for stronger C++ conformance.

C++/CLI is a programming language based on C++ (ISO/IEC 14882:2003) which targets a mixed native+CLI platform. It was originally developed by Microsoft and supersedes "Managed Extensions for C++". It is formally standardized in Standard ECMA-372.

The Common Language Infrastructure (CLI) is a standardized specification for a runtime environment. Its principal implementation is Microsoft's .NET platform, but alternative implementations such as Mono exist. CLI executables are stored in bytecode in the "Common Intermediate Language" (CIL) that is run by a virtual machine and assembled by the "Intermediate Language Assembler" (ILASM).

There are multiple programming languages that emit pure CIL bytecode, for example C#. C++/CLI on the other hand can emit both native code (the C++-compatible parts of the program) and CLI code.

It has two distinct heaps, the familiar (native) C++ heap and the garbage-collected CLI heap. The language adds new features to properly deal with these two disparate concepts, while treating them as uniformly as possible. Both C++ pointers Foo * p and CLI references Bar ^ q are dereferenced the same way, *p = 1 / *q = 2 and p->f() / q->g().

C++/CLI compiles most standard C++ programs out of the box, while simultaneously opening up access to the very large CLI library.

6033 questions
231
votes
7 answers

What does the caret (‘^’) mean in C++/CLI?

I just came across this code and a few Google searches turn up no explanation of this mysterious (to me) syntax. Hashtable^ tempHash = gcnew Hashtable(iterators_); IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator(); What the heck does…
Owen
  • 6,853
  • 8
  • 36
  • 50
153
votes
4 answers

Change C++/CLI project to another framework than 4.0 with vs2010

Since I upgraded my project to visual studio 2010 project format, my C++/CLI project is targeted to .net framework 4.0. It is easy to switch the framework version to another version from a C# project, but I have no clue how to do this in a C++/CLI…
codymanix
  • 25,944
  • 18
  • 83
  • 142
100
votes
2 answers

Is the VC++ code DOM accessible from VS addons?

Visual Studio IntelliSense for VC++ includes the "complete" EDG C++ parser (also used by Intel and others). Since the C# Code DOM is accessible to addons (correct me if I'm wrong), is the C++ Code DOM also accessible? Can this be used to analyse an…
Robin Rodricks
  • 99,791
  • 133
  • 372
  • 575
94
votes
10 answers

C++/CLI Converting from System::String^ to std::string

Can someone please post a simple code that would convert, System::String^ To, C++ std::string I.e., I just want to assign the value of, String^ originalString; To, std::string newString;
sivabudh
  • 29,317
  • 56
  • 156
  • 219
93
votes
4 answers

When and why would you seal a class?

In C# and C++/CLI the keyword sealed (or NotInheritable in VB) is used to protect a class from any inheritance chance (the class will be non-inheritable). I know that one feature of object-oriented programming is inheritance and I feel that the use…
Aan
  • 10,547
  • 30
  • 78
  • 138
79
votes
7 answers

How can I make my managed NuGet package support C++/CLI projects?

I have made a NuGet package that works well when I use it from a C# project. It contains a DLL in the lib/net40 directory, and the DLL gets added as a reference. Now that NuGet supports C++, how do I actually modify my package so that the DLL can be…
Tor Hovland
  • 1,549
  • 2
  • 14
  • 23
70
votes
13 answers

Why C# is not allowing non-member functions like C++

C# will not allow to write non-member functions and every method should be part of a class. I was thinking this as a restriction in all CLI languages. But I was wrong and I found that C++/CLI supports non-member functions. When it is compiled,…
Navaneeth K N
  • 14,484
  • 33
  • 119
  • 177
69
votes
4 answers

How to initialize and print a std::wstring?

I had the code: std::string st = "SomeText"; ... std::cout << st; and that worked fine. But now my team wants to move to wstring. So I tried: std::wstring st = "SomeText"; ... std::cout << st; but this gave me a compilation error: Error 1 error…
Roee Gavirel
  • 17,192
  • 12
  • 58
  • 82
65
votes
4 answers

How do I call C++/CLI from C#?

I have a class implemented in C++ that's responsible for the arithmetic computation of the program, and an interface using WPF. I process the input with C# but then how can I use my C++ class? I've seen some comments about making a managed C++…
master chief
  • 751
  • 1
  • 7
  • 8
60
votes
3 answers

What is gcnew?

I stumbled across this code and am too proud to go and ask the author what it means. Hashtable^ tempHash = gcnew Hashtable(iterators_); IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator(); What is gcnew and how important is it to use…
Owen
  • 6,853
  • 8
  • 36
  • 50
60
votes
8 answers

C++/CLI: why should I use it?

I'm pretty familiar with C++, so I considered learning .NET and all its derivatives (especially C#). Along the way I bumped into C++/CLI, and I want to know if there is any specific use for that language? Is it just suppose to be a intermediate…
Idan
  • 5,487
  • 9
  • 45
  • 82
56
votes
6 answers

How to call a C# library from Native C++ (using C++\CLI and IJW)

Background: As part of a larger assignment I need to make a C# library accessible to unmanaged C++ and C code. In an attempt to answer this question myself I have been learning C++/CLI the past few days/ weeks. There seems to be a number of…
amalgamate
  • 2,000
  • 5
  • 20
  • 37
52
votes
8 answers

Calling C# code from C++

I need to be able to invoke arbitrary C# functions from C++. http://www.infoq.com/articles/in-process-java-net-integration suggests using ICLRRuntimeHost::ExecuteInDefaultAppDomain() but this only allows me to invoke methods having this format: int…
Gili
  • 76,473
  • 85
  • 341
  • 624
52
votes
4 answers

Any reason to prefer CefSharp over CefGlue (or vice-versa)?

In the realm of providing a decent implementation of the Chromium Embedded Framework (CEF) for .Net, the two leading options appear to be CefSharp and CefGlue. They differ in approach (CefGlue uses P/Invoke to call into the CEF unmanaged code,…
Drew Shafer
  • 4,520
  • 4
  • 28
  • 40
51
votes
7 answers

No IntelliSense for C++/CLI in Visual Studio 2010?

I just moved from Visual Studio 2008 to Visual Studio 2010 (final) and noticed one major flaw: When I try to use AutoComplete in a C++ source file for managed C++, a small note in the footer appears: IntelliSense for C++/CLI is not available Uh, has…
Sam
  • 26,538
  • 45
  • 157
  • 240
1
2 3
99 100