void Nish(char* szBlog);

Nish’s thoughts on MFC, C++/CLI and .NET

void Nish(char* szBlog); header image 4

Entries Tagged as 'C++'

VC++ 2010 : C++/CLI does not support variant delegates/interfaces

July 11th, 2010 · No Comments

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 [...]

[Read more →]

Tags: C++/CLI · VC++ 2010

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 [...]

[Read more →]

Tags: C++/CLI · VC++ 2010

VC++ 2008 with MFC and GDI+ dependency

June 30th, 2010 · 1 Comment

A month or two back, I had to write a launcher app that would allow/disallow the running of select installers based on various conditions and config files. Since this would run prior to any of the MSIs, and thus couldn’t assume the presence of any dependencies like .NET or the VC++ runtime, I wrote it [...]

[Read more →]

Tags: C++ · VC++ Orcas · Win32/MFC

Undocumented compiler error CS0226

February 28th, 2010 · No Comments

This one’s an obvious error really – but it’s still undocumented, and thus qualifies for a blog entry. I guess once __arglist was dropped from the standard documentation, all its associated error messages were dropped too. Compiler Error CS0226 Error Message An __arglist expression may only appear inside of a call or new expression Example [...]

[Read more →]

Tags: C#/.NET · VC++ 2010

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 [...]

[Read more →]

Tags: C++/CLI · VC++ 2010

Rewriting a WCF service in WWS

July 25th, 2009 · 4 Comments

In my last blog entry I had shown a WWS native client connecting to a WCF service. In this one I’ll talk about how the WCF service can be converted into an equivalent WWS service. Connecting clients (whether WWS, WCF, or other) would continue to behave the same. I am going to use the same [...]

[Read more →]

Tags: C++ · WWS API

Consuming a WCF service using a native WWS client

July 23rd, 2009 · 4 Comments

I have been meaning to play with Windows Web Services ever since I heard Nikola Dudar talk about it at the MVP Summit earlier this year. It’s natively included with Windows 7, but can also be installed and used from older OSes (XP, Vista, 2003 and 2008). You can write native clients using WWS that [...]

[Read more →]

Tags: C#/.NET · C++ · Indigo · WWS API

Setting VC++ directories in VS 2010

July 17th, 2009 · 3 Comments

In VS 2010, Tools/Options does not have a VC++ directories tab (where you normally set the include/lib search folders). Instead if you take project settings for a C++ project, you’ll see VC++ Directories listed under Configuration Properties. Of course these are per project and not per user (as in VS 2008). If you want to [...]

[Read more →]

Tags: C++ · VC++ 2010

Article : Deploying MFC applications via ClickOnce

January 13th, 2008 · 3 Comments

Recently I had the task of deploying an MFC application suite along with its dependencies via ClickOnce. Visual Studio does not directly support deployment of MFC applications (even if it’s compiled with /clr) and one of the suggested solutions I found on the web was to have a stub C# executable which would launch the [...]

[Read more →]

Tags: C++ · CLR/.NET BCL · Win32/MFC

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 [...]

[Read more →]

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 [...]

[Read more →]

Tags: C++/CLI · VC++ Orcas

Using marshal_as for mixed-mode string conversions

April 1st, 2007 · 8 Comments

The need to marshal between native and managed types is a very frequent scenario in mixed-mode programming. This is specially true when it comes to strings – when you’ve got MFC strings, COM strings, standard C++ strings and CLR strings and need to convert between those types. In fact that’s what prompted me to write [...]

[Read more →]

Tags: VC++ Orcas

Zero-length arrays

August 25th, 2006 · 11 Comments

Earlier this morning, my classmate and friend Raj (who btw is a hardcore open-source gnu/linux guy) sent an email to our class mailing list commenting on how he found a struct in some code he was working on that had a zero-length array member, and how he thought that was weird. What he was talking [...]

[Read more →]

Tags: C++

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 [...]

[Read more →]

Tags: C++ · C++/CLI

Dynamically load a Xaml file from a C++ app

March 25th, 2006 · 6 Comments

While it’s an absolute tragedy that C++ does not directly support compiled Xaml, you can use Xaml dynamically from a C++ Avalon app using XamlReader::Load. Let me show you how to do that, using a simple example. You can create your Xaml file, either using a text editor or using a temporary dummy C# or [...]

[Read more →]

Tags: VC++ 2005 · WPF (Avalon)

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 [...]

[Read more →]

Tags: C++/CLI · VC++ 2005 · Win32/MFC

VS 2005 Document Explorer never finds anything

February 4th, 2006 · 9 Comments

9 times out of 10, when I select a class name or a keyword and hit F1, the Document Explorer shows me an “Information Not Found” page. But at the same time, the index on the left has selected the topic I am looking for, which means all I need to do is to double [...]

[Read more →]

Tags: VC++ 2005

CCW and returning an array of String^

January 22nd, 2006 · 3 Comments

I was working on an app that uses CCW to access a managed library. One of the methods in the library returns an array<String^>^. The COM version of this method will have a SAFEARRAY** as the [out,retval] parameter. Not having a lot of COM experience, I was pretty surprised to find how little documentation there [...]

[Read more →]

Tags: VC++ 2005

gcnew T vs gcnew T()

January 13th, 2006 · 6 Comments

I was asked recently, why I always do gcnew T() when gcnew T produces the exact same MSIL. Here’s why. In standard C++, new T and new T() are not the same. The latter version zeroes out the memory before calling the constructor, so if you haven’t initialized a member variable, it’s zero initialized by [...]

[Read more →]

Tags: C++ · C++/CLI

You cannot #include wabdefs.h with VC++ 2005

January 4th, 2006 · 3 Comments

The following code will not compile :- #include <windows.h> #include <wabdefs.h> int main() { return 0; } You’ll get a compiler error (C2371) saying that you are redefining WCHAR. The problem is that wabdefs.h defines WCHAR as a typedef for WORD, while winnt.h defines WCHAR as a typedef for wchar_t. In VC++ 2005, /Zc:wchar_t is [...]

[Read more →]

Tags: VC++ 2005