DirectPlay - Client name and sending data to specific client

Started by
5 comments, last by rip-off 16 years, 3 months ago
I work with direct play and I have several questions about. I create a server, host a session and make possible for players to connect.

case DPN_MSGID_CREATE_PLAYER:
{  
   HRESULT hr;
   PDPNMSG_CREATE_PLAYER pCreatePlayerMsg = (PDPNMSG_CREATE_PLAYER)pMsgBuffer;

   DWORD dwSize = 0;
   DPN_PLAYER_INFO* pdpPlayerInfo = NULL;
   hr = g_pDPServer->GetClientInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);

   if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
   break;
								  
   pdpPlayerInfo = (DPN_PLAYER_INFO*) new BYTE[ dwSize ];
   if( NULL == pdpPlayerInfo )
   break;

   ZeroMemory(pdpPlayerInfo, dwSize);
   pdpPlayerInfo->dwSize = sizeof(DPN_PLAYER_INFO);
   hr = g_pDPServer->GetClientInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);

   std::cout << pdpPlayerInfo->pwszName << std::endl;
   break;
}
When i run few clients, server must show names of player but he show strange characters for each one: 00B25EA8 //1 client 00B26D30 //2 client 00B26D88 //etc. I think that's the addresses of pointers in memory or something like that. So how can I show the players names normally as they are? For example in place of 00B25EA8, Player1. The second question is how can I send data to specific client. Yes I know function SendTo and her first parameter but what must I write there if I want to send something to third client for example? Must I make a array? No, dumb idea. :) Thanks for answers.
Advertisement
Use
  std::cout << *pdpPlayerInfo->pwszName << std::endl;
Think you I didn't try?
Quote:Original post by Marineio
Use
  std::cout << *pdpPlayerInfo->pwszName << std::endl;
pdpPlayerInfo is a pointer to a struct which presumably contains a wide character string, so dereferencing it will just output the first character of the string.

The problem (I think) is that std::cout doesn't seem to like wide character strings. Does it work if you do this?
std::cout << L"Testing" << std::endl;

If it does, what if you do:
std::cout << (LPCWSTR)pdpPlayerInfo->pwszName << std::endl;

Although if that doesn't work, I've no idea. I very rarely use STL iostreams. Another thing you could try is printf (Although it's horrible, I know):
printf("%S\n", pdpPlayerInfo->pwszName); (Note it's an upper case S for wide character strings).
Consider the following program:
#include <iostream>int main(){        const wchar_t *foo = L"foo";        std::cout << foo << std::endl;        std::wcout << foo << std::endl;}


When run, it outputs:
Quote:
0x804895c
foo
Quote:Original post by rip-off
Consider the following program:
*** Source Snippet Removed ***

When run, it outputs:
Quote:
0x804895c
foo
Ah, so std::cout can't handle wide character strings at all then? Any idea if there's a deliberate reason for that?
Quote:Original post by Evil Steve
Quote:Original post by rip-off
Consider the following program:
*** Source Snippet Removed ***

When run, it outputs:
Quote:
0x804895c
foo
Ah, so std::cout can't handle wide character strings at all then? Any idea if there's a deliberate reason for that?


AFAIK, std::cout (as a std::ostream, or std::basic_ostream<char>) has an overload for its template type pointer and std::wcout (as a std::wostream or std::basic_ostream<whcar_t>) similarly has an overload for wchar_t pointers.

Both have an overload for a void pointer, which is what is being used here.

I don't know if there is a reason for not having an object that supports both, but it certainly wouldn't surprise me if there wasn't such a reason.

This topic is closed to new replies.

Advertisement