Posts tagged ‘CPP’

9 Rules about Constructors, Destructors, and Finalizers

First, this writing concentrates of and compares between three programming languages, C#, C++/CLI, and ISO/ANSI C++. It discusses 9 rules that every developer should keep in mind while working with constructors, destructors, and finalizers and class hierarchies:

Marshaling with C# – Chapter 3: Marshaling Compound Types

Marshaling with C# Pocket Reference
Chapter 3: Marshaling Compound Types (structures, unions, etc.)

Marshaling with C# – Chapter 2: Marshaling Simple Types

Marshaling with C# Pocket Reference
Chapter 2: Marshaling Simple Types (primitives, booleans, strings, etc.)

Marshaling with C# – Chapter 1: Introducing Marshaling

Marshaling with C# Pocket Reference
Chapter 1: Introducing Marshaling

Marshaling with C# Pocket Reference

Marshaling with C# Pocket Reference (online version + direct download links)

Learn how to marshal between managed types and unmanaged types.

Note: Overcoming WinMain’s ANSI lpCmdLine

I got a question about WinMain and its ANSI lpCmdLine. Are you required to use the ANSI argument? No, you are not!

Simulating CWinApp::OnIdle in C

MFC allows you to override CWinApp::OnIdle function to perform idle-time processing.

This function is called whenever there’re no messages are waiting for processing in the message queue.

In this function, you can perform some secondary processing like updating the status bar, toolbar, etc.

How To: Refer a Resource

This article teaches you how to refer to resources, to use Resource IDs, and to use Resource Names. It doesn’t talk about resource, how to define them, or how to load them. It assumes previous knowledge of ABCs of handling resources in an IDE like Microsoft Visual Studio or Microsoft Visual C++.

How To: Represent Numbers in Dec, Hex, and Oct

In C and C++, you can have 3 ways of write a number: a) decimal b) hexadecimal 3) octal

Converting Colors to Gray Shades

This article discusses how you can display the page in print preview as grayscale if the printer is black-and-white. It discusses first how you can convert colors to grayscale. After that is discusses how to detect whether you are in print preview or not and whether the current printer is color or black-and-white printer. Let’s go…

Marshaling Unions

If this is your first time you hear about unions or you need to know more about them, please refer to our article “A short speech about Unions” first.

You can marshal a union the same way you marshal structures. However, because of the way that unions laid-out into memory, you will need to explicitly set variable positions inside the type.


Windows comes with two types that represent a Boolean variable (TRUE or FALSE.) Both represent FALSE if 0 and TRUE if non-zero.

A Short Speech about Unions

A union is a memory location that is shared by two or more different types of variables. A union provides a way for interpreting the same bit pattern in two or more different ways (or forms.)

In fact, unions share structures lots of characteristics, like the way they defined and marshaled. It might be helpful to know that, like structures, unions can be defined inside a structure or even as a single entity. In addition, unions can define complex types inside, like structures too.