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
51
votes
5 answers

Documenting C++/CLI library code for use from c# - best tools and practices?

I'm working on a project where a c++/cli library is being used primarily from a c# application. Is there any way to make the code comments in c++/cli visible to c# intellisence within visual studio? Assuming there isn't, what would be the best way…
Hrvoje Prgeša
  • 2,021
  • 5
  • 21
  • 36
49
votes
3 answers

In C++/CLI, how do I declare and call a function with an 'out' parameter?

I have a function which parses one string into two strings. In C# I would declare it like this: void ParseQuery(string toParse, out string search, out string sort) { ... } and I'd call it like this: string searchOutput,…
Simon
  • 24,010
  • 36
  • 139
  • 249
46
votes
5 answers

Using C++ Class DLL in C# Application

I have an unmanaged C++ DLL which merely exports a single class (not COM...it's just a simple C++ class) as its interface. I want to use this class in C# but am told that it cannot merely be imported into C#. What is the right way to use this class…
cjserio
  • 2,747
  • 7
  • 26
  • 29
45
votes
3 answers

In C++/CLI, what does the hat character ^ do?

I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main: int main(array ^args) I went back, page by page, to the beginning of the book to find the first such instance with…
Tuminoid
  • 8,635
  • 7
  • 34
  • 50
44
votes
5 answers

What is the best way to convert between char* and System::String in C++/CLI

What is the approved way to convert from char* to System::string and back in C++/CLI? I found a few references to marshal_to<> templated functions on Google, but it appears that this feature never made the cut for Visual Studio 2005 (and isn't in…
Brian Stewart
  • 8,647
  • 11
  • 49
  • 65
42
votes
1 answer

How to use Nullable types in c++/cli?

I have the following code, which I thought would work: property Nullable Angle { Nullable get() { return nullptr; } } It doesn't. How can I do it? Does c++/CLI even support nullable types?
devoured elysium
  • 90,453
  • 117
  • 313
  • 521
37
votes
2 answers

What is app.aps file in Visual C++?

I just discovered a misterious file in my (new) Visual Studio 2012 C++/CLI project: app.aps. I can find no reference on the internet about it. What is it meant for? Can I safely delete it? It seems so. Should I ignore or include in my commits to…
bluish
  • 23,093
  • 23
  • 110
  • 171
37
votes
6 answers

P/Invoke or C++/CLI for wrapping a C library

Have a moderate size (40-odd function) C API that needs to be called from a C# project. The functions logically break up to form a few classes that will be API presented to the rest of the project. Are there any objective reasons to prefer P/Invoke…
Ian G
  • 9,739
  • 5
  • 27
  • 33
37
votes
6 answers

Windows Phone 7 and native C++/CLI

Microsoft recently released tools and documentation for its new Phone 7 platform, which to the dismay of those who have a big C++ codebase (like me) doesn't support native development anymore. Although I've found speculation about this decision…
Fabio Ceconello
  • 15,049
  • 5
  • 34
  • 49
36
votes
1 answer

C++/CLI wrapper for native C++ to use as reference in C#

Title explains. I have native C++ dlls that I'm writing C++/CLI wrappers for, which will in turn will be imported in C# as reference. The problem is that in C# I don't see the classes I have in wrapper (imported from DLL). What keywords should I use…
Haix64
  • 748
  • 1
  • 12
  • 20
35
votes
1 answer

Implementing an interface declared in C# from C++/CLI

Say I have a C# interface called IMyInterface defined as follows: // C# code public interface IMyInterface { void Foo(string value); string MyProperty { get; } } Assume I also have a C++/CLI class, MyConcreteClass, that implements this…
Simon Brangwin
  • 841
  • 1
  • 7
  • 15
34
votes
2 answers

How to use LINQ in C++/CLI - in VS 2010/.Net 4.0

Just wondering if there is a way to use LINQ in C++/CLI. I found one post that was focused on VS 2008 and required a bunch of workarounds for the System::String class. I have seen some framework replacements on CodeProject, but I was wondering if…
pstrjds
  • 15,103
  • 6
  • 48
  • 60
34
votes
7 answers

Why is "array" marked as a reserved word in Visual-C++?

Visual Studio syntax highlighting colors this word blue as if it were a keyword or reserved word. I tried searching online for it but the word "array" throws the search off, I get mostly pages explaining what an array is. What is it used for?
CS student
  • 411
  • 1
  • 6
  • 11
34
votes
7 answers

Does Mono .NET support and compile C++ / CLI?

Does Mono .NET support and compile C++ / CLI? If not, do you know if they have any plans of supporting it?
Brian R. Bondy
  • 314,085
  • 114
  • 576
  • 619
33
votes
4 answers

debugging in mixed mode with native C++, managed c++ cli, and c# solution

I have a multithreaded project im working on and the startup project is set to a c# project that runs my UI. Then there is a whole series of underlying c++ native projects which are connected to the C# by managed C++/CLI projects. I've enabled in…
jamie
  • 331
  • 1
  • 3
  • 3