c++-cli

What is the difference between ANSI/ISO C++ and C++/CLI?

Created by Microsoft as the foundation of its .NET technology, the Common Language Infrastructure (CLI) is an ECMA standard (ECMA-335) that allows applications to be written in a variety of high-level programming languages and executed in different system environments. Programming languages that conform to the CLI have ...

Loading interdependent assemblies from C++/CLI

Hi. I want to load two assemblies from C++/CLI; assembly A depends on assembly B, and both are VB.Net projects (3.5). I want them to load from a byte array, so I use Assembly::Load(), but when I try to instantiate a class from assembly A, the framework ignores the previously loaded assembly B and attempts to load it again, which fails be...

CLI/C++ Converting "this" pointer to an integer

I am trying to trace managed object creation/disposing in a CLI/C++ prog: ::System::Diagnostics::Trace::WriteLine(String::Format( "Created {0} #{1:X8}", this->GetType()->Name, ((UInt64)this).ToString())); Which fails with error C2440: 'type cast' : cannot convert from 'MyType ^const ' to 'unsigned __int64' Is there a wa...

Embedding resource in a C++/CLI project

Hello. I'd like to embed some files (text files, maybe graphics) in a C++/CLI project -- preferably the same way I can do in C# project. This might be however impossible, as I found in this post: http://bytes.com/topic/net/answers/571530-loading-markup-xamlreader-load-resource-file#post2240705. This was written three years ago, so maybe...

Faster to Compare by Name or Type?

When performing an object comparison, is it faster to compare by name (string) or type (pointer)? See below: if(sender is DataGridView) { .. } or if(sender.GetType().ToString() == "System.Forms.DataGridView") { .. } Note: I may not have the syntax exactly right... this is a C# example, but the comment answer here in one my questi...

Cast native pointer to a C++\CLI manged object reference?

hi, I have a callback that is called through a delegate. Inside it I will need to treat the buffer data that arrive from a record procedure. Normaly in a unmanaged context I could do a reinterpret_cast on dwParam1 to get the object reference. But in a manged context how can I cast a DWORD_PTR to a managed object ref? static void Wav...

pin_ptr performance relative to native (VC) heap objects

In a C# to native lib CLI/C++ wrapper, I have a choice: Store native pointer in a managed class (native object is created using native "new") or Store native object as a data blob in a managed class' field, and use pin_ptr to pin it before each native use. Has anyone done any comparative analysis on the relative performance costs...

Is there an equivalent to the C# "var" keyword in C++/CLI ?

In C#, I like the var keyword for situations like this: var myList = new List<MyType>(); Is there any equivalent in C++/CLI, or do I have to repeat the type name everytime just like this: List<MyType ^>^ myList = gcnew List<MyType ^>(); Could not find an explicit statement in the docs or by Google so far. I am using Visual Studio 2...

Catch a C Runtime Library fatal error in (mixed) .NET code?

I have a project that consists of a C# application that calls into a couple of C++/CLI DLLs. If I have a Visual Studio C Runtime Library fatal error in the native code, there appears to be no way to catch it. To give a simple example, if I put this in the native code: wchar_t buf[1]; ::wcscpy_s(buf, 1, L"ab"); The app wil...

How to use C++/CLI to program Winforms applications

Is there a pdf or video or some media that can inform me on how to program Winforms with C++. Obviously C++ is the most common programming language and I already have some prior knowledge. But when I try to find media about programming in C++, the examples are usually Console applications. I want some media that can teach me how to progr...

issue regarding overloading in VS2008 C++/CLI

I have written a class for managing GPU memory buffers. I've got one method for building a buffer initialized with a chunk of CPU memory (if pData is null, then allocated block of GPU memory is not initialized, remaining with indeterminate values) and an overload for building it initialized with the same byte value: IBuffer* CreateBuff...

How to simulate a member reference tracking variable in C++/CLI?

This is going to be a really goofy question but is it possible to do the following in C++/CLI? // C++/CLI public ref class Managed { public: array<double>^ m_data; Managed(array<double>^% data) : m_data(data) { } void bar(int x) { System::Array::Resize(m_data, x); ...

Emulating pass by ref in C++/CLI without using tracking reference (%)?

I want to emulate the following method: ref class Something{ void foo(array<double>^% data) { data = gcnew array<double>(10); } }; Such that, the caller's array gets modified/created. Nevertheless, there are some constrains: foo cannot use ref/out/% nor any additional parameters. the actual parameter of foo has to be ...

Changing foreach iteration variable and implementation differences between C# and C++/CLI

Consider the following C# code. string[] stringArray = new string[10]; foreach (string s in stringArray) s = "a new string"; // Compiler error - Can't assign to foreach iteration variable Now consider the following valid C++/CLI code. array<String^>^ stringArray = gcnew array<String^>(10); for each(String^% s in stringArray) ...

How to debug and solve a 'DisconnectedContext' crash?

I have a GUI app which connects to a sensor, gathers data and processes it in the background using BackgroundWorker threads. As it stands I'm posting data to the GUI using the ProgressChanged which seemed to be working well to begin with. I've since upped the data rates and have discovered a problem; if the software is left to run for a...

How do I create a CLI value class containing a List (or similar) which is passed by value?

We have a C++ library which uses a struct containing an STL vector of structs, like so: struct Params { // values... } struct Settings { std::vector<Params> m_params; // values... } I'm writing a CLI wrapper for the library, and I want equivalents for the above struct types. I had been thinking about using a List as the...

...array<Object^>^ args

I'm reading C++/CLI. I see this stuff: Object^ CreateInstanceFromTypename(String^ type, ...array<Object^>^ args) { if (!type) throw gcnew ArgumentNullException("type"); Type^ t = Type::GetType(type); if (!t) throw gcnew ArgumentException("Invalid type name"); Object^ obj = Activator::CreateInstance(t, args); return obj; } When calling...

Target .NET 3.5 C++/CLI in Visual Studio 2010 Beta 2

Has anyone had any success converting a VS 2008 C++/CLI (vcproj) project to a VS 2010 project (vcxproj), whilst maintaining .NET 3.5 as the target framework? I haven't been able to do this and get the project to build successfully. The project compiles fine in VS2008 as .NET 3.5, and fine in VS2010 as .NET 4.0, but I am unable to target ...

Calling a C++/CLI function from a C++ library

I need to integrate a native C++ library into a C# project. Now in this C++ library there is class with virtual functions that I need to inherit from in C++/CLI. So in C++/CLI I wrote someting like class C++CliClass : public C++Class { C++CliClass(Callback callback) { iCallback = callback; } virtual VirualFunctionCallFromC++(int x...

How to port C++ code to C++/CLI in Visual Studio?

I have an application written in native C++ which I'd like to get running on the .NET virtual machine. I was thinking of recompiling the C++ code as C++/CLI, using the Visual Studio 2008 compiler. Regrettably, I don't find any documentation on how to do this, so hence my questions: Does this actually make sense? Am I trying the impossi...