Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

    • 14,897

Archive for the ‘General’ Category

OLE,COM and ActiveX

Posted by kiraninbng on September 8, 2006

First came OLE(Object linking and embedding) , which was basically used in ms applications to embed an object of one into another.

Then came the COM standard which took over the tasks of the OLE.For sometime it was also called as OLE2 for sometime.

Next was the ActiveX,which referred to suite of COM based technologies targeted mainly at the internet.The best known ActiveX technology are ActiveX controls.

Then came DCOM which is basically use of COM across the networks.

I guess now the .NET technologies are replacing the COM based technologies and are much simpler.

Posted in General | 2 Comments »

getting special folders path…

Posted by kiraninbng on July 27, 2006

Three simple steps to get the paths for special folders,
1. Use SHGetSpecialFolderLocation with appropriate nFolder value(2nd param)
2. SHGetPathFromIDList – Fetch the path name from returned Item Identifier list
3. Release the Item Identifier list
   

Below is an example,

    LPITEMIDLIST pIDList;
    HRESULT hr = SHGetSpecialFolderLocation(NULL,CSIDL_PERSONAL,&pIDList);

    if(SUCCEEDED(hr))
    {
        char szSpecialFolderPath[_MAX_PATH];

       if(SHGetPathFromIDList(pIDList,szSpecialFolderPath))
       {
           LPMALLOC pMalloc;

           hr = SHGetMalloc(&pMalloc);
           if(SUCCEEDED(hr))
           {
               pMalloc->Free(pIDList);
               pMalloc->Release();
           }
       }

Posted in General | Leave a Comment »

const functions….

Posted by kiraninbng on July 25, 2006

If the function is declared as const,the compiler treats the “this” as const pointer.So if you are calling a non const member function of the same class then all you need to do is to remove the constantness of “this” pointer.The case for an embedded object of user defined type is pretty much straight forward.Below is an example,

Class CConstObj
{
 // dummy class
}

Class CConst
{
public:
    void Constfn()const;
    void NonConstfn(); 
    //…..
private:
    CConstObj m_oConstObj; 
 
}

void CConst::Constfn()const
{
    // Call a non const member function from the same class 
    ((CConstObj*)this)->NonConstfn();

    // Call non const member function of m_oConstObj ; 
    // m_oConstObj is a member of type CConstObj.
    ((CConstObj&)m_oConstObj).CallNonConstFn();
    ((CConstObj*)&m_oConstObj)->CallNonConstFn();
}

void CConst::NonConstfn()
{
   
}

Posted in General | 3 Comments »

function return values…

Posted by kiraninbng on July 18, 2006

Generally functions on success will return a value of 0,but i have often seen funtions which return a value of 1 for success,which i believe makes the function inextensible
for returning meaningful error codes.Heres what i follow,

typedef enum
{
 SUCCESS,
 …,
 FAILURE_N
}RETURNTYPE;

RETURNTYPE SomeFunction()
{
 RETURNTYPE Result = SUCCESS;
 
 if(…)
 {
  Result = FAILURE_N;
 }

 return(Result);

In simple terms return a value of 0(FALSE) for success and a value other than 0 for failure.

Posted in General | 2 Comments »

Microsoft codenames…

Posted by kiraninbng on July 10, 2006

Whidbey – VS2005
Yukon – MSSQL2005
Avalon – Windows Presentation foundation(WPF)
Indigo –  Windows Communication foundation(WCF)
Longhorn – Windows Vista

ofcourse it is not possible to post all the codenames..so heres the complete list.

Posted in General | Leave a Comment »

Pointer to member functions

Posted by kiraninbng on July 10, 2006

A pointer to a member function consists of return type, the class name followed by ::, the function pointer name and the
function’s parameter list.

Ex :

class CTest
{
 int fn();
}

// pmCTest is a pointer to a member function which takes int as the parameter
int CTest::*pmCTest();
Below code shows how to invoke the pointer to member function,

pmCTest = &CTest::fn;
CTest oCTest;
CTest *pCTest = &oCTest;
// Invoke the member function using an object
(oCTest.*pmCTest)();
// Invoke the member function using an object pointer
(pCTest->*pmCTest)();

If you call virtual member function using a pointer to member function, the call will get resolved dynamically.

Also the size of the pointer to member function can change depending on whether the class is inherited from a single class
or from multiple classes.

Posted in General | Leave a Comment »

embedded pdb path…

Posted by kiraninbng on July 8, 2006

Dumpbin is a command line utility used for extracting various information like headers,imported and exported functions etc from the exe or dll.

For more information u can check http://support.microsoft.com/kb/q177429/.

So how do u find the embedded pdb path,just give

Dumpbin /headers <exe name>

and then search for the debug directories section in the output of the dumpbin,u will find something like this,

Debug Directories

Type    Size  RVA    Pointer
—— —— —–  ——–
cv       30  00000000 2A000    Format: NB10, 44a89304, 2, D:\DELETE\ExeNameDebug\ExeName.pdb

Posted in General | 1 Comment »

Pointers to data members..

Posted by kiraninbng on July 7, 2006

Pointers to data members are pointers which help us to manipulate the data members of an object.The syntax is very similar to that of pointer to function,with the addition of the class name followed by the scope resolution operator(::).

Ex :

class CTest
{
 int nVal;
}

// pmCTest is a pointer to an int member of CTest
int CTest::*pmCTest;

You can initialize the pointer to data member by giving the address of member of the Class

Ex:  pmCTest = &CTest::nVal;

The data pointed can be manipulated either by using the object or the object pointer,

Ex :

CTest oCTest;
CTest* pCTest = new CTest;

int nTemp = oCTest.*pmcTest; // Using the object
pcTest->*pmcTest = nTemp; // Using the object pointer

In the next post i will talk about pointers to member functions.

Posted in General | Leave a Comment »

Why virtual destructors…

Posted by kiraninbng on July 6, 2006

Heres a great post on when and why the destructors should be made virtual.

Posted in General | 1 Comment »

sizeof…

Posted by kiraninbng on July 5, 2006

Here is a simple way to find the size of an object without using the sizeof operator,

class CTest { … }

CTest oCTest;
CTest* pCTest;
unsigned char* pStart = NULL;
unsigned char* pEnd = NULL;

pCTest = &oCTest;
pStart = (unsigned char*)pCTest;
pEnd = (unsigned char*)(++pCTest);

//size gives the size of the object oCTest.
size_t size =  pEnd – pStart;

Posted in General | 1 Comment »