This section of the archives stores flipcode's complete Developer Toolbox collection, featuring a variety of mini-articles and source code contributions from our readers.

| Dealing With HRESULTS Submitted by

Here's a little macro and function combo you might find useful when dealing with HRESULTS:

    #define Report(function) _Report(__FILE__, __LINE__, #function, function)

    HRESULT _Report(const char* szFileName, int nLine, const char* szFunction, HRESULT hResult)
    {
    	if (FAILED(hResult))
    		cerr << szFileName << " [" << nLine << "] - FAILED.  Result: " << hResult << endl;

    	return hResult;
    }

This makes some pretty easy to understand code, for example:

    if (Report(pDDS->Flip(NULL, DDFLIP_DONOTWAIT )) == DDERR_WASSTILLDRAWING)
    {
    	// Do some AI...
    }

I think this provides a simple, yet effective way of logging errors that may occur. If you want something more versatile, you could try transforming the _Report function to a singleton class, complete with file logging.
Anyways, enjoy!

The zip file viewer built into the Developer Toolbox made use of the zlib library, as well as the zlibdll source additions.

Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
Please read our Terms, Conditions, and Privacy information.