Pelles C forum

C language => User contributions => Topic started by: tony74 on March 10, 2019, 12:27:04 am

Title: EasyPipe console redirection lib
Post by: tony74 on March 10, 2019, 12:27:04 am
A small 'realtime' console redirection lib for Pelles C.

These use pipestuffer.exe, a 2018 update to RTconsole that handles win10 issues.

The original C++ for Olivier Marcoux's 2018 update to RTconsole, pipestuffer.cpp:

I adapted pipestuffer.cpp to C for use in Pelles C and added some functions that
make it easier to manage realtime console redirection for GUI use.

Pelles C Projects:        The static library for windows projects    The 2018 update to RTconsole, but in C for Pelles C          An example showing pipestuffer and easylib's use. 

Note: I compiled for multithreaded 64-bit in all projects, just a heads-up.

All you need is a multiline edit control. There are only three functions to call,
two on create to initialize a struct and one that spawns the console and redirects
it to your edit control, see the example testDlg.c.

Code: [Select]
static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    char *cmd="testconsole.exe";                          //the console to run

    switch (uMsg)
        case WM_INITDIALOG:
                initpipe();                               //init first...
                loadpipe(hwnd, "pipe01", cmd, IDC_EDIT);  //then load the struct - done!
        return TRUE;

        case WM_SIZE:
        return TRUE;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID(wParam, lParam))

                case IDB_PROC:
                    enablepipe();                         //click to run the console
                return TRUE;

                case IDOK:
                    EndDialog(hwnd, TRUE);
                return TRUE;

        case WM_CLOSE:
                   EndDialog(hwnd, 0);
        return TRUE;

        case WM_CTLCOLORSTATIC:                           //make the edit look 'console-ish'
        return  onCTLCOLORSTATIC(hwnd, wParam);

    return FALSE;

If you find any errors, anomalies or leaks, fix 'em - you've got the code.

tony74 03/09/2019
Title: Update - threads
Post by: tony74 on March 10, 2019, 06:18:38 pm
It occurs to me after all that, that I failed to actually create a thread for the read-loop.
So this updates the lib and the testDlg demo that uses the lib.

There's also no reason that initpipe() couldn't be called from loadpipe() (as long as it's done first-thing), which would reduce the function calls necessary for console redirection to two.

Anyway, I have to get on with reason I make this lib to begin with.