Hello guys,

I have this structure with another double pointer structure inside that I need to pass through named pipes with the function WriteFile from WinAPI.

typedef struct Labyrinth{
    Cell **board;
    int currentLevel;
} Labyrinth;

typedef struct Cell{    
    BOOL wall;
    BOOL player;
    BOOL object;
    BOOL enemy;
    BOOL labyrinthExit;
    int objectType;
    int objectQuantity;
} Cell;

I am passing it like this

GenerateDefaultMap(&message->game.current);

            fSuccess = WriteFile(
                hPipe,        // handle to pipe 
                &message,     // buffer to write from 
                sizeof(Message), // number of bytes to write 
                &cbWritten,   // number of bytes written 
                NULL);        // not overlapped I/O 

And I'm writing the board like this

DWORD GenerateDefaultMap(Labyrinth *labyrinth){
    int i = 0, j = 0;

    labyrinth->board = (Cell **) malloc(MIN_SIZE * sizeof(Cell *));
    for (i = 0; i < MIN_SIZE; ++i)
        labyrinth->board[i] = (Cell *) malloc(MIN_SIZE * sizeof(Cell));

    for (i = 0; i < MIN_SIZE; i++){
        for (j = 0; j < MIN_SIZE; j++){
            if (i == 0 || i == (MIN_SIZE - 1) || j == 0 || j == (MIN_SIZE - 1))
                labyrinth->board[i][j].wall = TRUE;
            else
                labyrinth->board[i][j].wall = FALSE;
        }
    }
}

When I receive it on the client side I have nothing but garbage. Could you guys point me in the right direction?

This looks incorrect from the beginning. Pointers point to memory which is memory in your app and machine. Passing pointers to another PC would be almost meaningless 99% of the time.

This article has been dead for over six months. Start a new discussion instead.