Initial commit: ROW Client source code

Game client codebase including:
- CharacterActionControl: Character and creature management
- GlobalScript: Network, items, skills, quests, utilities
- RYLClient: Main client application with GUI and event handlers
- Engine: 3D rendering engine (RYLGL)
- MemoryManager: Custom memory allocation
- Library: Third-party dependencies (DirectX, boost, etc.)
- Tools: Development utilities

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-29 16:24:34 +09:00
commit e067522598
5135 changed files with 1745744 additions and 0 deletions

View File

@@ -0,0 +1,160 @@
//----------------------------------------------------------------------------
// File: EnumSP.cpp
//
// Desc: This simple program inits DirectPlay and enumerates the available
// DirectPlay Service Providers.
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL; // DirectPlay peer object
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
HRESULT InitDirectPlay();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfoEnum = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
DWORD i;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Enumerate all the Service Providers available
hr = g_pDP->EnumServiceProviders(NULL, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%X\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders(NULL, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%X\n", hr);
goto LCleanup;
}
// Run through each provider desc printing them all out
pdnSPInfoEnum = pdnSPInfo;
for (i = 0; i < dwItems; i++)
{
printf("Found Service Provider: %S\n", pdnSPInfoEnum->pwszName);
pdnSPInfoEnum++;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages. This tutorial doesn't repond to any
// DirectPlay messages
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId,
PVOID pMsgBuffer)
{
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
SAFE_RELEASE(g_pDP);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="EnumSP" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=EnumSP - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "EnumSP.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "EnumSP.mak" CFG="EnumSP - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "EnumSP - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "EnumSP - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "EnumSP - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "EnumSP - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "EnumSP - Win32 Release"
# Name "EnumSP - Win32 Debug"
# Begin Source File
SOURCE=.\EnumSP.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "EnumSP"=.\EnumSP.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on EnumSP.dsp
!IF "$(CFG)" == ""
CFG=EnumSP - Win32 Debug
!MESSAGE No configuration specified. Defaulting to EnumSP - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "EnumSP - Win32 Release" && "$(CFG)" != "EnumSP - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "EnumSP.mak" CFG="EnumSP - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "EnumSP - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "EnumSP - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "EnumSP - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\EnumSP.exe"
CLEAN :
-@erase "$(INTDIR)\EnumSP.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\EnumSP.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\EnumSP.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\EnumSP.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\EnumSP.pdb" /machine:I386 /out:"$(OUTDIR)\EnumSP.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\EnumSP.obj"
"$(OUTDIR)\EnumSP.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "EnumSP - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\EnumSP.exe"
CLEAN :
-@erase "$(INTDIR)\EnumSP.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\EnumSP.exe"
-@erase "$(OUTDIR)\EnumSP.ilk"
-@erase "$(OUTDIR)\EnumSP.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\EnumSP.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\EnumSP.pdb" /debug /machine:I386 /out:"$(OUTDIR)\EnumSP.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\EnumSP.obj"
"$(OUTDIR)\EnumSP.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("EnumSP.dep")
!INCLUDE "EnumSP.dep"
!ELSE
!MESSAGE Warning: cannot find "EnumSP.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "EnumSP - Win32 Release" || "$(CFG)" == "EnumSP - Win32 Debug"
SOURCE=.\EnumSP.cpp
"$(INTDIR)\EnumSP.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,16 @@
//-----------------------------------------------------------------------------
// Name: EnumSP DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The EnumSP tutorial is the first tutorial for inits DirectPlay and enumerates
the available DirectPlay Service Providers.
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut01_EnumSP

View File

@@ -0,0 +1,275 @@
//----------------------------------------------------------------------------
// File: Host.cpp
//
// Desc: This simple program builds upon the EnumSP.cpp tutorial and adds
// creation of an Address Object and hosting a session
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <conio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {5e4ab2ee-6a50-4614-807e-c632807b5eb1}
GUID g_guidApp = {0x5e4ab2ee, 0x6a50, 0x4614, {0x80, 0x7e, 0xc6, 0x32, 0x80, 0x7b, 0x5e, 0xb1}};
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT HostSession();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
// Wait for user action
printf("Press a key to exit\n");
_getch();
LCleanup:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages. This tutorial doesn't repond to any
// DirectPlay messages
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, NULL,
&dwSize, &dwItems, 0 );
if( hr != DPNERR_BUFFERTOOSMALL )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, pdnSPInfo,
&dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host( &dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pDP);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Host" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Host - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Host.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Host.mak" CFG="Host - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Host - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Host - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Host - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Host - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Host - Win32 Release"
# Name "Host - Win32 Debug"
# Begin Source File
SOURCE=.\Host.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Host"=.\Host.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on Host.dsp
!IF "$(CFG)" == ""
CFG=Host - Win32 Debug
!MESSAGE No configuration specified. Defaulting to Host - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "Host - Win32 Release" && "$(CFG)" != "Host - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Host.mak" CFG="Host - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Host - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Host - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "Host - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\Host.exe"
CLEAN :
-@erase "$(INTDIR)\Host.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\Host.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\Host.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Host.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\Host.pdb" /machine:I386 /out:"$(OUTDIR)\Host.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Host.obj"
"$(OUTDIR)\Host.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "Host - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\Host.exe"
CLEAN :
-@erase "$(INTDIR)\Host.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\Host.exe"
-@erase "$(OUTDIR)\Host.ilk"
-@erase "$(OUTDIR)\Host.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Host.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\Host.pdb" /debug /machine:I386 /out:"$(OUTDIR)\Host.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Host.obj"
"$(OUTDIR)\Host.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("Host.dep")
!INCLUDE "Host.dep"
!ELSE
!MESSAGE Warning: cannot find "Host.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "Host - Win32 Release" || "$(CFG)" == "Host - Win32 Debug"
SOURCE=.\Host.cpp
"$(INTDIR)\Host.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: Host DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Host tutorial is the 2nd tutorial for DirectPlay. It builds upon the last
tutorial and adds creation of an Address Object and hosting a session.
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut02_Host

View File

@@ -0,0 +1,558 @@
//----------------------------------------------------------------------------
// File: EnumHosts.cpp
//
// Desc: This simple program builds upon the last tutorial and adds enumerating
// the hosts at a given target address
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <conio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
BOOL g_bHost;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {358E1C8D-DB4A-4867-B2C3-DEF3F5046B17}
GUID g_guidApp = { 0x358e1c8d, 0xdb4a, 0x4867, { 0xb2, 0xc3, 0xde, 0xf3, 0xf5, 0x4, 0x6b, 0x17 } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LFail;
}
InitializeCriticalSection(&g_csHostList);
// Get the necessary user input on whether they are hosting or connecting
do
{
printf("Please select one.\n1. Host\n2. Connect\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_HOST && iUserChoice != USER_CONNECT);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LFail;
}
if( iUserChoice == USER_HOST )
{
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LFail;
}
}
else
{
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LFail;
}
}
LFail:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LFail;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LFail;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LFail;
}
LFail:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, NULL,
&dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LFail;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, pdnSPInfo,
&dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LFail;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LFail:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages. This tutorial only responds to the
// DPN_MSGID_ENUM_HOSTS_RESPONSE message.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId,
PVOID pMsgBuffer )
{
HRESULT hr = S_OK;
switch( dwMessageId )
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
HOST_NODE* pHostNode = NULL;
DWORD dwNumChars = 0;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress( wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LFail;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDP->EnumHosts( &dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) ) // dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LFail;
}
// Go through and print out all the hosts URL's that we found
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext, dwNumChars = 0)
{
hr = pHostNode->pHostAddress->GetURLW(NULL, &dwNumChars);
if( hr == DPNERR_BUFFERTOOSMALL)
{
pwszURL = new WCHAR[dwNumChars];
if( pwszURL && SUCCEEDED(hr = pHostNode->pHostAddress->GetURLW(pwszURL, &dwNumChars ) ) )
{
printf("Found a Session Called %S at Address: %S\n", pHostNode->pwszSessionName, pwszURL);
}
}
SAFE_DELETE_ARRAY(pwszURL);
}
LeaveCriticalSection(&g_csHostList);
LFail:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LFail;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LFail;
}
LFail:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LFail;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LFail;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent( DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LFail;
}
LFail:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
WCHAR wszSession[128];
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host( &dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LFail;
}
else
{
printf("Currently Hosting...\n");
printf("Press a key to exit\n");
_getch();
}
LFail:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDP);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="EnumHosts" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=EnumHosts - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "EnumHosts.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "EnumHosts.mak" CFG="EnumHosts - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "EnumHosts - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "EnumHosts - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "EnumHosts - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "EnumHosts - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "EnumHosts - Win32 Release"
# Name "EnumHosts - Win32 Debug"
# Begin Source File
SOURCE=.\EnumHosts.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "EnumHosts"=.\EnumHosts.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on EnumHosts.dsp
!IF "$(CFG)" == ""
CFG=EnumHosts - Win32 Debug
!MESSAGE No configuration specified. Defaulting to EnumHosts - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "EnumHosts - Win32 Release" && "$(CFG)" != "EnumHosts - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "EnumHosts.mak" CFG="EnumHosts - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "EnumHosts - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "EnumHosts - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "EnumHosts - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\EnumHosts.exe"
CLEAN :
-@erase "$(INTDIR)\EnumHosts.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\EnumHosts.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\EnumHosts.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\EnumHosts.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\EnumHosts.pdb" /machine:I386 /out:"$(OUTDIR)\EnumHosts.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\EnumHosts.obj"
"$(OUTDIR)\EnumHosts.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "EnumHosts - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\EnumHosts.exe"
CLEAN :
-@erase "$(INTDIR)\EnumHosts.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\EnumHosts.exe"
-@erase "$(OUTDIR)\EnumHosts.ilk"
-@erase "$(OUTDIR)\EnumHosts.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\EnumHosts.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\EnumHosts.pdb" /debug /machine:I386 /out:"$(OUTDIR)\EnumHosts.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\EnumHosts.obj"
"$(OUTDIR)\EnumHosts.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("EnumHosts.dep")
!INCLUDE "EnumHosts.dep"
!ELSE
!MESSAGE Warning: cannot find "EnumHosts.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "EnumHosts - Win32 Release" || "$(CFG)" == "EnumHosts - Win32 Debug"
SOURCE=.\EnumHosts.cpp
"$(INTDIR)\EnumHosts.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: EnumHosts DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The EnumHosts tutorial is the 3nd tutorial for DirectPlay. It builds upon the last
tutorial and adds the enumerating the hosts at a given target address
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut03_EnumHosts

