c++-cli

C++/CLI : How to declare template array as method parameters

I am a newbie to C++/CLI. What is the equivalent of the following C# code in managed C++/CLI for both the header and source file? public static bool ArrayEquals<T>(T[] a, T[] b) { return true; } ...

C++/CLI : How do I declare abstract (in C#) class and method in C++/CLI?

What is the equivalent of the following C# code in C++/CLI? public abstract class SomeClass { public abstract String SomeMethod(); } ...

C++/CLI generics, use T in array<> and other collections

Hi. I'm writing a generics class in C++/CLI (VS2008) to store and manage records of different kinds and I need collections to keep them before flusing them to DB/disk/etc. I was thinking in something like this: ref class Record { // ... }; generic<typename T> where T : Record, gcnew() public ref class Factory { public: // ....f...

C++/CLI performance gain

I started long ago with plain C, then moved to C++ and now I'm facing C++/CLI. As a performance freak, I'm always trying to squeeze the last drop of performance to every line of code. I'm currently in a project that makes sense to be done mostly in VB.Net (simplicity, resource availability, etc.), but has a few points that are very perfo...

C++/CLI : Casting from unmanaged enum to managed enum

What is the correct way of casting (in C++/CLI) from a native code enum to a managed code enum which contain the same enum values? Is there any difference with using the C# way of casting like for example (int) in C++/CLI. ...

What are the situations or pros and cons to use of C++/CLI over C#

I have been keeping up with .NET CLR for awhile now, and my language of choice is C#. Up until recently, I was unaware that C++/CLI could produce "mixed mode" executables capable of running native and managed code. Now knowing this, another developer friend of mine were discussing this attribute and trying to determine when and how thi...

How can C++/CLI make this situation easier?

I have a little piece of a library that I would like to write a .NET wrapper for. At the moment, I'm using P/Invoke, but since I don't have the library's source code or a whole lot of C knowledge, I'm having a difficult time with marshaling. It works so far (sort of), but it feels like a hack. C Signatures typedef struct { unsigned...

C++/CLI : Advantages over C#

Is there any major advantage of managed C++/CLI over C#. Definitely not the syntax I suppose as the following code in C++/CLI is real ugly, C++/CLI code: [Out]List<SomeObject^>^% someVariable Compare above with C# Code: out List<SomeObject> someVariable Just out of curiosity, is there an even uglier syntax in C++/CLI as compared t...

C++/CLI managed thread cleanup

Hi. I'm writing a managed C++/CLI library wrapper for the MySQL embedded server. The mysql C library requires me to call mysql_thread_init() for every thread that will be using it, and mysql_thread_end() for each thread that exits after using it. Debugging any given VB.Net project I can see at least seven threads; I suppose my library w...

C++/CLI efficient multithreaded circular buffer

I have four threads in a C++/CLI GUI I'm developing: Collects raw data The GUI itself A background processing thread which takes chunks of raw data and produces useful information Acts as a controller which joins the other three threads I've got the raw data collector working and posting results to the controller, but the next step i...

C++/CLI shorthand properties

Hello, How does a developer do the equivalent of this in managed c++? : c# code public String SomeValue { get; set; } I've scoured the net and found some solutions, however it is hard to distinguish which is the correct (latest, .NET 3.5) way, given the colourful history of getters/setters and managed c++. Thanks! ...

No appropriate default constructor available?

I've got a peculiar error writing some C++/CLI code. I'm trying to make a copy of a class which holds some data. The class is defined as: public ref class RawDataPacket { protected: float* m_internalData; public: RawDataPacket(const float* newInternalData); RawDataPacket(const RawDataPacket^ rdp); RawDataPacket(RawDataPacket^ rdp)...

What is the correct way to add references to libraries in C++/CLI?

I am writing a lib in C++/CLI, and one of the functions is returning a System::Drawing::Color object. I added System.Drawing as a project reference. It works. I then created a test application to link to this lib and added my created lib as a reference. Everything linked fine, but then I tried to the run the application and I had the...

C++/CLI: Native Reference vs Tracking Reference

What is the difference between the following two functions? ref class SomeClass; void swap(SomeClass^& a, SomeClass^& b){ SomeClass^ c = a; a = b; b = c; } void swap2(SomeClass^% a, SomeClass^% b){ SomeClass^ c = a; a = b; b = c; } ...

C++ CLI Collection initializer syntax

Is this supported in C++ CLI? I want to do something like the following C# example in C++ CLI var dictionary = new Dictionary<string, string> { { "foo", "bar" } }; Thanks ...

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 language for transforming from native C++ to C#? Another question that popped to my head is ...

Wrapping a std::exception and throwing an ApplicationException

I have the following code in a c++/CLI library to catch unmanaged exceptions and rethrow them: catch(const std::exception &e) { String ^errorMessage = String::Format(L"Parser threw exception: {0}", gcnew String(e.what())); throw gcnew ApplicationException(errorMessage); } Is this the best way? I seem to be losing a lot of inf...

Does a C++ Windows Forms Application require .NET Framework?

Does a C++ Windows Forms Application require .NET Framework? It seems that it does because it imports "System::Forms" but I just want be 100% sure. I tried opening it with depends and it looks like it imports the usual C++ dll's but there is nothing about the framework. ...

Encryption of a C++/CLI /clr DLL and Assembly.Load()

Hi, guys. I'm developing a client software for an online community I belong to. In order to let me write a client to it, the owners and webmasters demand my code to be encrypted (not just obfuscated). Most of my project is written in VB.NET (F3.5), and some of it is using SQLite and libcrypt via C++/CLI for performance reasons (so I cann...

What is the C++/CLI equivalent to C#'s default(T)?

I'm working with some C++/CLI code (new syntax) and am trying to declare a generic type and want to set a member variable to it's default. In C#: class Class<T> { T member = default(T); } What's the equivalent in CLI? generic<typename T> public ref class Class { public: Class() : member(default(T)) // <-- no worky { ...