Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectPlay Init Help

Started by ms291052 Feb 1, 2004 at 11:32 AM 6 replies 1.4k views
Original Post
ms291052
ms291052
I can''t seem to figure it out but Host is returing DPNERR_INVALIDDEVICEADDRESS. I read the docs and they said that means a) I used bad init code for the Address structure or b) There is already a server running on that port. I can eliminate b Because I''ve checked my net traffic and changed the port many times so that''s not the problem. So it''s my init code. I can''t find any errors though. I''ve checked all return codes (the only failed one is Host). Any ideas? Here''s the code:
void Init()
{
	HRESULT hr;
	DPN_SERVICE_PROVIDER_INFO* pSP = NULL;
	DWORD                      dwNumSP=0, dwSize=0;

	CoCreateInstance(CLSID_DirectPlay8Server, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Server, (void**)&pDPServer);
	pDPServer->Initialize(NULL, DPServerMessageHandler, 0);
	CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address, (void**)&pDPAddress);

	pDPAddress->SetSP(&CLSID_DP8SP_TCPIP);
	pDPAddress->AddComponent(DPNA_KEY_PORT, &g_Port, sizeof(DWORD), DPNA_DATATYPE_DWORD);

	pDPServer->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, pSP, &dwSize, &dwNumSP, 0 );
	pSP = (DPN_SERVICE_PROVIDER_INFO*)new BYTE[dwSize];
	hr = pDPServer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pSP, &dwSize, &dwNumSP, 0);
	if(FAILED(hr))
		cout << "EnumServiceProviders : " << hr << endl;
	pDPAddress->AddComponent(DPNA_KEY_PROVIDER, &pSP->guid, sizeof(GUID), DPNA_DATATYPE_GUID);
	delete[] pSP;

	ZeroMemory(&dpad, sizeof(DPN_APPLICATION_DESC));
	dpad.dwSize = sizeof(DPN_APPLICATION_DESC);
	dpad.pwszSessionName = L"MySession";
	dpad.pwszPassword = L"Password";
	dpad.dwMaxPlayers = 32;
	dpad.guidApplication = AppGuid;
	dpad.dwFlags = DPNSESSION_CLIENT_SERVER | DPNSESSION_REQUIREPASSWORD;
	hr = pDPServer->Host(&dpad, &pDPAddress, 1, NULL, NULL, NULL, NULL);
	if(FAILED(hr))
		cout << "Host : " << hr << endl;
}
Any light you could shed on this would be great. Thanks, ms
SelethD
SelethD
Im not sure what your problem is, however when I init directplay on my winXP it wont let me specify a port, I have to use port 0 and let winXP auto select a port.

This is a pain because then your client has to enumerate hosts to find the server

Although I guess it might be good for compatibility.

So I would suggest setting your port to 0 and then see if you get the same error. If you do, then you know its not the port for sure. If you dont get an error, then you know its the same problem I have, and no I dont know how to fix it.
ms291052
ms291052
Hey thanks for the idea, but it didn''t work. Any other possibilities?
ms291052
ms291052
bump
ms291052
ms291052
Whoopdy-doo!! The server is now officially up and running, thank you! Do you have any code like that for the client, because my client app still doesn't work. If you need it here's what I'm currently doing:

IDirectPlay8Client *StartClientServer(char* szPlayerName, char* szSessionName, char* szPassword, char* szIPAddress, DWORD dwPort)
{
IDirectPlay8Client *pDPClient;
DPN_SERVICE_PROVIDER_INFO* pSP = NULL;
IDirectPlay8Address *pDPAddress, *pDPHostAddress;
DPN_APPLICATION_DESC dpad;
DPN_PLAYER_INFO dppi;
//GUID* guidAdapter = new GUID;

WCHAR wszSessionName[256];
WCHAR wszPassword[256];
WCHAR wszIPAddress[256];
WCHAR wszPlayerName[256];

CoCreateInstance(CLSID_DirectPlay8Client, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Client, (void**)&pDPClient);
pDPClient->Initialize(NULL, DPClientMessageHandler, NULL);
CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address, (void**)&pDPAddress);
CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address, (void**)&pDPHostAddress);
pDPAddress->SetSP(&CLSID_DP8SP_TCPIP);
pDPHostAddress->SetSP(&CLSID_DP8SP_TCPIP);
mbstowcs(wszIPAddress, szIPAddress, strlen(szIPAddress)+1);
pDPHostAddress->AddComponent(DPNA_KEY_HOSTNAME, wszIPAddress, (wcslen(wszIPAddress)+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING);

pDPHostAddress->AddComponent(DPNA_KEY_PORT, &dwPort, sizeof(DWORD), DPNA_DATATYPE_DWORD);

//pDPHostAddress->AddComponent(DPNA_KEY_DEVICE, guidAdapter, sizeof(GUID), DPNA_DATATYPE_GUID);


ZeroMemory(&dppi, sizeof(DPN_PLAYER_INFO));
dppi.dwSize = sizeof(DPN_PLAYER_INFO);
dppi.dwInfoFlags = DPNINFO_NAME | DPNINFO_DATA;
mbstowcs(wszPlayerName, szPlayerName, strlen(szPlayerName+1));
dppi.pwszName = wszPlayerName;
pDPClient->SetClientInfo(&dppi, NULL, NULL, DPNSETCLIENTINFO_SYNC);
ZeroMemory(&dpad, sizeof(DPN_APPLICATION_DESC));
dpad.dwSize = sizeof(DPN_APPLICATION_DESC);
dpad.dwFlags = DPNSESSION_CLIENT_SERVER;
mbstowcs(wszSessionName, szSessionName, strlen(szSessionName)+1);
dpad.pwszSessionName = wszSessionName;
if(szPassword != NULL)
{
mbstowcs(wszPassword, szPassword, strlen(szPassword)+1);
dpad.pwszPassword = wszPassword;
dpad.dwFlags |= DPNSESSION_REQUIREPASSWORD;
}

HRESULT hr = pDPClient->Connect(&dpad, pDPHostAddress, pDPAddress, NULL, NULL, NULL, 0, NULL, NULL, DPNCONNECT_SYNC);
//DPNERR_INVALIDDEVICEADDRESS

pDPAddress->Release();
pDPHostAddress->Release();
return pDPClient;
}


Thank you SO incredibly much.

P.S. Connect too is giving me the DPN_ERR_INVALIDDEVICEADDRESS.

[edited by - ms291052 on February 3, 2004 7:36:36 AM]
ms291052
ms291052
bump

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.