View File

@@ -0,0 +1,595 @@
//----------------------------------------------------------------------------
// File: Connect.cpp
//
// Desc: This simple program builds upon the last tutorial and adds connecting
// to a host
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
BOOL g_bHost;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // // {A8F02BED-B09A-4911-A1CD-DB02578B9C8F}
GUID g_guidApp = { 0xa8f02bed, 0xb09a, 0x4911, { 0xa1, 0xcd, 0xdb, 0x2, 0x57, 0x8b, 0x9c, 0x8f } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts();
HRESULT ConnectToSession();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
InitializeCriticalSection(&g_csHostList);
// Get the necessary user input on whether they are hosting or connecting
do
{
printf("Please select one.\n1. Host\n2. Connect\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_HOST && iUserChoice != USER_CONNECT);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( iUserChoice == USER_HOST)
{
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
}
else
{
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = ConnectToSession() ) )
{
printf("Failed Connect to Host: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("\nConnection Successful.\n");
}
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages. This tutorial only responds to the
// DPN_MSGID_ENUM_HOSTS_RESPONSE message.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId,
PVOID pMsgBuffer )
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode)
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress( wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LCleanup;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDP->EnumHosts(&dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) )// dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: Host()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
WCHAR wszSession[128];
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host( &dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: ConnectToSession()
// Desc: Connects to a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT ConnectToSession()
{
HRESULT hr = E_FAIL;
DPN_APPLICATION_DESC dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
// Simply connect to the first one in the list
EnterCriticalSection(&g_csHostList);
if( g_pHostList && SUCCEEDED(hr = g_pHostList->pHostAddress->Duplicate(&pHostAddress ) ) )
{
hr = g_pDP->Connect(&dpnAppDesc, // pdnAppDesc
pHostAddress, // pHostAddr
g_pDeviceAddress, // pDeviceInfo
NULL, // pdnSecurity
NULL, // pdnCredentials
NULL, 0, // pvUserConnectData/Size
NULL, // pvPlayerContext
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNCONNECT_SYNC); // dwFlags
if( FAILED( hr))
printf("Failed Connecting to Host: 0x%x\n", hr);
}
else
{
printf("Failed Duplicating Host Address: 0x%x\n", hr);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(pHostAddress);
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDP);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Connect" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Connect - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Connect.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Connect.mak" CFG="Connect - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Connect - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Connect - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Connect - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Connect - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Connect - Win32 Release"
# Name "Connect - Win32 Debug"
# Begin Source File
SOURCE=.\Connect.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Connect"=.\Connect.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on Connect.dsp
!IF "$(CFG)" == ""
CFG=Connect - Win32 Debug
!MESSAGE No configuration specified. Defaulting to Connect - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "Connect - Win32 Release" && "$(CFG)" != "Connect - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Connect.mak" CFG="Connect - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Connect - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Connect - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "Connect - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\Connect.exe"
CLEAN :
-@erase "$(INTDIR)\Connect.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\Connect.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\Connect.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Connect.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\Connect.pdb" /machine:I386 /out:"$(OUTDIR)\Connect.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Connect.obj"
"$(OUTDIR)\Connect.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "Connect - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\Connect.exe"
CLEAN :
-@erase "$(INTDIR)\Connect.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\Connect.exe"
-@erase "$(OUTDIR)\Connect.ilk"
-@erase "$(OUTDIR)\Connect.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Connect.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\Connect.pdb" /debug /machine:I386 /out:"$(OUTDIR)\Connect.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Connect.obj"
"$(OUTDIR)\Connect.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("Connect.dep")
!INCLUDE "Connect.dep"
!ELSE
!MESSAGE Warning: cannot find "Connect.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "Connect - Win32 Release" || "$(CFG)" == "Connect - Win32 Debug"
SOURCE=.\Connect.cpp
"$(INTDIR)\Connect.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: Connect DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Connect tutorial is the 4th tutorial for DirectPlay. It builds upon
the last tutorial and adds the enumerating the hosts at a given target address
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut04_Connect

View File

@@ -0,0 +1,651 @@
//----------------------------------------------------------------------------
// File: Send.cpp
//
// Desc: This simple program builds upon the last tutorial and adds a send
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
BOOL g_bHost;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {590E16DD-538F-40fb-A7DF-9654EA6BE71E}
GUID g_guidApp = { 0x590e16dd, 0x538f, 0x40fb, { 0xa7, 0xdf, 0x96, 0x54, 0xea, 0x6b, 0xe7, 0x1e } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts();
HRESULT ConnectToSession();
HRESULT SendDirectPlayMessage();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
#define USER_SEND 2
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
InitializeCriticalSection(&g_csHostList);
// Get the necessary user input on whether they are hosting or connecting
do
{
printf("Please select one.\n1. Host\n2. Connect\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_HOST && iUserChoice != USER_CONNECT);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( iUserChoice == USER_HOST)
{
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
}
else
{
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = ConnectToSession() ) )
{
printf("Failed Connect to Host: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("\nConnection Successful.\n");
}
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n2. Send Data\n");
scanf("%d", &iUserChoice);
if( iUserChoice == USER_SEND)
{
if( FAILED( hr = SendDirectPlayMessage() ) )
{
printf("Failed To Send Data: 0x%X\n", hr);
goto LCleanup;
}
}
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId,
PVOID pMsgBuffer)
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode)
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;
pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress(wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LCleanup;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDP->EnumHosts( &dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) )// dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP( &CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent( DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
WCHAR wszSession[128];
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host( &dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: ConnectToSession()
// Desc: Connects to a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT ConnectToSession()
{
HRESULT hr = E_FAIL;
DPN_APPLICATION_DESC dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
// Simply connect to the first one in the list
EnterCriticalSection(&g_csHostList);
if( g_pHostList && SUCCEEDED(hr = g_pHostList->pHostAddress->Duplicate(&pHostAddress ) ) )
{
hr = g_pDP->Connect( &dpnAppDesc, // pdnAppDesc
pHostAddress, // pHostAddr
g_pDeviceAddress, // pDeviceInfo
NULL, // pdnSecurity
NULL, // pdnCredentials
NULL, 0, // pvUserConnectData/Size
NULL, // pvPlayerContext
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNCONNECT_SYNC); // dwFlags
if( FAILED( hr))
printf("Failed Connecting to Host: 0x%x\n", hr);
}
else
{
printf("Failed Duplicating Host Address: 0x%x\n", hr);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(pHostAddress);
return hr;
}
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];
// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);
dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);
if( FAILED( hr = g_pDP->SendTo( DPNID_ALL_PLAYERS_GROUP, // dpnid
&dpnBuffer, // pBufferDesc
1, // cBufferDesc
0, // dwTimeOut
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNSEND_SYNC |
DPNSEND_NOLOOPBACK ) ) ) // dwFlags
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDP);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Send" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Send - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Send.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Send.mak" CFG="Send - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Send - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Send - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Send - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Send - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Send - Win32 Release"
# Name "Send - Win32 Debug"
# Begin Source File
SOURCE=.\Send.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Send"=.\Send.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on Send.dsp
!IF "$(CFG)" == ""
CFG=Send - Win32 Debug
!MESSAGE No configuration specified. Defaulting to Send - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "Send - Win32 Release" && "$(CFG)" != "Send - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Send.mak" CFG="Send - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Send - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Send - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "Send - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\Send.exe"
CLEAN :
-@erase "$(INTDIR)\Send.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\Send.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\Send.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Send.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\Send.pdb" /machine:I386 /out:"$(OUTDIR)\Send.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Send.obj"
"$(OUTDIR)\Send.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "Send - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\Send.exe"
CLEAN :
-@erase "$(INTDIR)\Send.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\Send.exe"
-@erase "$(OUTDIR)\Send.ilk"
-@erase "$(OUTDIR)\Send.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Send.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\Send.pdb" /debug /machine:I386 /out:"$(OUTDIR)\Send.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Send.obj"
"$(OUTDIR)\Send.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("Send.dep")
!INCLUDE "Send.dep"
!ELSE
!MESSAGE Warning: cannot find "Send.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "Send - Win32 Release" || "$(CFG)" == "Send - Win32 Debug"
SOURCE=.\Send.cpp
"$(INTDIR)\Send.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: Send DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Send tutorial is the 5th tutorial for DirectPlay. It builds upon the last
tutorial and adds a send
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut05_Send

View File

@@ -0,0 +1,702 @@
//----------------------------------------------------------------------------
// File: HostMigration.cpp
//
// Desc: This simple program builds upon the last tutorial and adds host migration
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
BOOL g_bHost;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
DPNID g_dpnidLocalPlayer = 0;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {2C6FEE8B-3088-4b74-B38F-A16D02DAD246}
GUID g_guidApp = { 0x2c6fee8b, 0x3088, 0x4b74, { 0xb3, 0x8f, 0xa1, 0x6d, 0x2, 0xda, 0xd2, 0x46 } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts();
HRESULT ConnectToSession();
HRESULT SendDirectPlayMessage();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
#define USER_SEND 2
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
InitializeCriticalSection(&g_csHostList);
// Get the necessary user input on whether they are hosting or connecting
do
{
printf("Please select one.\n1. Host\n2. Connect\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_HOST && iUserChoice != USER_CONNECT);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( iUserChoice == USER_HOST)
{
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
}
else
{
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = ConnectToSession() ) )
{
printf("Failed Connect to Host: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("\nConnection Successful.\n");
}
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n2. Send Data\n");
scanf("%d", &iUserChoice);
if( iUserChoice == USER_SEND)
{
if( FAILED( hr = SendDirectPlayMessage() ) )
{
printf("Failed To Send Data: 0x%X\n", hr);
goto LCleanup;
}
}
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance( CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders( &CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId,
PVOID pMsgBuffer )
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode)
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;
pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
case DPN_MSGID_HOST_MIGRATE:
{
PDPNMSG_HOST_MIGRATE pHostMigrateMsg;
pHostMigrateMsg = (PDPNMSG_HOST_MIGRATE) pMsgBuffer;
printf("\nHost Migration Has Occured.\n");
// See if we are the new host
if( pHostMigrateMsg->dpnidNewHost == g_dpnidLocalPlayer)
printf("You are the New Host\n");
else
printf("DPNID of New Host is %d\n", pHostMigrateMsg->dpnidNewHost);
break;
}
case DPN_MSGID_CREATE_PLAYER:
{
PDPNMSG_CREATE_PLAYER pCreatePlayerMsg;
DWORD dwSize = 0;
DPN_PLAYER_INFO* pdpPlayerInfo = NULL;
pCreatePlayerMsg = (PDPNMSG_CREATE_PLAYER)pMsgBuffer;
// check to see if we are the player being created
hr = g_pDP->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);
if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed GetPeerInfo: 0x%X\n", hr);
return hr;
}
pdpPlayerInfo = (DPN_PLAYER_INFO*) new BYTE[dwSize];
ZeroMemory(pdpPlayerInfo, dwSize);
pdpPlayerInfo->dwSize = sizeof(DPN_PLAYER_INFO);
if( FAILED( hr = g_pDP->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0 ) ) )
{
printf("Failed GetPeerInfo: 0x%X\n", hr);
goto Error_DPN_MSGID_CREATE_PLAYER;
}
if( pdpPlayerInfo->dwPlayerFlags & DPNPLAYER_LOCAL)
g_dpnidLocalPlayer = pCreatePlayerMsg->dpnidPlayer;
Error_DPN_MSGID_CREATE_PLAYER:
SAFE_DELETE_ARRAY(pdpPlayerInfo);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress(wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LCleanup;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDP->EnumHosts(&dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) )// dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
WCHAR wszSession[128];
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
dpAppDesc.dwFlags = DPNSESSION_MIGRATE_HOST;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host( &dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: ConnectToSession()
// Desc: Connects to a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT ConnectToSession()
{
HRESULT hr = E_FAIL;
DPN_APPLICATION_DESC dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
// Simply connect to the first one in the list
EnterCriticalSection(&g_csHostList);
if( g_pHostList && SUCCEEDED(hr = g_pHostList->pHostAddress->Duplicate(&pHostAddress ) ) )
{
hr = g_pDP->Connect(&dpnAppDesc, // pdnAppDesc
pHostAddress, // pHostAddr
g_pDeviceAddress, // pDeviceInfo
NULL, // pdnSecurity
NULL, // pdnCredentials
NULL, 0, // pvUserConnectData/Size
NULL, // pvPlayerContext
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNCONNECT_SYNC); // dwFlags
if( FAILED( hr))
printf("Failed Connecting to Host: 0x%x\n", hr);
}
else
{
printf("Failed Duplicating Host Address: 0x%x\n", hr);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(pHostAddress);
return hr;
}
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];
// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);
dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);
if( FAILED( hr = g_pDP->SendTo( DPNID_ALL_PLAYERS_GROUP, // dpnid
&dpnBuffer, // pBufferDesc
1, // cBufferDesc
0, // dwTimeOut
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNSEND_SYNC |
DPNSEND_NOLOOPBACK ) ) ) // dwFlags
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDP);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="HostMigration" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=HostMigration - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "HostMigration.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "HostMigration.mak" CFG="HostMigration - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "HostMigration - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "HostMigration - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "HostMigration - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "HostMigration - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "HostMigration - Win32 Release"
# Name "HostMigration - Win32 Debug"
# Begin Source File
SOURCE=.\HostMigration.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "HostMigration"=.\HostMigration.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on HostMigration.dsp
!IF "$(CFG)" == ""
CFG=HostMigration - Win32 Debug
!MESSAGE No configuration specified. Defaulting to HostMigration - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "HostMigration - Win32 Release" && "$(CFG)" != "HostMigration - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "HostMigration.mak" CFG="HostMigration - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "HostMigration - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "HostMigration - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "HostMigration - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\HostMigration.exe"
CLEAN :
-@erase "$(INTDIR)\HostMigration.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\HostMigration.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\HostMigration.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\HostMigration.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\HostMigration.pdb" /machine:I386 /out:"$(OUTDIR)\HostMigration.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\HostMigration.obj"
"$(OUTDIR)\HostMigration.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "HostMigration - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\HostMigration.exe"
CLEAN :
-@erase "$(INTDIR)\HostMigration.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\HostMigration.exe"
-@erase "$(OUTDIR)\HostMigration.ilk"
-@erase "$(OUTDIR)\HostMigration.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\HostMigration.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\HostMigration.pdb" /debug /machine:I386 /out:"$(OUTDIR)\HostMigration.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\HostMigration.obj"
"$(OUTDIR)\HostMigration.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("HostMigration.dep")
!INCLUDE "HostMigration.dep"
!ELSE
!MESSAGE Warning: cannot find "HostMigration.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "HostMigration - Win32 Release" || "$(CFG)" == "HostMigration - Win32 Debug"
SOURCE=.\HostMigration.cpp
"$(INTDIR)\HostMigration.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: HostMigration DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The HostMigration tutorial is the 6th tutorial for DirectPlay. It builds upon the last
tutorial and adds host migration
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut06_HostMigration

View File

@@ -0,0 +1,970 @@
//----------------------------------------------------------------------------
// File: LobbyLaunch.cpp
//
// Desc: This simple program builds upon the last tutorial and adds lobby
// launching
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
#include <dplobby8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Peer* g_pDP = NULL;
IDirectPlay8LobbiedApplication* g_pLobbyApp = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
DPNHANDLE g_hLobbyHandle = NULL;
BOOL g_bLobbyLaunched = FALSE;
BOOL g_bHost;
BOOL g_bRegister = FALSE;
BOOL g_bUnRegister = FALSE;
WCHAR* g_wszPath = NULL;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
DPNID g_dpnidLocalPlayer = 0;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {C301FCED-E884-41a9-94D7-DE66943EC7DB}
GUID g_guidApp = { 0xc301fced, 0xe884, 0x41a9, { 0x94, 0xd7, 0xde, 0x66, 0x94, 0x3e, 0xc7, 0xdb } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
HRESULT WINAPI LobbyAppMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT HostSession();
HRESULT EnumDirectPlayHosts();
HRESULT ConnectToSession();
HRESULT SendDirectPlayMessage();
HRESULT Register();
HRESULT UnRegister();
HRESULT LobbyLaunch();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
#define USER_SEND 2
#define CMDLINE_REGISTER "register"
#define CMDLINE_UNREGISTER "unregister"
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
int i;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
InitializeCriticalSection(&g_csHostList);
// Process the args
for (i = 1; i < argc, argv[i] != NULL; i++)
{
if( !(strcmp(CMDLINE_REGISTER, argv[i] ) ) )
{
g_bRegister = TRUE;
g_wszPath = new WCHAR[strlen(argv[0]) + 1];
if( !g_wszPath)
{
printf("Failed allocating string\n");
goto LCleanup;
}
MultiByteToWideChar(CP_ACP, 0, argv[0], -1, g_wszPath, strlen(argv[0]) + 1);
}
else if( !strcmp(CMDLINE_UNREGISTER, argv[i]))
{
g_bUnRegister = TRUE;
}
else if( !strcmp("-?", argv[i]))
{
printf("\nUsage: register/unregister\n");
goto LCleanup;
}
}
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
if( g_bRegister )
{
if( FAILED( hr = Register() ) )
{
printf("Failed To Register: 0x%X\n", hr);
}
goto LCleanup;
}
else if( g_bUnRegister )
{
if( FAILED( hr = UnRegister() ) )
{
printf("Failed To Unregister: 0x%X\n", hr);
}
goto LCleanup;
}
// See if we were lobby launched or not
if( g_bLobbyLaunched )
{
if( FAILED( hr = LobbyLaunch() ) )
{
printf("Failed be Lobby Launched: 0x%X\n", hr);
goto LCleanup;
}
}
else
{
// Get the necessary user input on whether they are hosting or connecting
do
{
printf("Please select one.\n1. Host\n2. Connect\n");
scanf("%d", &iUserChoice);
} while (iUserChoice != USER_HOST && iUserChoice != USER_CONNECT);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( iUserChoice == USER_HOST)
{
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
}
else
{
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = ConnectToSession() ) )
{
printf("Failed Connect to Host: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("\nConnection Successful.\n");
}
}
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n2. Send Data\n");
scanf("%d", &iUserChoice);
if( iUserChoice == USER_SEND)
{
if( FAILED( hr = SendDirectPlayMessage() ) )
{
printf("Failed To Send Data: 0x%X\n", hr);
goto LCleanup;
}
}
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// Cleanup COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Peer Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Peer, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Peer,
(LPVOID*) &g_pDP ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Create the IDirectPlay8LobbiedApplication Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8LobbiedApplication, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8LobbiedApplication,
(LPVOID*) &g_pLobbyApp ) ) )
{
printf("Failed Creating the IDirectPlay8LobbiedApplication Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDP->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Init the Lobby interface
if( FAILED( hr = g_pLobbyApp->Initialize(NULL, LobbyAppMessageHandler, &g_hLobbyHandle, 0 ) ) )
{
printf("Failed Initializing Lobby: 0x%X\n", hr);
goto LCleanup;
}
else
g_bLobbyLaunched = (g_hLobbyHandle != NULL);
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDP->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode)
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;
pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
case DPN_MSGID_HOST_MIGRATE:
{
PDPNMSG_HOST_MIGRATE pHostMigrateMsg;
pHostMigrateMsg = (PDPNMSG_HOST_MIGRATE) pMsgBuffer;
printf("\nHost Migration Has Occured.\n");
// See if we are the new host
if( pHostMigrateMsg->dpnidNewHost == g_dpnidLocalPlayer)
printf("You are the New Host\n");
else
printf("DPNID of New Host is %d\n", pHostMigrateMsg->dpnidNewHost);
break;
}
case DPN_MSGID_CREATE_PLAYER:
{
PDPNMSG_CREATE_PLAYER pCreatePlayerMsg;
DWORD dwSize = 0;
DPN_PLAYER_INFO* pdpPlayerInfo = NULL;
pCreatePlayerMsg = (PDPNMSG_CREATE_PLAYER)pMsgBuffer;
// check to see if we are the player being created
hr = g_pDP->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0);
if( FAILED( hr) && hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed GetPeerInfo: 0x%X\n", hr);
return hr;
}
pdpPlayerInfo = (DPN_PLAYER_INFO*) new BYTE[dwSize];
ZeroMemory(pdpPlayerInfo, dwSize);
pdpPlayerInfo->dwSize = sizeof(DPN_PLAYER_INFO);
if( FAILED( hr = g_pDP->GetPeerInfo(pCreatePlayerMsg->dpnidPlayer, pdpPlayerInfo, &dwSize, 0 ) ) )
{
printf("Failed GetPeerInfo: 0x%X\n", hr);
goto Error_DPN_MSGID_CREATE_PLAYER;
}
if( pdpPlayerInfo->dwPlayerFlags & DPNPLAYER_LOCAL)
g_dpnidLocalPlayer = pCreatePlayerMsg->dpnidPlayer;
Error_DPN_MSGID_CREATE_PLAYER:
SAFE_DELETE_ARRAY(pdpPlayerInfo);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: LobbyAppMessageHandler
// Desc: Handler for DirectPlay lobby messages
//-----------------------------------------------------------------------------
HRESULT WINAPI LobbyAppMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPL_MSGID_CONNECT:
{
PDPL_MESSAGE_CONNECT pConnectMsg;
PDPL_CONNECTION_SETTINGS pSettings;
pConnectMsg = (PDPL_MESSAGE_CONNECT)pMsgBuffer;
pSettings = pConnectMsg->pdplConnectionSettings;
// Register the lobby with directplay so we get automatic notifications
hr = g_pDP->RegisterLobby(pConnectMsg->hConnectId, g_pLobbyApp, DPNLOBBY_REGISTER);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress(wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LCleanup;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDP->EnumHosts( &dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) )// dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
WCHAR wszSession[128];
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
dpAppDesc.dwFlags = DPNSESSION_MIGRATE_HOST;
// We are now ready to host the app
if( FAILED( hr = g_pDP->Host(&dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: ConnectToSession()
// Desc: Connects to a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT ConnectToSession()
{
HRESULT hr = E_FAIL;
DPN_APPLICATION_DESC dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
// Simply connect to the first one in the list
EnterCriticalSection(&g_csHostList);
if( g_pHostList && SUCCEEDED(hr = g_pHostList->pHostAddress->Duplicate(&pHostAddress ) ) )
{
hr = g_pDP->Connect(&dpnAppDesc, // pdnAppDesc
pHostAddress, // pHostAddr
g_pDeviceAddress, // pDeviceInfo
NULL, // pdnSecurity
NULL, // pdnCredentials
NULL, 0, // pvUserConnectData/Size
NULL, // pvPlayerContext
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNCONNECT_SYNC); // dwFlags
if( FAILED( hr))
printf("Failed Connecting to Host: 0x%x\n", hr);
}
else
{
printf("Failed Duplicating Host Address: 0x%x\n", hr);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(pHostAddress);
return hr;
}
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];
// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);
dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);
if( FAILED( hr = g_pDP->SendTo(DPNID_ALL_PLAYERS_GROUP, // dpnid
&dpnBuffer, // pBufferDesc
1, // cBufferDesc
0, // dwTimeOut
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNSEND_SYNC |
DPNSEND_NOLOOPBACK ) ) ) // dwFlags
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: Register()
// Desc: Register app as lobby launchable
//-----------------------------------------------------------------------------
HRESULT Register()
{
HRESULT hr = S_OK;
DPL_PROGRAM_DESC dplDesc;
WCHAR* pwszPath = NULL;
WCHAR* pwszExecutable = NULL;
int i;
ZeroMemory(&dplDesc, sizeof(DPL_PROGRAM_DESC));
dplDesc.dwSize = sizeof(DPL_PROGRAM_DESC);
dplDesc.guidApplication = g_guidApp;
// We need to parse out the path and the exe name from the input value
for (i = wcslen(g_wszPath); i >=0 && g_wszPath[i] != L'\\'; i--);
pwszPath = new WCHAR[i + 1];
if( pwszPath == NULL)
{
printf("Failed parsing path.");
hr = E_FAIL;
goto LCleanup;
}
wcsncpy(pwszPath, g_wszPath, i);
pwszPath[i] = L'\0';
pwszExecutable = g_wszPath + i + 1;
dplDesc.pwszApplicationName = pwszExecutable;
dplDesc.pwszExecutableFilename = pwszExecutable;
dplDesc.pwszExecutablePath = pwszPath;
hr = g_pLobbyApp->RegisterProgram(&dplDesc, 0);
LCleanup:
SAFE_DELETE_ARRAY(pwszPath);
return hr;
}
//-----------------------------------------------------------------------------
// Name: UnRegister()
// Desc: Unregister app as lobby launchable
//-----------------------------------------------------------------------------
HRESULT UnRegister()
{
HRESULT hr = S_OK;
hr = g_pLobbyApp->UnRegisterProgram(&g_guidApp, 0);
return hr;
}
//-----------------------------------------------------------------------------
// Name: LobbyLaunch()
// Desc: Host or connect to session based on lobby launch settings
//-----------------------------------------------------------------------------
HRESULT LobbyLaunch()
{
HRESULT hr = S_OK;
DPL_CONNECTION_SETTINGS* pSettings = NULL;
DWORD dwSettingsSize = 0;
// Get the lobby connection data
// First see how big a buffer we need
hr = g_pLobbyApp->GetConnectionSettings(g_hLobbyHandle, pSettings, &dwSettingsSize, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed GetConnectionSettings: 0x%x\n", hr);
goto LCleanup;
}
pSettings = (DPL_CONNECTION_SETTINGS*) new BYTE[dwSettingsSize];
if( pSettings == NULL)
{
printf("Failed Allocating Buffer: 0x%x\n");
hr = E_FAIL;
goto LCleanup;
}
if( FAILED( hr = g_pLobbyApp->GetConnectionSettings(g_hLobbyHandle, pSettings, &dwSettingsSize, 0 ) ) )
{
printf("Failed GetConnectionSettings: 0x%x\n", hr);
goto LCleanup;
}
if( pSettings->dwFlags & DPLCONNECTSETTINGS_HOST)
{
// We are to host the game
if( FAILED( hr = g_pDP->Host(&pSettings->dpnAppDesc, // dpnAppDesc
pSettings->ppdp8DeviceAddresses,// prgpDeviceInfo
pSettings->cNumDeviceAddresses, // cDeviceInfo
NULL, NULL, // Security
NULL, // pvPlayerContext
0 ) ) ) // dwFlags
{
printf("Failed Host: 0x%x\n", hr);
goto LCleanup;
}
}
else
{
// We need to connect
if( FAILED( hr = g_pDP->Connect(&pSettings->dpnAppDesc, // pdnAppDesc
pSettings->pdp8HostAddress, // pHostAddr
pSettings->ppdp8DeviceAddresses[0], // pDeviceInfo
NULL, NULL, // Security
NULL, 0, // pvUserConnectData/Size
NULL, // pvPlayerContext
NULL, NULL, // pvAsyncContext/Handle
DPNCONNECT_SYNC ) ) ) // dwFlags
{
printf("Failed Lobby App Connect: 0x%x\n", hr);
goto LCleanup;
}
}
LCleanup:
if( pSettings)
{
SAFE_RELEASE(pSettings->pdp8HostAddress);
for (DWORD dwIndex = 0; dwIndex < pSettings->cNumDeviceAddresses; dwIndex++)
{
SAFE_RELEASE(pSettings->ppdp8DeviceAddresses[dwIndex]);
}
}
SAFE_DELETE_ARRAY(pSettings);
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Cleanup DirectPlay
if( g_pDP)
g_pDP->Close(0);
if( g_pLobbyApp)
g_pLobbyApp->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDP);
SAFE_RELEASE(g_pLobbyApp);
SAFE_DELETE_ARRAY(g_wszPath);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="LobbyLaunch" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=LobbyLaunch - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "LobbyLaunch.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "LobbyLaunch.mak" CFG="LobbyLaunch - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "LobbyLaunch - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "LobbyLaunch - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "LobbyLaunch - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "LobbyLaunch - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "LobbyLaunch - Win32 Release"
# Name "LobbyLaunch - Win32 Debug"
# Begin Source File
SOURCE=.\LobbyLaunch.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "LobbyLaunch"=.\LobbyLaunch.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on LobbyLaunch.dsp
!IF "$(CFG)" == ""
CFG=LobbyLaunch - Win32 Debug
!MESSAGE No configuration specified. Defaulting to LobbyLaunch - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "LobbyLaunch - Win32 Release" && "$(CFG)" != "LobbyLaunch - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "LobbyLaunch.mak" CFG="LobbyLaunch - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "LobbyLaunch - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "LobbyLaunch - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "LobbyLaunch - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\LobbyLaunch.exe"
CLEAN :
-@erase "$(INTDIR)\LobbyLaunch.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(OUTDIR)\LobbyLaunch.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\LobbyLaunch.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\LobbyLaunch.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\LobbyLaunch.pdb" /machine:I386 /out:"$(OUTDIR)\LobbyLaunch.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\LobbyLaunch.obj"
"$(OUTDIR)\LobbyLaunch.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "LobbyLaunch - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\LobbyLaunch.exe"
CLEAN :
-@erase "$(INTDIR)\LobbyLaunch.obj"
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(OUTDIR)\LobbyLaunch.exe"
-@erase "$(OUTDIR)\LobbyLaunch.ilk"
-@erase "$(OUTDIR)\LobbyLaunch.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\LobbyLaunch.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\LobbyLaunch.pdb" /debug /machine:I386 /out:"$(OUTDIR)\LobbyLaunch.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\LobbyLaunch.obj"
"$(OUTDIR)\LobbyLaunch.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("LobbyLaunch.dep")
!INCLUDE "LobbyLaunch.dep"
!ELSE
!MESSAGE Warning: cannot find "LobbyLaunch.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "LobbyLaunch - Win32 Release" || "$(CFG)" == "LobbyLaunch - Win32 Debug"
SOURCE=.\LobbyLaunch.cpp
"$(INTDIR)\LobbyLaunch.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: LobbyLaunch DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The LobbyLaunch tutorial is the 7th tutorial for DirectPlay. It builds upon
the last tutorial and adds lobby launching
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut07_LobbyLaunch

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Voice" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Voice - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Voice.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Voice.mak" CFG="Voice - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Voice - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Voice - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Voice - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Voice - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Voice - Win32 Release"
# Name "Voice - Win32 Debug"
# Begin Source File
SOURCE=.\Voice.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Voice"=.\Voice.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,189 @@
# Microsoft Developer Studio Generated NMAKE File, Based on Voice.dsp
!IF "$(CFG)" == ""
CFG=Voice - Win32 Debug
!MESSAGE No configuration specified. Defaulting to Voice - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "Voice - Win32 Release" && "$(CFG)" != "Voice - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Voice.mak" CFG="Voice - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Voice - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Voice - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "Voice - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
ALL : "$(OUTDIR)\Voice.exe"
CLEAN :
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\Voice.obj"
-@erase "$(OUTDIR)\Voice.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /Fp"$(INTDIR)\Voice.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Voice.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\Voice.pdb" /machine:I386 /out:"$(OUTDIR)\Voice.exe" /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Voice.obj"
"$(OUTDIR)\Voice.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ELSEIF "$(CFG)" == "Voice - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
ALL : "$(OUTDIR)\Voice.exe"
CLEAN :
-@erase "$(INTDIR)\vc60.idb"
-@erase "$(INTDIR)\vc60.pdb"
-@erase "$(INTDIR)\Voice.obj"
-@erase "$(OUTDIR)\Voice.exe"
-@erase "$(OUTDIR)\Voice.ilk"
-@erase "$(OUTDIR)\Voice.pdb"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
.c{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(INTDIR)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
MTL=midl.exe
MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\Voice.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /incremental:yes /pdb:"$(OUTDIR)\Voice.pdb" /debug /machine:I386 /out:"$(OUTDIR)\Voice.exe" /pdbtype:sept /stack:0x10000,0x10000
LINK32_OBJS= \
"$(INTDIR)\Voice.obj"
"$(OUTDIR)\Voice.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
!ENDIF
!IF "$(NO_EXTERNAL_DEPS)" != "1"
!IF EXISTS("Voice.dep")
!INCLUDE "Voice.dep"
!ELSE
!MESSAGE Warning: cannot find "Voice.dep"
!ENDIF
!ENDIF
!IF "$(CFG)" == "Voice - Win32 Release" || "$(CFG)" == "Voice - Win32 Debug"
SOURCE=.\Voice.cpp
"$(INTDIR)\Voice.obj" : $(SOURCE) "$(INTDIR)"
!ENDIF

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: Voice DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The Voice tutorial is the 8th tutorial for DirectPlay. It builds upon the last
tutorial and adds voice support
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut08_Voice

View File

@@ -0,0 +1,599 @@
//----------------------------------------------------------------------------
// File: client.cpp
//
// Desc: This simple program builds upon the 5th tutorial, and is the client
// code for the server in the client/server model
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// App specific structures
//-----------------------------------------------------------------------------
struct HOST_NODE
{
DPN_APPLICATION_DESC* pAppDesc;
IDirectPlay8Address* pHostAddress;
WCHAR* pwszSessionName;
HOST_NODE* pNext;
};
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Client* g_pDPClient = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
BOOL g_bHost;
HOST_NODE* g_pHostList = NULL;
CRITICAL_SECTION g_csHostList;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {1AD4CA3B-AC68-4d9b-9522-BE59CD485276}
GUID g_guidApp = { 0x1ad4ca3b, 0xac68, 0x4d9b, { 0x95, 0x22, 0xbe, 0x59, 0xcd, 0x48, 0x52, 0x76 } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT CreateHostAddress(WCHAR* pwszHost);
HRESULT EnumDirectPlayHosts();
HRESULT ConnectToSession();
HRESULT SendDirectPlayMessage();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_HOST 1
#define USER_CONNECT 2
#define USER_EXIT 1
#define USER_SEND 2
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
InitializeCriticalSection(&g_csHostList);
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = EnumDirectPlayHosts() ) )
{
printf("Failed Enumerating Host: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = ConnectToSession() ) )
{
printf("Failed Connect to Host: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("\nConnection Successful.\n");
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n2. Send Data\n");
scanf("%d", &iUserChoice);
if( iUserChoice == USER_SEND )
{
if( FAILED( hr = SendDirectPlayMessage() ) )
{
printf("Failed To Send Data: 0x%X\n", hr);
goto LCleanup;
}
}
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// ShutDown COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Client Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Client, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Client,
(LPVOID*) &g_pDPClient ) ) )
{
printf("Failed Creating the IDirectPlay8Client Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDPClient->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDPClient->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDPClient->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_ENUM_HOSTS_RESPONSE:
{
PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg;
const DPN_APPLICATION_DESC* pAppDesc;
HOST_NODE* pHostNode = NULL;
WCHAR* pwszSession = NULL;
pEnumHostsResponseMsg = (PDPNMSG_ENUM_HOSTS_RESPONSE) pMsgBuffer;
pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;
// Insert each host response if it isn't already present
EnterCriticalSection(&g_csHostList);
for (pHostNode = g_pHostList; pHostNode; pHostNode = pHostNode->pNext)
{
if( pAppDesc->guidInstance == pHostNode->pAppDesc->guidInstance)
{
// This host is already in the list
pHostNode = NULL;
goto Break_ENUM_HOSTS_RESPONSE;
}
}
// This host session is not in the list then so insert it.
pHostNode = new HOST_NODE;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode, sizeof(HOST_NODE));
// Copy the Host Address
if( FAILED( pEnumHostsResponseMsg->pAddressSender->Duplicate(&pHostNode->pHostAddress ) ) )
{
goto Break_ENUM_HOSTS_RESPONSE;
}
pHostNode->pAppDesc = new DPN_APPLICATION_DESC;
if( pHostNode == NULL)
{
goto Break_ENUM_HOSTS_RESPONSE;
}
ZeroMemory(pHostNode->pAppDesc, sizeof(DPN_APPLICATION_DESC));
memcpy(pHostNode->pAppDesc, pAppDesc, sizeof(DPN_APPLICATION_DESC));
// Null out all the pointers we aren't copying
pHostNode->pAppDesc->pwszSessionName = NULL;
pHostNode->pAppDesc->pwszPassword = NULL;
pHostNode->pAppDesc->pvReservedData = NULL;
pHostNode->pAppDesc->dwReservedDataSize = 0;
pHostNode->pAppDesc->pvApplicationReservedData = NULL;
pHostNode->pAppDesc->dwApplicationReservedDataSize = 0;
if( pAppDesc->pwszSessionName)
{
pwszSession = new WCHAR[wcslen(pAppDesc->pwszSessionName) + 1];
if( pwszSession)
{
wcscpy(pwszSession, pAppDesc->pwszSessionName);
}
}
pHostNode->pwszSessionName = pwszSession;
// Insert it onto the front of the list
pHostNode->pNext = g_pHostList ? g_pHostList->pNext : NULL;
g_pHostList = pHostNode;
pHostNode = NULL;
Break_ENUM_HOSTS_RESPONSE:
LeaveCriticalSection(&g_csHostList);
if( pHostNode)
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
delete pHostNode;
}
break;
}
case DPN_MSGID_TERMINATE_SESSION:
{
PDPNMSG_TERMINATE_SESSION pTermSessionMsg;
pTermSessionMsg = (PDPNMSG_TERMINATE_SESSION) pMsgBuffer;
printf("\nThe Session has been terminated!\n");
break;
}
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;
pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: EnumDirectPlayHosts()
// Desc: Enumerates the hosts
//-----------------------------------------------------------------------------
HRESULT EnumDirectPlayHosts()
{
HRESULT hr = S_OK;
WCHAR wszHost[128];
DPN_APPLICATION_DESC dpAppDesc;
WCHAR* pwszURL = NULL;
// Prompt for the hostname/ip
printf("\nPlease enter the IP address of host:\n");
wscanf(L"%ls", wszHost);
if( FAILED( hr = CreateHostAddress(wszHost ) ) )
{
printf("Failed Creating Host Address: 0x%X\n", hr);
goto LCleanup;
}
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.guidApplication = g_guidApp;
// We now have the host address so lets enum
if( FAILED( hr = g_pDPClient->EnumHosts(&dpAppDesc, // pApplicationDesc
g_pHostAddress, // pdpaddrHost
g_pDeviceAddress, // pdpaddrDeviceInfo
NULL, 0, // pvUserEnumData, size
4, // dwEnumCount
0, // dwRetryInterval
0, // dwTimeOut
NULL, // pvUserContext
NULL, // pAsyncHandle
DPNENUMHOSTS_SYNC ) ) )// dwFlags
{
printf("Failed Enumerating the Hosts: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateHostAddress()
// Desc: Creates a host address
//-----------------------------------------------------------------------------
HRESULT CreateHostAddress(WCHAR* pwszHost)
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Host Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pHostAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Host Address
if( FAILED( hr = g_pHostAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
// Set the hostname into the address
if( FAILED( hr = g_pHostAddress->AddComponent(DPNA_KEY_HOSTNAME, pwszHost,
2*(wcslen(pwszHost) + 1), /*bytes*/
DPNA_DATATYPE_STRING ) ) )
{
printf("Failed Adding Hostname to Host Address: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: ConnectToSession()
// Desc: Connects to a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT ConnectToSession()
{
HRESULT hr = E_FAIL;
DPN_APPLICATION_DESC dpnAppDesc;
IDirectPlay8Address* pHostAddress = NULL;
ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpnAppDesc.guidApplication = g_guidApp;
// Simply connect to the first one in the list
EnterCriticalSection(&g_csHostList);
if( g_pHostList && SUCCEEDED(hr = g_pHostList->pHostAddress->Duplicate(&pHostAddress ) ) )
{
hr = g_pDPClient->Connect(&dpnAppDesc, // pdnAppDesc
pHostAddress, // pHostAddr
g_pDeviceAddress, // pDeviceInfo
NULL, // pdnSecurity
NULL, // pdnCredentials
NULL, 0, // pvUserConnectData/Size
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNCONNECT_SYNC); // dwFlags
if( FAILED( hr))
printf("Failed Connecting to Host: 0x%x\n", hr);
}
else
{
printf("Failed Duplicating Host Address: 0x%x\n", hr);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(pHostAddress);
return hr;
}
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];
// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);
dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);
if( FAILED( hr = g_pDPClient->Send(&dpnBuffer, // pBufferDesc
1, // cBufferDesc
0, // dwTimeOut
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNSEND_SYNC |
DPNSEND_NOLOOPBACK ) ) ) // dwFlags
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
HOST_NODE* pHostNode = NULL;
HOST_NODE* pHostNodetmp = NULL;
// Shutdown DirectPlay
if( g_pDPClient)
g_pDPClient->Close(0);
// Clean up Host list
EnterCriticalSection(&g_csHostList);
pHostNode = g_pHostList;
while( pHostNode != NULL )
{
SAFE_RELEASE(pHostNode->pHostAddress);
SAFE_DELETE(pHostNode->pAppDesc);
SAFE_DELETE(pHostNode->pwszSessionName);
pHostNodetmp = pHostNode;
pHostNode = pHostNode->pNext;
SAFE_DELETE(pHostNodetmp);
}
LeaveCriticalSection(&g_csHostList);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDPClient);
DeleteCriticalSection(&g_csHostList);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Client" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Client - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Client.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Client.mak" CFG="Client - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Client - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Client - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Client - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Client - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Client - Win32 Release"
# Name "Client - Win32 Debug"
# Begin Source File
SOURCE=.\Client.cpp
# End Source File
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,41 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Client"=.\Client\Client.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "Server"=.\Server\Server.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -0,0 +1,362 @@
//----------------------------------------------------------------------------
// File: server.cpp
//
// Desc: This simple program builds upon the 5th tutorial, and is the server
// code for the server in the client/server model
//
// Copyright (c) 2000-2001 Microsoft Corp. All rights reserved.
//-----------------------------------------------------------------------------
#define INITGUID
#define _WIN32_DCOM
#include <stdio.h>
#include <dplay8.h>
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
IDirectPlay8Server* g_pDPServer = NULL;
IDirectPlay8Address* g_pDeviceAddress = NULL;
IDirectPlay8Address* g_pHostAddress = NULL;
// This GUID allows DirectPlay to find other instances of the same game on
// the network. So it must be unique for every game, and the same for
// every instance of that game. // {1AD4CA3B-AC68-4d9b-9522-BE59CD485276}
GUID g_guidApp = { 0x1ad4ca3b, 0xac68, 0x4d9b, { 0x95, 0x22, 0xbe, 0x59, 0xcd, 0x48, 0x52, 0x76 } };
//-----------------------------------------------------------------------------
// Function-prototypes
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);
BOOL IsServiceProviderValid(const GUID* pGuidSP);
HRESULT InitDirectPlay();
HRESULT CreateDeviceAddress();
HRESULT HostSession();
HRESULT SendDirectPlayMessage();
void CleanupDirectPlay();
//-----------------------------------------------------------------------------
// Miscellaneous helper functions
//-----------------------------------------------------------------------------
#define SAFE_DELETE(p) {if(p) {delete (p); (p)=NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(p) {delete[] (p); (p)=NULL;}}
#define SAFE_RELEASE(p) {if(p) {(p)->Release(); (p)=NULL;}}
#define USER_EXIT 1
#define USER_SEND 2
//-----------------------------------------------------------------------------
// Name: main()
// Desc: Entry point for the application.
//-----------------------------------------------------------------------------
int main(int argc, char* argv[], char* envp[])
{
HRESULT hr;
int iUserChoice;
// Init COM so we can use CoCreateInstance
CoInitializeEx(NULL, COINIT_MULTITHREADED);
// Init the DirectPlay system
if( FAILED( hr = InitDirectPlay() ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = CreateDeviceAddress() ) )
{
printf("Failed CreatingDeviceAddress: 0x%X\n", hr);
goto LCleanup;
}
if( FAILED( hr = HostSession() ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
// Present User with Choices
do
{
printf("Please select one.\n1. Exit\n2. Send Data\n");
scanf("%d", &iUserChoice);
if( iUserChoice == USER_SEND )
{
if( FAILED( hr = SendDirectPlayMessage() ) )
{
printf("Failed To Send Data: 0x%X\n", hr);
goto LCleanup;
}
}
} while (iUserChoice != USER_EXIT);
LCleanup:
CleanupDirectPlay();
// ShutDown COM
CoUninitialize();
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitDirectPlay()
// Desc: Initialize DirectPlay
//-----------------------------------------------------------------------------
HRESULT InitDirectPlay()
{
HRESULT hr = S_OK;
// Create the IDirectPlay8Server Object
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Server, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Server,
(LPVOID*) &g_pDPServer ) ) )
{
printf("Failed Creating the IDirectPlay8Peer Object: 0x%X\n", hr);
goto LCleanup;
}
// Init DirectPlay
if( FAILED( hr = g_pDPServer->Initialize(NULL, DirectPlayMessageHandler, 0 ) ) )
{
printf("Failed Initializing DirectPlay: 0x%X\n", hr);
goto LCleanup;
}
// Ensure that TCP/IP is a valid Service Provider
if( FALSE == IsServiceProviderValid(&CLSID_DP8SP_TCPIP ) )
{
hr = E_FAIL;
printf("Failed validating CLSID_DP8SP_TCPIP");
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: IsServiceProviderValid()
// Desc: Return TRUE if the service provider is valid
//-----------------------------------------------------------------------------
BOOL IsServiceProviderValid(const GUID* pGuidSP)
{
HRESULT hr;
DPN_SERVICE_PROVIDER_INFO* pdnSPInfo = NULL;
DWORD dwItems = 0;
DWORD dwSize = 0;
hr = g_pDPServer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, NULL, &dwSize, &dwItems, 0);
if( hr != DPNERR_BUFFERTOOSMALL)
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
pdnSPInfo = (DPN_SERVICE_PROVIDER_INFO*) new BYTE[dwSize];
if( FAILED( hr = g_pDPServer->EnumServiceProviders(&CLSID_DP8SP_TCPIP, NULL, pdnSPInfo, &dwSize, &dwItems, 0 ) ) )
{
printf("Failed Enumerating Service Providers: 0x%x\n", hr);
goto LCleanup;
}
// There are no items returned so the requested SP is not available
if( dwItems == 0)
{
hr = E_FAIL;
}
LCleanup:
SAFE_DELETE_ARRAY(pdnSPInfo);
if( SUCCEEDED(hr) )
return TRUE;
else
return FALSE;
}
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;
switch (dwMessageId)
{
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;
pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;
printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: CreateDeviceAddress()
// Desc: Creates a device address
//-----------------------------------------------------------------------------
HRESULT CreateDeviceAddress()
{
HRESULT hr = S_OK;
// Create our IDirectPlay8Address Device Address
if( FAILED( hr = CoCreateInstance(CLSID_DirectPlay8Address, NULL,
CLSCTX_INPROC_SERVER,
IID_IDirectPlay8Address,
(LPVOID*) &g_pDeviceAddress ) ) )
{
printf("Failed Creating the IDirectPlay8Address Object: 0x%X\n", hr);
goto LCleanup;
}
// Set the SP for our Device Address
if( FAILED( hr = g_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP ) ) )
{
printf("Failed Setting the Service Provider: 0x%X\n", hr);
goto LCleanup;
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: HostSession()
// Desc: Host a DirectPlay session
//-----------------------------------------------------------------------------
HRESULT HostSession()
{
HRESULT hr = S_OK;
DPN_APPLICATION_DESC dpAppDesc;
DPN_PLAYER_INFO dpPlayerInfo;
WCHAR wszSession[128];
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;
if( FAILED( hr = g_pDPServer->SetServerInfo( &dpPlayerInfo, NULL, NULL,
DPNSETSERVERINFO_SYNC ) ) )
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
// Prompt the user for the session name
printf("\nPlease Enter a Session Name.\n");
wscanf(L"%ls", wszSession);
// Now set up the Application Description
ZeroMemory(&dpAppDesc, sizeof(DPN_APPLICATION_DESC));
dpAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
dpAppDesc.dwFlags = DPNSESSION_CLIENT_SERVER;
dpAppDesc.guidApplication = g_guidApp;
dpAppDesc.pwszSessionName = wszSession;
// We are now ready to host the app
if( FAILED( hr = g_pDPServer->Host(&dpAppDesc, // AppDesc
&g_pDeviceAddress, 1, // Device Address
NULL, NULL, // Reserved
NULL, // Player Context
0 ) ) ) // dwFlags
{
printf("Failed Hosting: 0x%X\n", hr);
goto LCleanup;
}
else
{
printf("Currently Hosting...\n");
}
LCleanup:
return hr;
}
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];
// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);
dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);
if( FAILED( hr = g_pDPServer->SendTo(DPNID_ALL_PLAYERS_GROUP, // dpnid
&dpnBuffer, // pBufferDesc
1, // cBufferDesc
0, // dwTimeOut
NULL, // pvAsyncContext
NULL, // pvAsyncHandle
DPNSEND_SYNC | // dwFlags
DPNSEND_NOLOOPBACK ) ) )
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}
//-----------------------------------------------------------------------------
// Name: CleanupDirectPlay()
// Desc: Cleanup DirectPlay
//-----------------------------------------------------------------------------
void CleanupDirectPlay()
{
// Shutdown DirectPlay
if( g_pDPServer)
g_pDPServer->Close(0);
SAFE_RELEASE(g_pDeviceAddress);
SAFE_RELEASE(g_pHostAddress);
SAFE_RELEASE(g_pDPServer);
}

View File

@@ -0,0 +1,100 @@
# Microsoft Developer Studio Project File - Name="Server" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Application" 0x0101
CFG=Server - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Server.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Server.mak" CFG="Server - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Server - Win32 Release" (based on "Win32 (x86) Application")
!MESSAGE "Server - Win32 Debug" (based on "Win32 (x86) Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Server - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_CONSOLE" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /D "_CONSOLE" /YX /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 dplay.lib dxguid.lib ole32.lib uuid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /machine:I386 /stack:0x10000,0x10000
!ELSEIF "$(CFG)" == "Server - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /D "_CONSOLE" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /FD /c
# SUBTRACT CPP /YX
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 ole32.lib uuid.lib oleaut32.lib odbc32.lib odbccp32.lib dplay.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /stack:0x10000,0x10000
!ENDIF
# Begin Target
# Name "Server - Win32 Release"
# Name "Server - Win32 Debug"
# Begin Source File
SOURCE=.\readme.txt
# End Source File
# Begin Source File
SOURCE=.\Server.cpp
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,15 @@
//-----------------------------------------------------------------------------
// Name: ClientServer DirectPlay Tutorial
//
// Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
Description
===========
The ClientServer tutorial is the 5th tutorial for DirectPlay. It builds upon the last
tutorial and adds a ClientServer
Path
====
Source: DXSDK\Samples\Multimedia\DirectPlay\Tutorials\Tut05_ClientServer