DirectPlay - Get/SetGroupData

Started by
1 comment, last by Stetto 24 years, 5 months ago
The problem is the pointer in the structure. When you call SetGroupData it just does a byte copy of the data in the structure - so it copies the value of the pointer not the board it points to.

To do what you want to do, you'd need something like this

struct GroupData {
int Rows, Cols;
char board[0]; // a placeholder for the board data
};

then when you allocate the board make a call like this:

GroupData *pData = (GroupData *)new BYTE[sizeof(GroupData)+Rows*Cols];

and when you call SetGroupData
pDP->SetGroupData(idGroup, pData, sizeof(GroupData)+Rows*Cols, dwFlags);

This will send the whole board.

------------------
-vince


-vince


Advertisement
I need some help with the GetGroupData and SetGroupData functions in DirectPlay.
Initially, this sounded like a good way to share some simple global data that changes very infrequently. However, I don't seem to be able to get it to successfully communicate some data structures. As an example, I want to use this struct:

struct {
int Rows, Cols;
char **board;
}

where board is a 2d array of char whose dimensions are set a runtime.

Does anyone know of a way to use such a structure as the Group(or Player) Data?


Stetto

Thank you. Someone else gave me a similar tip to use malloc with a board[1] placeholder, and that worked.

The only drawback is that I can't directly acces individual cells on the board with board[x][y]; I have to use board[x+y*cols].

Stetto

This topic is closed to new replies.

Advertisement