int main()

in misc/ScreenBufferTest2.cc [95:151]


int main(int argc, char *argv[]) {
    if (argc == 1) {
        startChildProcess(L"parent");
        return 0;
    }

    if (!strcmp(argv[1], "parent")) {
        g_prefix = "parent: ";
        dumpHandles();
        HANDLE hChild = startChildInSameConsole(L"child");

        // Windows 10.
        HANDLE orig1 = GetStdHandle(STD_OUTPUT_HANDLE);
        HANDLE new1 = createBuffer();

        Sleep(2000);
        setConsoleActiveScreenBuffer(new1);

        // Handle duplication results to child process in same console:
        //  - Windows XP:                                       fails
        //  - Windows 7 Ultimate SP1 32-bit:                    fails
        //  - Windows Server 2008 R2 Datacenter SP1 64-bit:     fails
        //  - Windows 8 Enterprise 32-bit:                      succeeds
        //  - Windows 10:                                       succeeds
        HANDLE orig2 = dup(orig1, GetCurrentProcess());
        HANDLE new2 = dup(new1, GetCurrentProcess());

        dup(orig1, hChild);
        dup(new1, hChild);

        // The writes to orig1/orig2 are invisible.  The writes to new1/new2
        // are visible.
        writeTest(orig1, "write to orig1");
        writeTest(orig2, "write to orig2");
        writeTest(new1, "write to new1");
        writeTest(new2, "write to new2");

        Sleep(120000);
        return 0;
    }

    if (!strcmp(argv[1], "child")) {
        g_prefix = "child: ";
        dumpHandles();
        Sleep(4000);
        for (unsigned int i = 0x1; i <= 0xB0; ++i) {
            char msg[256];
            sprintf(msg, "Write to handle 0x%x", i);
            HANDLE h = reinterpret_cast<HANDLE>(i);
            writeTest(h, msg);
        }
        Sleep(120000);
        return 0;
    }

    return 0;
}