using System;

namespace Sample
{
    public class Base
    {
        protected  string initialized = "No";

        public Base()
        {
            Console.WriteLine( "Calling base ctor." );
            DoSomething();
        }
        // This will be overridden in the derived type.
        public virtual void DoSomething()
        {
            Console.WriteLine( "Base DoSomething" );
        }
    }

    public class DerivedType : Base
    {
        public DerivedType ()
        {
            Console.WriteLine( "Calling derived ctor." );
            initialized = "Yes";
        }
        public override void DoSomething()
        {
            Console.WriteLine( "Derived DoSomething is called - initialized ? {0}", initialized );
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Base derivedInstance = new DerivedType();
        }
    }
}

Output:
Calling base ctor.
Derived DoSomething is called - initialized ? No
Calling derived ctor.

Is there something wrong ? … Yes of course Read the rest of this entry »

Hardcore Win32 developers are probably familiar with the OutputDebugString() API function that lets your program talk with a debugger.

When OutputDebugString() is called by an application, it takes these steps. Note that a failure at any point abandons the whole thing and treats the debugging request as a no-op (the string isn’t sent anywhere).

  1. Open DBWinMutex and wait until we have exclusive access to it.
  2. Map the DBWIN_BUFFER segment into memory. If it’s not found, there is no debugger running so the entire request is ignored.The DBWIN_BUFFER when present, is organized like this structure. The process ID shows where the message came from, and string data fills out the remainder of the 4KB. By convention, a NULL byte is always included at the end of the message. Read the rest of this entry »

When an object containing virtual functions is created, its VPTR must be initialized to point to the proper VTABLE. This must be done before there’s any possibility of calling a virtual function. A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor. As you might guess, because the constructor has the job of bringing an object into existence, it is also the constructor’s job to set up the VPTR. The compiler secretly inserts code into the beginning of the constructor that initializes the VPTR. In fact, even if you don’t explicitly create a constructor for a class, the compiler will create one for you with the proper VPTR initialization code (if you have virtual functions). This has several implications.

The first concerns efficiency. The reason for inline functions is to reduce the calling overhead for small functions. If C++ didn’t provide inline functions, the preprocessor might be used to create these “macros.” However, the preprocessor has no concept of access or classes, and therefore couldn’t be used to create member function macros. In addition, with constructors that must have hidden code inserted by the compiler, a preprocessor macro wouldn’t work at all. Read the rest of this entry »

The hierarchy of constructor calls brings up an interesting dilemma. What happens if you’re inside a constructor and you call a virtual function? Inside an ordinary member function you can imagine what will happen – the virtual call is resolved at runtime because the object cannot know whether it belongs to the class the member function is in, or some class derived from it. For consistency, you might think this is what should happen inside constructors.This is not the case. If you call a virtual function inside a constructor, only the local version of the function is used. That is, the virtual mechanism doesn’t work within the constructor. Read the rest of this entry »

Ever wondered which program has a particular file or directory open? Now you can find out. Handle is a utility that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program.

To know more, click here

Download Handle