Hey,

The exe code is very ugly, please excuse this, but this was my first time using "real" Win32 (project) stuff.


Click to reveal..

DLL
Code:
/*
*	LiteConsole
*
*	DLL Code.
*/

#define WIN32_LEAN_AND_MEAN
#define DLL_USE

#include <windows.h> 
#include "adll.h"

BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) 
{
	engine_bind(); 
	return TRUE;
}

DLLFUNC void LCexternOutC(char *str)
{
	HWND hWnd = FindWindow(NULL, "LiteConsole");
	COPYDATASTRUCT cds;
	cds.dwData = 1;
	cds.cbData = strlen(str) + 1;
	cds.lpData = str;
	SendMessage(hWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)(LPVOID)&cds);
}
DLLFUNC void LCexternOutS(STRING *stri)
{
	char *str = _chr(stri);
	HWND hWnd = FindWindow(NULL, "LiteConsole");
	COPYDATASTRUCT cds;
	cds.dwData = 1;
	cds.cbData = strlen(str) + 1;
	cds.lpData = str;
	SendMessage(hWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)(LPVOID)&cds);
}



exe, needs a "real" window, so that message can be processed. Way easier than just using a console.
Code:
/*
*	LiteConsole
*
*	EXE Code.
*/

#include "stdafx.h"
#include "LiteConsole.h"
#include <iostream>

#define MAX_LOADSTRING 100

HINSTANCE hInst;								// current instance
TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];			// the main window class name

ATOM				MyRegisterClass(HINSTANCE hInstance);
BOOL				InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);

class outbuf : public std::streambuf {
public:
    outbuf() 
	{
        setp(0, 0);
    }

    virtual int_type overflow(int_type c = traits_type::eof()) 
	{
        return fputc(c, stdout) == EOF ? traits_type::eof() : c;
    }
};

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	MSG msg;
	HACCEL hAccelTable;

	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_LITECONSOLE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_LITECONSOLE));
	
	if(AllocConsole()) 
	{
		freopen("CONOUT$", "w", stdout);
		freopen("CONIN$", "r", stdin);
		SetConsoleTitle(_T("Gamestudio Debug Console"));
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);  
	}

	outbuf ob;
	std::streambuf *sb = std::cout.rdbuf(&ob);
	

	std::cout.rdbuf(sb);
	HWND hwnd = FindWindow(NULL, _T("LiteConsole"));

	ShowWindow(hwnd, SW_HIDE);


	bool bRet;
	while( (bRet = GetMessage( &msg, hwnd, 0, 0 )) != 0)
	{
		if (bRet != -1)
		{
			TranslateMessage(&msg); 
			DispatchMessage(&msg); 
		}
	}

	return 0;
}

ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_LITECONSOLE));
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= MAKEINTRESOURCE(IDC_LITECONSOLE);
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

	return RegisterClassEx(&wcex);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance;

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message)
	{
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_COPYDATA:
	{
		COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
		if (pcds->dwData == 1)
		{
			std::cout << (char*)pcds->lpData;
		}
		break;
	}
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}



Here are the important parts from the exe:
Code:
if(AllocConsole()) 
	{
		freopen("CONOUT$", "w", stdout);
		freopen("CONIN$", "r", stdin);
		SetConsoleTitle(_T("Gamestudio Debug Console"));
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);  
	}

	outbuf ob;
	std::streambuf *sb = std::cout.rdbuf(&ob);
	

	std::cout.rdbuf(sb);
	HWND hwnd = FindWindow(NULL, _T("LiteConsole"));

//////////////////////

	bool bRet;
	while( (bRet = GetMessage( &msg, hwnd, 0, 0 )) != 0)
	{
		if (bRet != -1)
		{
			TranslateMessage(&msg); 
			DispatchMessage(&msg); 
		}
	}

/////////////////////

	case WM_COPYDATA:
	{
		COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
		if (pcds->dwData == 1)
		{
			std::cout << (char*)pcds->lpData;
		}
		break;
	}




So, all in all my approach is the following: SendMessage and GetMessage with WM_COPYDATA, and the string in the COPYDATASTRUCT.