February 24, 2008

0.0F vs 0.0 vs 0.0L and 0 vs 0L

There are different types in C++.

0.0F is a float, 0.0 is a double, and 0.0L is a long double.

0 is a int and 0L is a long.

"ABC" is a ansi string and L"ABC" is a wide string.

February 23, 2008

General Protection Fault

General Protection Fault = GP Fault = GPF

You received this kind of error when the program is attempting accessing a read-only memory.

For example:

class Object
{
public:
  int nValue;
};

Object* pObject = NULL;
int nValueOfObject = pObject->nValue; // Accessing a memory which should not be accessed

Sample code for IWMMediaProps::GetMediaType()

// Get the required buffer size
DWORD cbType = 0;
pWMMediaProps->GetMediaType(NULL, &cbType);

// Get media type
WM_MEDIA_TYPE* pType = (WM_MEDIA_TYPE*)new BYTE[cbType];
if(SUCCEEDED(pWMMediaProps->GetMediaType(pType, &cbType)))
{
  // Use media type here
  // ...
}

// Free buffer
// Should not use "delete [] pType", we have to cast it to (BYTE*) before delete it.
delete [] (BYTE*)pType;