tags:

views:

188

answers:

1

Hello,

I'm new to C++ and Direct X, and I was wondering what is the proper use of DXGetErrorString and DXGetErrorDescription?

According to http://msdn.microsoft.com/en-us/library/bb173057(VS.85).aspx and http://msdn.microsoft.com/en-us/library/bb173056(VS.85).aspx, these functions return a pointer to a string. However, in all the examples I've seen on the web, they directly use the return value without freeing it afterward.

For example:

char buf[2048];
sprintf(buf, "Error: %s error description: %s\n",DXGetErrorString(hr),DXGetErrorDescription(hr));

Does that mean there is a memory leak because the memory allocated for the error string and the error description is never released ? If not, how is it released ?

Thank you for the help !

+2  A: 

Most likely, the functions return a static string, so it doesn't need to be free'd.

It'd be similar to writing code like this, where you would not worry about freeing the return value:

PCWSTR GetErrorCode(int error)
{
    switch (error)
    {
        case 1:
          return L"File not found";
        ...
        default:
          return "Unknown error";
    }
}
Michael
Good point. I didn't think about that, thanks!
Kevin