Archived

This topic is now archived and is closed to further replies.

yoshscout

DirectPlay weird invalid device

Recommended Posts

before u read the code, keep in mind that if(FAILED(hr)) return; is not good practice BUT this app is my app and a breakpoint on the return statement is enough to suit me, FAILED is not an acceptable option and so that is my reasoning
	HRESULT hr;

    // Init COM so we can use CoCreateInstance
    CoInitialize(NULL);

	hr = CoCreateInstance( CLSID_DirectPlay8Server, NULL, 
							CLSCTX_INPROC_SERVER,
							IID_IDirectPlay8Server, 
							(LPVOID*) &m_pDPServer);
	if(FAILED(hr))
		return;

	DWORD dwFlags;
	#if defined(_DEBUG) || defined(DEBUG)
	    dwFlags = 0;
	#else
	    dwFlags = DPNINITIALIZE_DISABLEPARAMVAL;
	#endif

	m_pDPServer->Initialize((PVOID)this, StaticMessageHandler, dwFlags);

	// Create the device address
	IDirectPlay8Address*	m_pDeviceAddress = NULL;
	hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,	
                       CLSCTX_INPROC_SERVER,
                       IID_IDirectPlay8Address,
                       (LPVOID*) &m_pDeviceAddress );
	if(FAILED(hr))
		return;

	hr = m_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP );
	if(FAILED(hr))
		return;

	DWORD dwPort;
	#if defined(_DEBUG) || defined(DEBUG)
	    dwPort = 10111;
	#else
	    dwPort = 10115;
	#endif

	hr = m_pDeviceAddress->AddComponent( DPNA_KEY_PORT,       //pwszName
                                   &dwPort, sizeof(dwPort),   //lpvData, dwDataSize
                                   DPNA_DATATYPE_DWORD );     //dwDataType

	// Host
    DPN_PLAYER_INFO         dpPlayerInfo;
    WCHAR                   wszName[] = L"Server";
    ZeroMemory(&dpPlayerInfo, sizeof(DPN_PLAYER_INFO));
    dpPlayerInfo.dwSize = sizeof(DPN_PLAYER_INFO);
    dpPlayerInfo.dwInfoFlags = DPNINFO_NAME;
    dpPlayerInfo.pwszName = wszName;
    dpPlayerInfo.pvData = NULL;
    dpPlayerInfo.dwDataSize = NULL;
    dpPlayerInfo.dwPlayerFlags = 0;

	m_pDPServer->SetServerInfo(&dpPlayerInfo, NULL, NULL, DPNSETSERVERINFO_SYNC);

	DPN_APPLICATION_DESC	dpAppDesc;
    WCHAR                   wszSession[] = L"Ponganet";
    ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
    dpAppDesc.dwSize			= sizeof(DPN_APPLICATION_DESC);
	dpAppDesc.dwFlags			= DPNSESSION_CLIENT_SERVER|DPNSESSION_NODPNSVR;
    dpAppDesc.guidApplication	= g_guidApp;
    dpAppDesc.pwszSessionName	= wszSession;

	hr = m_pDPServer->Host(&dpAppDesc, &m_pDeviceAddress, 1,
						NULL, NULL, NULL, 0);
	if(FAILED(hr))
		return;
	else
		hr = S_OK;
[/Code]

the odd thing is that this code does not work on my computer anymore.  it used to and now it fails on the Host call, although the reference files say that Host only returns if the private app data is too large OR if the parameters are invalid, it is returning an INVALID DEVICE error code.  looks like a slip up in the documentation.  however my system has a network card as well as a usb cable modem, i have enumerated both using DirectPlay modifying the code slightly and passed each individually and they both failed with invalid device, anyone ever come acrost this before?   

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
DPNERR_INVALIDDEVICEADDRESS

Maybe the port is already in use? Check if the port is available with the DOS shell command ''netstat -a''.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
... or maybe you are now running Windows XP which has an ''Internet Connection Firewall'' fully enabled, thus preventing you from opening the port. Check http://www.microsoft.com/windowsxp/pro/using/howto/networking/icf.asp

Share this post


Link to post
Share on other sites