Live Chat Icon For mobile
Live Chat Icon

WinForms FAQ - from MFC

Find answers for the most frequently asked questions
Expand All Collapse All

MyClass ht; does not create any object. Instead, it creates a variable (a reference) of type MyClass, and sets its value to null. No object is created. To create an object, you need to explicitly call the class constructor with a new.

	
	MyClass  ht = new MyClass();

You can also use ht to refer to an instance of MyClass that has been created (with a new) at some other point in your code.

	
	MyClass  myClass = new MyClass();
	......
	MyClass ht;
	......
	ht = myClass; // both ht and myClass are references to the same object...
Permalink

Your managed code doesn’t have a destructor, just a finalizer. The difference is a destructor (as in C++) fires immediately when an object goes out of scope, but a finalizer is run when the CLR’s garbage collector (GC) gets to your object. It’s not deterministic when this will occur, but it’s very unlikely to occur right after the object goes out of scope. It will happen at a later time, however.

(from sburke_online@microsoft..nospam..com on microsoft.public.dotnet.framework.windowsforms)

Permalink

You can create static methods that encode and decode these values. Here are some.

static int MakeLong(int LoWord, int HiWord)
{
	return (HiWord << 16) | (LoWord & 0xffff);
}
static IntPtr MakeLParam(int LoWord, int HiWord)
{
	return (IntPtr) ((HiWord << 16) | (LoWord & 0xffff));
}
static int HiWord(int Number)
{
	return (Number >> 16) & 0xffff;
}
static int LoWord(int Number)
{
	return Number & 0xffff;
}
Permalink

1] The conditionals in if-statements must calculate to a boolean value. You cannot write something like

if (nUnits)  {    ...   } 

where nUnits is a int.

2] All code must reside in a class. There are no global variables per se.

3] Bitwise & and | operators can be used with boolean types as logical operators. The && and || operators are also used, and do have the ‘short-cut calculation’ behavior found in C++. The & and | operators do not have this ”short-cut calculation’ behavior.

4] Pointers are not available in managed code.

5] In managed code, destructors are not hit immediately when as object goes out of scope. Ie, there is no deterministic destruction.

Permalink

Share with

Couldn't find the FAQs you're looking for?

Please submit your question and answer.