void Nish(char* szBlog);

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

void Nish(char* szBlog); header image 4

Entries Tagged as 'CLR/.NET BCL'

Type.ToString quirk on Array types

June 25th, 2010 · No Comments

There was a recent thread in the MSDN forums where someone was concerned about the behavior of Type.GetElementType. His example was similar to the following: char [][,][] arr = new char[2][,][]; Console.WriteLine(arr.GetType().GetElementType()); The output he got was: System.Char[][,] This puzzled him no end because the element type is clearly char[,][]. He was wondering if this [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

.NET 4.0 : Arrays are now structurally equatable

July 20th, 2009 · No Comments

In .NET 4.0, arrays implement IStructuralEquatable which lets you equate two arrays based on their contents. int[] array1 = new int[] { 3, 5, 9 }; int[] array2 = new int[] { 3, 5, 9 }; IStructuralEquatable equatableArray1 = array1; Console.WriteLine( equatableArray1.Equals( array2, EqualityComparer<int>.Default)); The above code outputs True. You can use it with your [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Article : A generic Trictionary class

March 11th, 2009 · 4 Comments

I just published an article on a generic Trictionary class : A generic Trictionary class [on VoidNish] The Code Project Mirror The article describes a Trictionary class that is essentially a dictionary except that for each key there are two values, both of differing types. In many cases instead of doing this, the proper approach [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Simulate a window minimize / memory release in your .NET apps

February 26th, 2009 · 3 Comments

Once in a while you have people complaining in the forums that their .NET applications are not releasing memory but that if they minimize the app and restore it, then the memory usage goes down. Why this happens is explained in this Microsoft KB article : The working set of an application is trimmed when [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Static initialization goof-up

February 21st, 2009 · 2 Comments

I am writing this blog entry as a reminder to myself to be careful when using static fields or properties, and I wanted to document some silliness on my part for posterity. Recently I was working on some code where I wanted to keep track of derived class instances by storing them in a static [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Recommendation for writing enums to a database

January 28th, 2009 · 3 Comments

I was reviewing some code and found that there were a few enum types that did not have a None value (which is a recommended practice). I thought I’d go ahead and add the None values when I found that the enum values were being written to the database via calls to Convert.ToInt32. Of course [...]

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Article : Using a TypeDescriptionProvider to support dynamic run-time properties

June 14th, 2008 · No Comments

Recently at work I had to use the TypeDescriptionProvider attribute while prototyping some new features for our product, and I thought it would be a good idea to demonstrate how to use this attribute and its related classes by writing an article. Using a TypeDescriptionProvider to support dynamic run-time properties

[Read more →]

Tags: C#/.NET · CLR/.NET BCL

Adding a DockStyle.Fill control at run-time

June 7th, 2008 · 2 Comments

This one was simple to resolve but it did halt my progress for about 5-6 minutes recently. I had a form (actually a user control) that had a control on it added at design time docked to the right. During run time I was adding a new WinForms control that I had set to DockStyle.Fill. [...]

[Read more →]

Tags: CLR/.NET BCL · Windows Forms

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

Typed URLs Cleaner utility for Windows Vista

December 31st, 2007 · 2 Comments

One really annoying feature in Windows Vista is that the typed URL history is shared between Windows Explorer and IE. So when you are using your browser and you drop down the address bar, you end up seeing dozens of local folders or network paths when all you really want to see are the web [...]

[Read more →]

Tags: CLR/.NET BCL

A data-bound multi-column combobox

July 28th, 2007 · 3 Comments

I wrote a multi-column combobox class with support for data-binding at work and I have published an article on it here :- A data-bound multi-column combobox It’s fairly easy to use and all you need to do is to set the DataSource property. The control will auto-populate the columns from the columns (if any) in [...]

[Read more →]

Tags: CLR/.NET BCL

Article – A modal dialog that fades the background to gray-scale

March 2nd, 2006 · 2 Comments

I actually published that last week, but forgot to write about it on my blog since I was engrossed in some other issues – which I’ll blog about soon. Anyway, DimmerDialog is a .NET class I wrote, that shows a modal dialog which grays out the rest of the background, just like the Windows XP [...]

[Read more →]

Tags: CLR/.NET BCL

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

[Read more →]

Tags: C++/CLI · CLR/.NET BCL

The coding gentleman’s guide to detecting the .NET Framework

July 27th, 2005 · No Comments

A C++ class I wrote that will detect and enumerate the active CLR versions on a machine! I am quite proud of the title I came up with for the article The coding gentleman’s guide to detecting the .NET Framework

[Read more →]

Tags: CLR/.NET BCL

Simulating polymorphic operator overloads with C#

April 25th, 2005 · No Comments

Isn’t that a fancy-sounding title? Jambo Johnson (Mister .NET) thought so too and so we used that as the title for our combo-article on The Code Project :- Link to article Basically, the article shows how you can work-around the operator-overloads must be static limitation in C# to simulate polymorphic behavior for operators.

[Read more →]

Tags: CLR/.NET BCL

Errata – RCW issue when returning a BSTR

January 26th, 2005 · 3 Comments

I hate being proved wrong as much as the next guy, but I owe it to my blog readers to correct a confusion that I’ve put into their minds due to a short sighted blog entry I made several months ago. For those of you who remember, I made a blog entry titled RCW issue [...]

[Read more →]

Tags: CLR/.NET BCL · Win32/MFC

String interning, pointers and a dangerous side-effect

December 6th, 2004 · 13 Comments

The CLR interns managed strings – this means that if the same string is used multiple times, all of them refer to the same instance of the string. This is possible because System::String is immutable – so the moment you change one of those strings, you are actually changing the reference which now refers to [...]

[Read more →]

Tags: C++/CLI · CLR/.NET BCL

Using reflection to invoke private methods

September 23rd, 2004 · 7 Comments

Here’s some sample code showing how you can do this; the example calls System::String::InternalLength which is private. Console::WriteLine(safe_cast<int>( __typeof(String)->InvokeMember(“InternalLength”, BindingFlags::InvokeMethod | BindingFlags::NonPublic | BindingFlags::Instance, nullptr,gcnew String(“hello world”), gcnew array<Object^>(0)))); Of course, in the above case what we did is not particularly useful since we could simply have used the Length property which internally calls InternalLength, [...]

[Read more →]

Tags: C++/CLI · CLR/.NET BCL

The significance of the C# event keyword

May 25th, 2004 · 7 Comments

Andrew Phillips asked on my CodeProject article Events and event handling in C# forum whether delegates alone aren’t sufficient for event handling and what the purpose of the event keyword is. Here is his post in it’s entirety:- OK, I understand delegates but there is a basic thing about events that no books, articles etc [...]

[Read more →]

Tags: CLR/.NET BCL

RCW issue when returning a BSTR

May 22nd, 2004 · 9 Comments

[Edit - Jan 26 2005]Unfortunately, the information in this entry is incorrect. See this later entry for details.[/Edit] I was trying out some RCW stuff (between VC++ 7.1 unmanaged and C#) and faced this little problem of a BSTR that could not be freed at all. I’ll explain the issue to you :- Let’s say [...]

[Read more →]

Tags: CLR/.NET BCL · Win32/MFC