forked from ClemensLode/Wars
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirectpl.cpp
107 lines (89 loc) · 2.46 KB
/
directpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "engine.h"
#include "resource.h"
LRESULT CALLBACK DPDialog(HWND,UINT,WPARAM,LPARAM);
LPDIRECTPLAY3 dp;
HWND hwnd;
BOOL Engine_Multiplayer::InitDirectPlay()
{
CoInitialize(NULL);
if(FAILED(CoCreateInstance(CLSID_DirectPlay,NULL,CLSCTX_ALL,
IID_IDirectPlay3A,(LPVOID*)&info.lpDP)))
{
return Fail("Fehler beim Anlegen von DirectPlay");
}
return TRUE;
}
void Engine_Multiplayer::ChooseConnection(void)
{
dp = (IDirectPlay3*)info.lpDP;
hwnd = (HWND)info.hwnd;
DialogBox((HINSTANCE)info.hInstance,(LPCTSTR)IDD_CHCONNECTION,info.hwnd,
(DLGPROC)DPDialog);
}
BOOL Engine_Multiplayer::Fail( char *szMsg)
{
ReleaseObjects();
OutputDebugString( szMsg );
MessageBox(info.hwnd, szMsg, info.AppName, MB_OK);
DestroyWindow( info.hwnd );
return FALSE;
}
BOOL WINAPI EnumConnection( LPCGUID lpguidSP,
LPVOID lpConnection, DWORD dwSize,
LPDPNAME lpName, DWORD dwFlags,
LPVOID lpContext )
{
LONG iIndex;
HWND hWnd = ( HWND ) lpContext;
LPVOID lpOurConnection = NULL;
LPDIRECTPLAY3 lpDPTemp;
if FAILED( CoCreateInstance( CLSID_DirectPlay,
NULL, CLSCTX_ALL, IID_IDirectPlay3A,
( LPVOID* ) &lpDPTemp ) )
{
return( FALSE );
}
if FAILED( lpDPTemp->InitializeConnection( lpConnection, 0 ) )
{
lpDPTemp->Release();
return( TRUE );
}
lpDPTemp->Release();
iIndex = SendMessage( hWnd, CB_ADDSTRING, 0,
(LPARAM) lpName->lpszShortNameA );
if ( iIndex != LB_ERR )
{
lpOurConnection = malloc( dwSize );
if ( !lpOurConnection ) return FALSE;
memcpy( lpOurConnection, lpConnection, dwSize );
SendMessage( hWnd, CB_SETITEMDATA, iIndex,
( LPARAM ) lpOurConnection );
}
else
{
return FALSE;
}
return( TRUE );
}
void Engine_Multiplayer::ReleaseObjects(void)
{
RELEASE(info.lpDP);
}
LRESULT CALLBACK DPDialog( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_INITDIALOG:
dp->EnumConnections(NULL,(LPDPENUMCONNECTIONSCALLBACK)EnumConnection,
(LPVOID)GetDlgItem(hwnd,IDC_CONNECTIONS),0);
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}