Skip to main content

Steve Jobs Documentary & Best videos

· One min read

To day I had found popular 'Steve Jobs Documentary' and inspiring speechs of Steve Jobs ...

Documentary

Documentary Part 1

[youtube=http://www.youtube.com/watch?v=QgiEG-NsAB0&feature=related]

Documentary Part 2

[youtube=http://www.youtube.com/watch?NR=1&v=3zvBLxvg7ds]

Documentary Part 3

[youtube=http://www.youtube.com/watch?NR=1&v=6tnz3NpR1xg]

Documentary Part 4

[youtube=http://www.youtube.com/watch?NR=1&v=K7tdqL_M87Y]

Documentary Part 5

[youtube=http://www.youtube.com/watch?NR=1&v=TUXUbVG-Lx8]

Stanford Commencement Address

Steve Jobs' Stanford Commencement Addres

[youtube=http://www.youtube.com/watch?v=UF8uR6Z6KLc]

Memory Layout of a class (C++) Object

· One min read

Let us know how the members of a class are stored in the C++ class object.

  1. All Static Members Functions, Static member variables and Non static Members Functions are hoisted outside the class object.
  2. All non static member variables are stored in the class object.
  3. All virtual functions are part of Virtual Table. And a pointer (vptr) to the created Virtual Table is inserted with in each class object.

Sample Program:

class Sample
{
public:
Sample() {};

virtual ~Sample() {}
virtual void virtualFun1() {}
virtual void virtualFun2() {}

void normalFun() {}

static int getCount() //static function
{
return nCount;
}

private:
int i;
static int nCount;
};

void main()
{
Sample obj;
cout<<obj;
}

Size Matters (C++)

· 2 min read

C++ class have

A. Data Members B. Members Functions

Data Members

  1. Static Data Member The size of a class object with only Static data members irrespective of Data Type (say float, long e.tc.) is equal to one Byte (~ size of Empty class)
    class CStaticDataMemberCls
{
public:
static int i;
static float f;
};


void main() {
CStaticDataMemberCls objSDMC;
cout<<objSDMC;
}
  1. Non Static Data Member The size of a class with non static data members is equal to sum of the data type size i.e. size of int = 4 size of float = 4 so total = 8
    class CNonStaticDataMemberCls
{
public:
int i;
float f;
};


void main() {
CNonStaticDataMemberCls objNSDMC;
cout<<objNSDMC;
}

Members Functions

  1. Static Members Functions
  2. Non Static Members Functions

As Static Members Functions and Non static Members Functions are hoisted outside the class object. The size of the class will also be equal to one Byte (~ size of Empty class)

class CMemberFunctionsCls
{
public:
int fun1() { return 1; }
static int staticFun() { return 1; }

};

void main()
{
CMemberFunctionsCls objMFC;
cout<<objMFC;
}
  1. Virtual Members Functions If a class consists of virtual functions a table of pointers(i.e. Virtual Table) to virtual functions is generated for each class. And a pointer (vptr) to the created Virtual Table is inserted with in each class object. So the size of CVirtualFunctionCls object will be 4 Bytes which is nothing but a size of vptr.
    class CVirtualFunctionCls
{
public:
virtual ~CVirtualFunctionCls() {}
virtual void virtualFun1() {}
virtual void virtualFun2() {}
};


void main() {
CVirtualFunctionCls objVFC;
cout<<objVFC;
}

Let us see the class with all the above members

class Sample
{
public:
Sample() {};

virtual ~Sample() {}
virtual void virtualFun1() {}
virtual void virtualFun2() {}

void normalFun() {}

static int getCount() //static function
{
return nCount;
}

private:
int i;
static int nCount;
};

void main()
{
Sample obj;
cout<<obj;
}

Variable arguments handling in C/C++

· One min read

Use va_list to accept a VARYING NUMBER OF ARGUMENTS for any function in C/C++. printf(const char*_Format, ...) is a real time function which uses va_list.

For using va_list we need to know about the following macros

va_start Initialize a variable argument list (macro) va_arg Retrieve next argument (macro) va_end End using variable argument list (macro)

The sample explains how to use VARYING NUMBER OF ARGUMENTS


# include <stdarg.h>

int Add(int args, ...)
{
int sum = 0;
int temp = 0;

va_list va; //1. Declare a va_list

va_start(va, args); //2. Initialise

for(int i = 0; i<=args; i++) {
temp = va_arg(va, int); //3. Retrieve
sum = temp+sum;
}

va_end(va); //4. END

return sum;
}

void main() {
printf("sum=%d n ", Add(2, 1, 2, 5));
//OutPut: 8
}

Why size of an empty C++ class not zero?

· One min read

To ensure that the addresses of two different objects will be different C++ compiler will allocate one byte of memory. The below sample code explains clearly. Because of this behaviour the addresses of class X objects are not equal even though there is no data present in the class X.

class X {

};

class Y {

};

void main() {
X objX1, objX2; Y objY;

cout<<"size of objX1: "<<sizeof(objX1)<<endl; //Output: 1
cout<<"size of objY: "<<sizeof(objY)<<endl; //Output: 1

//Addresses
cout<<"Address of objX1: "<<&objX1<<endl;
cout<<"Address of objX2: "<<&objX2<<endl;

cout<<"Address of objY: "<<&objY<<endl;

if(&objX1 == &objX2) {
cout<<"Never Happens";
}
}

Console Application Event Handling

· One min read

Using SetConsoleCtrlHandler we can Add an application-defined HandlerRoutine function say myConsoleHandler.

Note: If the second parameter is TRUE, the handler is added; if it is FALSE, the handler is removed by SetConsoleCtrlHandler function.

Sample code is Shown Below

#include "stdafx.h"
#include "windows.h"

void myConsoleHandler(DWORD ctrlEvent)
{
switch(ctrlEvent)
{
case CTRL_CLOSE_EVENT:
MessageBox(NULL,"Program being closed!","CTRL_CLOSE_EVENT",MB_OK);
break;

case CTRL_C_EVENT:
MessageBox(NULL,"Copy Event!","CTRL_C_EVENT",MB_OK);
break;
}

}

int main(int argc, _TCHAR* argv[])
{
SetConsoleTitle("Console Event Handler Demo");

if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)myConsoleHandler, TRUE))
{
printf( "nThe Control Handler is installed.n" );
printf( "n -- Now try pressing Ctrl+C or closing the console..." );
while(1)
{
//Do Nothing
}
}
else
{
printf( "nERROR: Could not set control handler");
return 1;
}
return 0;
}

Obtain a pointer to various objects in MFC

· One min read

The Table is very Handy when writing MFC SDI or MDI Applications

Note: To access only the current view, the document class

  • For SDI can call AfxGetMainWnd()->GetActiveView()

  • For MDI can call AfxGetMainWnd()->MDIGetActive()->GetActiveView()

MFC:Fill Background color of the Dialog

· One min read

MFC Tip: To fill the Background color of the Dialog and get the background of the controls to look correct

  1. Handle the ON_WM_ERASEBKGND Message and write the following code

     BOOL CTNV_MFCDialogDemoDlg::OnEraseBkgnd(CDC\* pDC)
    {
    CRect r;
    //GetClientRect gets the width & height of the client area of the Dialog
    GetClientRect(&r);
    CBrush br(RGB(0,255,0));
    pDC->SelectObject(br);
    pDC->FillRect(r,&br);

    //Make sure to return TRUE;
    //return CDialogEx::OnEraseBkgnd(pDC);
    return TRUE;
    }
  2. To  get the background of the controls to look correct Handle the ON_WM_CTLCOLOR Message and write the following code - Make sure to return the Brush Handle which was created same as a color of Dialog Background.

    HBRUSH CTNV_MFCDialogDemoDlg::OnCtlColor(CDC\* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    //HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    //return hbr;


    //Make sure to return the Brush color should be same as Dialog Background color
    CBrush br(RGB(0,255,0));
    return (HBRUSH)br;
    }

XAML Auto formatting in Visual Studio 2010

· One min read

To Auto format XAML code in a readable and organized way

  1. Open Visual Studio 2010
  2. Go to Menu: Tools->Options
  3. Select Text Editor |->XAML |->Formatting |->Spacing
  4. Set the options 1 & 2 as shown in the below image

Sample Code:

<Window x:Class="WpfApplication1.MainWindow" xmlns="[http://schemas.microsoft.com/winfx/2006/xaml/presentation"](http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot); xmlns:x="[http://schemas.microsoft.com/winfx/2006/xaml"](http://schemas.microsoft.com/winfx/2006/xaml&quot); Title="MainWindow" Height="350" Width="525"> 
<Grid> <!--Before Auto formatting -->
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="66,52,0,0" Name="button1" VerticalAlignment="Top" Width="75" /> <!--After Auto formatting -->
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="248,68,0,0" Name="button2" VerticalAlignment="Top" Width="75" /> </Grid>
</Window>

LightSwitch 2011

· One min read

Microsoft® Visual Studio® LightSwitch™ is used to build business applications for the desktop and cloud and focused on making it easy to develop line of business applications. It is based on data + screens which is common for LOB Applications.

Here are important links: Download a trial of LightSwitch 2011 for 90 days :

http://www.microsoft.com/download/en/confirmation.aspx?id=26830

IS0 format: http://go.microsoft.com/fwlink/?LinkId=216813 LightSwitch Developer Center: http://msdn.microsoft.com/en-US/lightswitch/ff938857

OverView: http://www.microsoft.com/visualstudio/en-us/lightswitch/overview