/*
 * SPDX-FileCopyrightText: 2025 Copyright contributors to the cppTango project
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 */
#ifndef TANGO_INTERNAL_WINDOWS_H
#define TANGO_INTERNAL_WINDOWS_H

#include <tango/common/tango_const.h>

//
// Static function to return a formatted error message for the last
// WIN32 error.
//

static char *GetErrorText()
{
    DWORD rc;
    char *str = 0;
    char *cstr = 0;
    rc = ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                         0,
                         GetLastError(),
                         LANG_NEUTRAL,
                         (char *) &str,
                         0,
                         0);
    if(str)
    {
        cstr = Tango::string_dup(str);
        ::LocalFree((HLOCAL) str);
    }
    else
    {
        cstr = Tango::string_dup("FormatMessage failed");
    }
    return cstr;
}

#endif
