Fehlerbehandlung auf der Systemebene (z.B. LoadLibrary, GetProcAddress)

void __fastcall ErrorHandling(HWND hwnd, String Caption)
{
    DWORD lErr = GetLastError();

    if (lErr != ERROR_SUCCESS)
    {
        LPVOID lpMsgBuf;
        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, lErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);

        MessageBox(hwnd, (LPCTSTR)lpMsgBuf, Caption.c_str(), MB_OK |MB_ICONERROR );

        LocalFree(lpMsgBuf);
    }

    SetLastError(0);
}

Schreibe einen Kommentar