Share via


How cleanup a TCHAR array variable?

Question

Tuesday, November 21, 2017 5:32 AM

Hello,

I have this code and want know how cleanup a TCHAR array variable after use.

TCHAR szRoaming[MAX_PATH];
HRESULT hRoaming = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, szRoaming);
    
if (! SUCCEEDED(hRoaming))
    {
        printf("SHGetFolderPath function failed.\n");
    }
    
...

Cleanup szRoaming;

All replies (1)

Tuesday, November 21, 2017 6:02 AM âś…Answered

I have this code and want know how cleanup a TCHAR array variable after use.

I'm not sure what you mean with cleanup in your case. Since you created an static array there is no need to clean up the memory (=to free the memory). You only need to clean up the memory if you created a dynamic array i.e. using new, malloc, ... than you use delete, free, .... to free the memory.

If you want to clear the content of your array you could use:

ZeroMemory(szRoaming, sizeof(szRoaming));

After this command all cells of your array are zero.

Best regards

Bordon

Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.