I just reported this bug on Connect : Connect Bug URL .NET 4.0 supports covariance and contravariance in delegates and interfaces. Unfortunately, C++/CLI does not support this as of VC++ 2010 RTM. Considering that the most popular use for C++/CLI today is as an interop language, the compiler not supporting a feature that’s going to [...]
Entries Tagged as 'C++/CLI'
VC++ 2010 : C++/CLI does not support variant delegates/interfaces
July 11th, 2010 · No Comments
Visual Assist X gives VC++ 2010 intellisense for C++/CLI
July 2nd, 2010 · 1 Comment
The lack of intellisense has been the biggest show-stopper for using VC++ 2010 for any managed or mixed mode programming. Many people could not make the upgrade from VC++ 2008 for this very reason. Fortunately, the latest version of Visual Assist X from Whole Tomato Software provides fully functional intellisense for C++/CLI code! VA has [...]
Native exe linking with mixed-mode static lib
June 21st, 2010 · No Comments
Pon Sayasith emailed me a couple of weeks ago saying he’d bought my C++/CLI book and then went on to ask me what I thought of a mixed mode static library that has a managed class and a native wrapper, that is then consumed by a native C++ app. My first reaction (which turned out [...]
Tags: C++/CLI
FAQ: C# calling C++ code with callbacks with unmanaged array arguments
June 11th, 2010 · No Comments
This question or a similar variation pops up in the forums once in a while. The core problem is that while null terminated char arrays can be marshaled to a System.String fairly easily, with other unmanaged arrays the marshaller cannot know for sure what size of array to create. The solution is to marshal the [...]
C++/CLI bug : Operator overloading in an interface
February 27th, 2010 · 1 Comment
There was a very interesting thread on Code Project’s C++/CLI forum last week. Here’s the link to the thread : Code Project forum thread The gist of the post is that the C++/CLI compiler was not recognizing an overloaded unary operator defined in an interface while it could do so when the interface was changed [...]
C++/CLI Article : Deriving from a C# disposable class
July 5th, 2008 · 1 Comment
Last week at work, I had to work on a C++/CLI class that derived from a class written in C# which implemented IDisposable. I got it wrong at first (yeah, same guy who wrote a book on the subject a couple of years ago) and my boss and I spent some time going through the [...]
Tags: C++/CLI
Invoking a virtual method in a managed constructor
June 19th, 2008 · 2 Comments
In standard C++, we know that a virtual method call in a base class constructor will not invoke the derived class override. This is an area where C++/CLI behaves differently from standard C++. The vtables are initialized even before the base class constructor is called. There was a post in the MSDN forums earlier today [...]
Tags: C++/CLI
Article : A look at STL/CLR performance for linear containers
March 8th, 2008 · 5 Comments
This article is an attempt to do a performance comparison of the STL/CLR sequential containers with corresponding generic collections in the BCL. To my total surprise, the STL/CLR containers fell way behind the BCL classes. Talk about misleading expectations. A look at STL/CLR performance for linear containers
Tags: C++/CLI
More on extending the marshal_as library
July 12th, 2007 · 1 Comment
In my previous blog entry, I talked about extending marshal_as to support other type conversions in addition to the default ones. But the examples I used didn’t need to handle resource deallocation. When you have type conversions which require explicit resource deallocation, you have to handle it slightly differently. As an example I have written [...]
Tags: C++/CLI · VC++ Orcas
Extending the marshal_as library
July 8th, 2007 · 4 Comments
A couple of blog entries ago, I had written about the marshal_as library that is introduced in Orcas and how it’s very useful for mixed-mode string conversions. While the built-in functionality only allows string conversions, it’s also possible to extend marshal_as functionality to support other type conversions. As an example of doing this, I have [...]
Tags: C++/CLI · VC++ Orcas
Sample chapter from my C++/CLI book
September 22nd, 2006 · 7 Comments
Manning has something called MEAP (Manning Early Access Programme), where they make available unedited drafts of chapters for people who apply for MEAP. It’s not free, but they usually give one free MEAP chapter. My book’s chapter 1 is now available for free from the Manning MEAP page for my book (other MEAP chapters are [...]
My book’s front cover
June 9th, 2006 · 16 Comments
Here’s a preview image of my book’s cover. Most of the Manning book covers use images from the 1805 edition of Sylvain MarŽchal’s four-volume compendium of regional dress customs. You can read more on that here. And no, that’s not the Pope! That’s what my wife jokingly asked me when she saw the cover.
You *can* delete a NULL pointer!
June 7th, 2006 · 7 Comments
This is an often asked question in newsgroups and forums. A lot of people do this :- if(p) delete p; The assumption is that, if they do not check for NULL, delete will result in a crash or in random behavior. This is not correct. C++ guarantees that a delete will do nothing if the [...]
C++/CLI in Action
May 10th, 2006 · 26 Comments
Some of you already know about this, but I have been working on a C++/CLI book for Manning Publications for the past five months or so. The book is titled “C++/CLI in Action” and is targeted at Visual C++ developers with a .NET background who’d like to interop their native code with managed frameworks. The [...]
Avalon with C++/CLI – what are your options?
March 31st, 2006 · 8 Comments
As of today (Feb CTP), Visual C++ projects cannot have XAML in them as C# and VB projects can. Of course, this does not mean that you cannot target Avalon using C++, and if you have read my previous blog entries, you’d have seen a couple of ways how that can be done. To put [...]
Tags: C++/CLI · WPF (Avalon)
A Windows Forms component that provides enhanced MessageBox functionality
February 21st, 2006 · 2 Comments
MessageBoxManager is a Windows Forms component I wrote that you can drag & drop into a Windows Forms project’s main form, and it gives you enhanced message box functionality without forcing you to change your existing calls to any of the MessageBox.Show() overloads . You can download it from :- MessageBoxManager – A Windows Forms [...]
Tags: C++/CLI · CLR/.NET BCL
Get the Office 2003 style menus/toolbars in your MFC apps using Windows Forms
February 15th, 2006 · 4 Comments
This is my latest Code Project article, and it shows you how to use the Windows Forms 2.0 MenuStrip and ToolStrip controls in your MFC applications to give them an Office 2003 look and feel. These Forms controls are pretty well written, and if you change the XP theme/style, they change accordingly, just like Word [...]
Tags: C++/CLI · VC++ 2005 · Win32/MFC
Preserving method signature for CCW
January 24th, 2006 · No Comments
I got this tip from my friend, Rama Krishna Vavilala – who’s virtually a total expert in anything Win32, from SDK to COM to .NET! Thanks Rama! By default, the CCW will convert your managed object’s methods so that the return type is an out parameter of the COM method. For example, if your managed [...]
Tags: C++/CLI
A managed smart pointer for using native objects in managed code
January 20th, 2006 · 2 Comments
CAutoNativePtr is a managed template class that I wrote, which acts as a smart pointer for using native objects in managed code, and it’s been posted on Code Project. CAutoNativePtr – A managed smart pointer for using native objects in managed code The class manages a smart pointer, which will automatically free the native resource [...]
Tags: C++/CLI
A finalizer that nearly ended up wrong!
January 19th, 2006 · 8 Comments
Holy cow! I very nearly wrote some messed up code a few minutes ago. I was writing this disposable class, and I wanted to call the finalizer from my destructor, to avoid code duplication. Guess what I did first! Man, I really was stupid! Here goes. ~MyType() { !MyType(); } And you know what that [...]
Tags: C++/CLI