Jump to content

  • Log In with Google      Sign In   
  • Create Account


DirectPlay - Get/SetGroupData


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Stetto   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 October 1999 - 09:37 AM

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



Sponsor:

#2 vince   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 October 1999 - 09:10 AM

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




#3 Stetto   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 October 1999 - 09:37 AM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS