NO

Author Topic: EasyPipe console redirection lib  (Read 4237 times)

Offline tony74

  • Member
  • *
  • Posts: 34
EasyPipe console redirection lib
« 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:
https://github.com/buck54321/PipeStuffer

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:

easypipeLib.zip        The static library for windows projects
pipestufferProj.zip    The 2018 update to RTconsole, but in C for Pelles C
testDlgProj.zip          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;
            }
        break;

        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
« Last Edit: March 10, 2019, 02:35:35 AM by tony74 »

Offline tony74

  • Member
  • *
  • Posts: 34
Update - threads
« Reply #1 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.

Ta