Step 2: Creating the DirectPlay Object
After the user has selected which service provider to use, your application can create a DirectPlay object based on the selection by calling the DirectPlayCreate function and specifying the appropriate service provider's globally unique identifier (GUID). Calling this function causes DirectPlay to load the library for the selected service provider and returns an IDirectPlay interface.
Although you could use the IDirectPlay interface to create new games, a better approach would be to use the newer DirectPlay interfaces, IDirectPlay2 and IDirectPlay2A, with all their increased functionality. Your application can obtain these interfaces by calling the QueryInterface method on the IDirectPlay interface returned by DirectPlayCreate.
The following example shows how the create the IDirectPlay interface, and then use QueryInterface to create an IDirectPlay2A interface:
HRESULT CreateDirectPlayInterface(LPGUID lpguidServiceProvider,
LPDIRECTPLAY2A *lplpDirectPlay2A)
{
LPDIRECTPLAY lpDirectPlay1 = NULL;
LPDIRECTPLAY2A lpDirectPlay2A = NULL;
HRESULT hr;
// Retrieve a DirectPlay 1.0 interface.
hr = DirectPlayCreate(lpguidServiceProvider, &lpDirectPlay1, NULL);
if FAILED(hr)
goto FAILURE;
// Query for an ANSI DirectPlay2 interface.
hr = lpDirectPlay1->QueryInterface(IID_IDirectPlay2A,
(LPVOID *) &lpDirectPlay2A);
if FAILED(hr)
goto FAILURE;
// Return the created interface.
*lplpDirectPlay2A = lpDirectPlay2A;
FAILURE:
if (lpDirectPlay1)
lpDirectPlay1->Release();
return (hr);
}