In the world of Win32, integer values were used to indicate errors produced by functions. This already introduces a problem: The meaning of a plain old integer is not very clear by just looking at it. Instead, symbolic constants need to be introduced to make program code look more meaningful. Although the error checks might be apparent during development, the magic error constants do not offer much information during debugging. Furthermore, those error codes need to be queried for after failed function calls using the GetLastError function. An example of such a function call, followed by error “handling,” is shown here:

HWND hWindow = CreateWindowEx(0, g_szClassName, L"Hello Win32",                              WS_OVERLAPPEDWINDOW, ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.