Output log messages as debug strings, if no console is attached.

This commit is contained in:
LoRd_MuldeR 2011-03-04 23:40:09 +01:00
parent 82e64a9a00
commit 0e0f63fe0d
3 changed files with 84 additions and 36 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 1
#define VER_LAMEXP_BUILD 346
#define VER_LAMEXP_BUILD 349
#define VER_LAMEXP_SUFFIX Beta-5
/*

View File

@ -112,6 +112,9 @@ static QDate g_lamexp_version_date;
static const char *g_lamexp_months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static const char *g_lamexp_version_raw_date = __DATE__;
//Console attached flag
static bool g_lamexp_console_attached = false;
//Compiler version
#if _MSC_VER == 1400
static const char *g_lamexp_version_compiler = "MSVC 8.0";
@ -262,11 +265,16 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
QMutexLocker lock(&g_lamexp_message_mutex);
if(!hConsole)
{
if(g_lamexp_console_attached)
{
hConsole = CreateFile(L"CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
if(hConsole == INVALID_HANDLE_VALUE) hConsole = NULL;
}
}
if(hConsole)
{
CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
GetConsoleScreenBufferInfo(hConsole, &bufferInfo);
SetConsoleOutputCP(CP_UTF8);
@ -283,7 +291,6 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
break;
case QtWarningMsg:
SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
//MessageBoxW(NULL, (wchar_t*) QString::fromUtf8(msg).utf16(), L"LameXP - GURU MEDITATION", MB_ICONWARNING | MB_TOPMOST | MB_TASKMODAL);
fwprintf(stderr, L"%S\n", msg);
fflush(stderr);
break;
@ -295,6 +302,27 @@ void lamexp_message_handler(QtMsgType type, const char *msg)
}
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
}
else
{
char temp_buffer[1024];
switch(type)
{
case QtCriticalMsg:
case QtFatalMsg:
sprintf_s(temp_buffer, 1024, "[LameXP][C] %s", msg);
break;
case QtWarningMsg:
sprintf_s(temp_buffer, 1024, "[LameXP][W] %s", msg);
break;
default:
sprintf_s(temp_buffer, 1024, "[LameXP][I] %s", msg);
break;
}
OutputDebugStringA(temp_buffer);
}
if(type == QtCriticalMsg || type == QtFatalMsg)
{
@ -325,7 +353,12 @@ void lamexp_init_console(int argc, char* argv[])
if(enableConsole)
{
if(AllocConsole())
if(!g_lamexp_console_attached)
{
g_lamexp_console_attached = AllocConsole();
}
if(g_lamexp_console_attached)
{
//-------------------------------------------------------------------
//See: http://support.microsoft.com/default.aspx?scid=kb;en-us;105305
@ -340,15 +373,21 @@ void lamexp_init_console(int argc, char* argv[])
setvbuf(stderr, NULL, _IONBF, 0);
}
HMENU hMenu = GetSystemMenu(GetConsoleWindow(), 0);
if(HWND hwndConsole = GetConsoleWindow())
{
HMENU hMenu = GetSystemMenu(hwndConsole, 0);
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
RemoveMenu(hMenu, SC_CLOSE, MF_BYCOMMAND);
SetWindowLong(hwndConsole, GWL_STYLE, GetWindowLong(hwndConsole, GWL_STYLE) & (~WS_MAXIMIZEBOX));
SetWindowLong(hwndConsole, GWL_STYLE, GetWindowLong(hwndConsole, GWL_STYLE) & (~WS_MINIMIZEBOX));
SetConsoleCtrlHandler(NULL, TRUE);
SetConsoleTitle(L"LameXP - Audio Encoder Front-End | Debug Console");
SetConsoleOutputCP(CP_UTF8);
}
}
}
/*
* Detect CPU features

View File

@ -208,3 +208,12 @@ int main(int argc, char* argv[])
}
#endif
}
extern "C"
{
void __declspec(dllexport) __stdcall Test(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
OutputDebugStringA("Hello cruel world!");
MessageBoxA(0, lpszCmdLine, "LameXP v9.0", MB_ICONINFORMATION);
}
}