4coder»Forums
3 posts
Redirection of OutputDebugString to a 4coder buffer
Edited by Zero on Reason: Initial post
This would only be a windows thing and I don't know if this feature is as good / helpful as I am thinking right now, but with the log messages that are passed to OutputDebugString could be redirected to a 4coder buffer, so that we don't have to open / switch to a visual studio, if we only want to view log output while running.
Ryan Fleury
204 posts / 4 projects
Working at Epic Games Tools (RAD). Former Handmade Network lead. Maker of Hidden Grove.
Redirection of OutputDebugString to a 4coder buffer
4coder receives stderr and stdout, so what you could probably do is just this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void DebugPrint(char *format, ...)
{
    static char buffer[4096];
    va_list args;
    va_start(args, format);
    vsnprintf(buffer, sizeof(buffer), format, args);
    va_end(args);
    printf("%s", buffer);
    OutputDebugString(buffer);
}
Mārtiņš Možeiko
2562 posts / 2 projects
Redirection of OutputDebugString to a 4coder buffer
Edited by Mārtiņš Možeiko on
Here's a small C code snippet how to redirect OutputDebugString to stderr of your process:
https://gist.github.com/mmozeiko/bfe0ce5762c496f92d8c775983c41694

Only thing you need to do is to call "ods_capture()" at start of process.

For more information on how OutputDebugString works internally you can read here: http://www.unixwiz.net/techtips/outputdebugstring.html
3 posts
Redirection of OutputDebugString to a 4coder buffer
Neither of them worked for me, they only work when I set the SUBSYSTEM to Console, and define entry point as 'int main' instead of 'WinMain'. So I ended of doing this:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
typedef void (WindowsLogFn)(const char*);
static WindowsLogFn* windowsLog;

static void windowsLogConsole(const char* msg)
{
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD written; // ignored
	char* t = (char*)msg;
	DWORD len = 0;
	while (*t != 0) { t++; len++; }
	WriteConsoleA(hOut, msg, len, &written, 0);
}

void log(const char* cstr)
{
	windowsLog(cstr);
	windowsLog("\n");
}

// entry point
if(IsDebuggerPresent())
{
	windowsLog = OutputDebugStringA;
}
else
{
	AllocConsole();
	windowsLog = windowsLogConsole;
}
// others
Mārtiņš Možeiko
2562 posts / 2 projects
Redirection of OutputDebugString to a 4coder buffer
If you are using subsystem windows, then you need to call AllocConsole and reopen stdout/stderr FILE's. Because by default they won't go anywhere. If you are using console subsystem, then there is no need to call AllocConsole - it is already called by OS for you.