Original Post
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