string GetLastErrorMessage() {

        wchar* lpMsgBuf;
        DWORD errorMessageID = GetLastError();

        uint len=FormatMessageW(
                FORMAT_MESSAGE_ALLOCATE_BUFFER |
                FORMAT_MESSAGE_FROM_SYSTEM |
                FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL,
                errorMessageID,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                cast(LPWSTR) &lpMsgBuf,
                0, NULL);

        string msg=lpMsgBuf[0..len].to!string;
        LocalFree(lpMsgBuf);

        return msg;
}

Reply via email to