#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[]) {

    if (argc != 2) {
        printf("Child: No handle received!\n");
        return 1;
    }

    // Convert string back to HANDLE
    HANDLE hFile = (HANDLE)_strtoui64(argv[1], NULL, 10);

    if (hFile == INVALID_HANDLE_VALUE) {
        printf("Child: Invalid handle received!\n");
        return 1;
    }

    // Write to the inherited file handle

    DWORD bytesWritten;
    const char *message = "Hello from the child process!\n";
    WriteFile(hFile, message, strlen(message), &bytesWritten, NULL);

    printf("Child: Wrote to file using inherited handle.\n");

    // Close the file handle
    CloseHandle(hFile);
    return 0;
}
