Subversion Repositories spacemission

Rev

Rev 1 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 4
Line 3... Line 3...
3
interface
3
interface
4
 
4
 
5
{$INCLUDE DelphiXcfg.inc}
5
{$INCLUDE DelphiXcfg.inc}
6
 
6
 
7
uses
7
uses
8
  Windows, SysUtils, Classes, Forms, DXClass, ActiveX, DirectX, DXETable;
8
  Windows, SysUtils, Classes, Forms, DXClass, ActiveX, DXETable,  
-
 
9
{$IfDef StandardDX}
-
 
10
  DirectDraw,
-
 
11
// Delphi 2010 cannot be use DirectPlay8 because structure was not rewriten
-
 
12
//  {$IfDef DX9}
-
 
13
//  DirectPlay8, DX7toDX8;
-
 
14
//  {$Else}
-
 
15
  DirectPlay; //old wersion, current in directory
-
 
16
//  {$EndIf}
-
 
17
{$Else}
-
 
18
  DirectX;
-
 
19
{$EndIf}
9
                                                                       
20
 
10
type
21
type
-
 
22
  {$IfDef DX9}
-
 
23
  TDPID = DWORD;
-
 
24
  {$EndIf}
11
 
25
 
12
  {  TDXPlayPlayer  }
26
  {  TDXPlayPlayer  }
13
 
27
 
14
  TDXPlayPlayer = class(TCollectionItem)
28
  TDXPlayPlayer = class(TCollectionItem)
15
  private
29
  private
Line 86... Line 100...
86
  TDXPlaySendCompleteEvent = procedure(Sender: TObject; MessageID: DWORD;
100
  TDXPlaySendCompleteEvent = procedure(Sender: TObject; MessageID: DWORD;
87
    Result: TDXPlaySendCompleteResult; SendTime: Integer) of object;
101
    Result: TDXPlaySendCompleteResult; SendTime: Integer) of object;
88
 
102
 
89
  TCustomDXPlay = class(TComponent)
103
  TCustomDXPlay = class(TComponent)
90
  private
104
  private
91
    FDPlay: IDirectPlay4A;
105
    FDPlay: //{$IfDef DX7}
-
 
106
      IDirectPlay4A;//{$Else}IDirectPlay8Address{$EndIf};
92
    FGUID: string;
107
    FGUID: string;
93
    FIsHost: Boolean;
108
    FIsHost: Boolean;
94
    FLocalPlayer: TDXPlayPlayer;
109
    FLocalPlayer: TDXPlayPlayer;
95
    FMaxPlayers: Integer;
110
    FMaxPlayers: Integer;
96
    FPlayers: TDXPlayPlayers;
111
    FPlayers: TDXPlayPlayers;
Line 114... Line 129...
114
    FModemSetting: TDXPlayModemSetting;
129
    FModemSetting: TDXPlayModemSetting;
115
    FTCPIPSetting: TDXPlayTCPIPSetting;
130
    FTCPIPSetting: TDXPlayTCPIPSetting;
116
    FAsync: Boolean;
131
    FAsync: Boolean;
117
    FAsyncSupported: Boolean;
132
    FAsyncSupported: Boolean;
118
    procedure ChangeDPlay;
133
    procedure ChangeDPlay;
119
    procedure CreateDPlayWithoutDialog(out DPlay: IDirectPlay4A; const ProviderName: string);
134
    procedure CreateDPlayWithoutDialog(out DPlay:
-
 
135
     //{$IfDef DX7}
-
 
136
     IDirectPlay4A;
-
 
137
     //{$Else}IDirectPlay8Address{$EndIf};
-
 
138
      const ProviderName: string);
120
    function OpenDPlayWithLobby(out Name: string): Boolean;
139
    function OpenDPlayWithLobby(out Name: string): Boolean;
121
    function OpenDPlayWithoutLobby(out Name: string): Boolean;
140
    function OpenDPlayWithoutLobby(out Name: string): Boolean;
122
    function OpenDPlayWithoutLobby2(const NewSession: Boolean; const ProviderName, SessionName, PlayerName: string): Boolean;
141
    function OpenDPlayWithoutLobby2(const NewSession: Boolean; const ProviderName, SessionName, PlayerName: string): Boolean;
123
    procedure Open_(NameS: string);
142
    procedure Open_(NameS: string);
124
    procedure ReceiveMessage;
143
    procedure ReceiveMessage;
Line 189... Line 208...
189
  end;
208
  end;
190
 
209
 
191
function DXPlayMessageType(P: Pointer): DWORD;
210
function DXPlayMessageType(P: Pointer): DWORD;
192
 
211
 
193
function DXPlayStringToGUID(const S: string): TGUID;
212
function DXPlayStringToGUID(const S: string): TGUID;
194
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: IDirectPlay;
213
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP:
-
 
214
  //{$IfDef DX7}
-
 
215
  IDirectPlay;
-
 
216
  //{$Else}IDirectPlay8Server{$EndIf};
195
  pUnk: IUnknown): HRESULT;
217
  pUnk: IUnknown): HRESULT;
196
 
218
 
197
implementation
219
implementation
198
 
220
 
199
uses DXPlayFm, DXConsts;
221
uses DXPlayFm, DXConsts;
Line 222... Line 244...
222
    raise EDXPlayError.Create(WindowsErrorMsg(ErrorCode));
244
    raise EDXPlayError.Create(WindowsErrorMsg(ErrorCode));
223
  Result := P;
245
  Result := P;
224
  CoTaskMemFree(P);
246
  CoTaskMemFree(P);
225
end;
247
end;
226
 
248
 
227
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: IDirectPlay;
249
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP:
-
 
250
  //{$IfDef DX7}
-
 
251
  IDirectPlay;
-
 
252
  //{$Else}IDirectPlay8Server{$EndIf};
228
  pUnk: IUnknown): HRESULT;
253
  pUnk: IUnknown): HRESULT;
229
type
254
type
230
  TDirectPlayCreate= function(const lpGUID: TGUID; out lplpDP: IDirectPlay; pUnk: IUnknown): HRESULT; stdcall;
255
  TDirectPlayCreate= function(const lpGUID: TGUID; out lplpDP: IDirectPlay; pUnk: IUnknown): HRESULT; stdcall;
231
begin
256
begin
232
  Result := TDirectPlayCreate(DXLoadLibrary('DPlayX.dll', 'DirectPlayCreate'))
257
  Result := TDirectPlayCreate(DXLoadLibrary('DPlayX.dll', 'DirectPlayCreate'))
233
    (lpGUID, lplpDP, pUnk);
258
    (lpGUID, lplpDP, pUnk);
234
end;
259
end;
-
 
260
{$IFDEF UNICODE}
-
 
261
function DXDirectPlayEnumerate(lpEnumDPCallback: TDPEnumDPCallbackW; lpContext: Pointer): HRESULT;
-
 
262
type
-
 
263
  TDirectPlayEnumerateW= function(lpEnumDPCallback: TDPEnumDPCallbackW; lpContext: Pointer): HRESULT; stdcall;
-
 
264
begin
-
 
265
  Result := TDirectPlayEnumerateW(DXLoadLibrary('DPlayX.dll', 'DirectPlayEnumerateW'))
-
 
266
    (lpEnumDPCallback, lpContext);
-
 
267
end;
235
 
268
 
-
 
269
function DXDirectPlayLobbyCreate(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyW;
-
 
270
  lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT;
-
 
271
type
-
 
272
  TDirectPlayLobbyCreateW = function(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyW;
-
 
273
    lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; stdcall;
-
 
274
begin
-
 
275
  Result := TDirectPlayLobbyCreateW(DXLoadLibrary('DPlayX.dll', 'DirectPlayLobbyCreateW'))
-
 
276
    (lpguidSP, lplpDPL, lpUnk, lpData, dwDataSize);
-
 
277
end;
-
 
278
{$ELSE}
236
function DXDirectPlayEnumerateA(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT;
279
function DXDirectPlayEnumerate(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT;
237
type
280
type
238
  TDirectPlayEnumerateA= function(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT; stdcall;
281
  TDirectPlayEnumerateA= function(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT; stdcall;
239
begin
282
begin
240
  Result := TDirectPlayEnumerateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayEnumerateA'))
283
  Result := TDirectPlayEnumerateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayEnumerateA'))
241
    (lpEnumDPCallback, lpContext);
284
    (lpEnumDPCallback, lpContext);
242
end;
285
end;
243
 
286
 
244
function DXDirectPlayLobbyCreateA(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA;
287
function DXDirectPlayLobbyCreate(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA;
245
  lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT;
288
  lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT;
246
type
289
type
247
  TDirectPlayLobbyCreateA = function(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA;
290
  TDirectPlayLobbyCreateA = function(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA;
248
    lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; stdcall;
291
    lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; stdcall;
249
begin
292
begin
250
  Result := TDirectPlayLobbyCreateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayLobbyCreateA'))
293
  Result := TDirectPlayLobbyCreateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayLobbyCreateA'))
251
    (lpguidSP, lplpDPL, lpUnk, lpData, dwDataSize);
294
    (lpguidSP, lplpDPL, lpUnk, lpData, dwDataSize);
252
end;
295
end;
253
 
296
{$ENDIF}
254
{  TDXPlayPlayers  }
297
{  TDXPlayPlayers  }
255
 
298
 
256
constructor TDXPlayPlayers.Create;
299
constructor TDXPlayPlayers.Create;
257
begin
300
begin
258
  inherited Create(TDXPlayPlayer);
301
  inherited Create(TDXPlayPlayer);
Line 314... Line 357...
314
      TStrings(lpContext).Add( PChar(lpData));
357
      TStrings(lpContext).Add( PChar(lpData));
315
    Result := True;
358
    Result := True;
316
  end;
359
  end;
317
 
360
 
318
var
361
var
-
 
362
  {$IFDEF UNICODE}
-
 
363
  Lobby1: IDirectPlayLobbyW;
-
 
364
  Lobby: IDirectPlayLobby2W;
-
 
365
  DPlay: IDirectPlay4W;
-
 
366
  {$ELSE}
319
  Lobby1: IDirectPlayLobbyA;
367
  Lobby1: IDirectPlayLobbyA;
320
  Lobby: IDirectPlayLobby2A;
368
  Lobby: IDirectPlayLobby2A;
321
  DPlay1: IDirectPlay;
-
 
322
  DPlay: IDirectPlay4A;
369
  DPlay: IDirectPlay4A;
-
 
370
  {$ENDIF}
-
 
371
  DPlay1: IDirectPlay;
323
  lpAddress: Pointer;
372
  lpAddress: Pointer;
324
  dwAddressSize: DWORD;
373
  dwAddressSize: DWORD;
325
begin
374
begin
326
  if FModemNames=nil then
375
  if FModemNames=nil then
327
  begin
376
  begin
328
    FModemNames := TStringList.Create;
377
    FModemNames := TStringList.Create;
329
    try
378
    try
330
      if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then
379
      if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then
331
        raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
380
        raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
332
      Lobby := Lobby1 as IDirectPlayLobby2A;
381
      Lobby := Lobby1 as {$IFDEF UNICODE}IDirectPlayLobby2W{$ELSE}IDirectPlayLobby2A{$ENDIF};
333
 
382
 
334
      if DXDirectPlayCreate(DPSPGUID_MODEM, DPlay1, nil)<>0 then
383
      if DXDirectPlayCreate(DPSPGUID_MODEM, DPlay1, nil)<>0 then
335
        raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
384
        raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
336
      DPlay := DPlay1 as IDirectPlay4A;
385
      DPlay := DPlay1 as {$IFDEF UNICODE}IDirectPlay4W{$ELSE}IDirectPlay4A{$ENDIF};
337
 
386
 
338
      {  get size of player address for all players  }
387
      {  get size of player address for all players  }
339
      if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, nil^, dwAddressSize)<>DPERR_BUFFERTOOSMALL then
388
      if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, nil, dwAddressSize)<>DPERR_BUFFERTOOSMALL then
340
        raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
389
        raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
341
 
390
 
342
      GetMem(lpAddress, dwAddressSize);
391
      GetMem(lpAddress, dwAddressSize);
343
      try
392
      try
344
        FillChar(lpAddress^, dwAddressSize, 0);
393
        FillChar(lpAddress^, dwAddressSize, 0);
345
 
394
 
346
        {  get the address  }
395
        {  get the address  }
347
        if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, lpAddress^, dwAddressSize)<>0 then
396
        if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, lpAddress, dwAddressSize)<>0 then
348
          raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
397
          raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
349
 
398
 
350
        {  get modem strings from address and put them in the combo box  }
399
        {  get modem strings from address and put them in the combo box  }
351
        if Lobby.EnumAddress(@EnumModemAddress, lpAddress^, dwAddressSize, FModemNames)<>0 then
400
        if Lobby.EnumAddress(@EnumModemAddress, lpAddress^, dwAddressSize, FModemNames)<>0 then
352
          raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
401
          raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired);
Line 468... Line 517...
468
      lpvMsgBuffer := nil;
517
      lpvMsgBuffer := nil;
469
      dwMsgBufferSize := 0;
518
      dwMsgBufferSize := 0;
470
 
519
 
471
      try
520
      try
472
        repeat
521
        repeat
473
          hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer^, dwMsgBufferSize);
522
          hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer, dwMsgBufferSize);
474
 
523
 
475
          if hr=DPERR_BUFFERTOOSMALL then
524
          if hr=DPERR_BUFFERTOOSMALL then
476
          begin
525
          begin
477
            ReAllocMem(lpvMsgBuffer, dwMsgBufferSize);
526
            ReAllocMem(lpvMsgBuffer, dwMsgBufferSize);
478
            hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer^, dwMsgBufferSize);
527
            hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer, dwMsgBufferSize);
479
          end;
528
          end;
480
 
529
 
481
          if (hr=0) and (dwMsgBufferSize>=SizeOf(TDPMSG_GENERIC)) then
530
          if (hr=0) and (dwMsgBufferSize>=SizeOf(TDPMSG_GENERIC)) then
482
          begin
531
          begin
483
            if idFrom=DPID_SYSMSG then
532
            if idFrom=DPID_SYSMSG then
Line 495... Line 544...
495
                      Player.FID := Msg_CreatePlayerOrGroup.DPID;
544
                      Player.FID := Msg_CreatePlayerOrGroup.DPID;
496
                      Player.FRemotePlayer := True;
545
                      Player.FRemotePlayer := True;
497
 
546
 
498
                      with Msg_CreatePlayerOrGroup.dpnName do
547
                      with Msg_CreatePlayerOrGroup.dpnName do
499
                      begin
548
                      begin
-
 
549
                        {$IFDEF UNICODE}
-
 
550
                        if lpszShortNameW<>nil then
-
 
551
                          Player.FName := lpszShortNameW;
-
 
552
                        {$ELSE}
500
                        if lpszShortNameA<>nil then
553
                        if lpszShortNameA<>nil then
501
                          Player.FName := lpszShortNameA;
554
                          Player.FName := lpszShortNameA;
-
 
555
                        {$ENDIF}
502
                      end;
556
                      end;
503
 
557
 
504
                      DoAddPlayer(Player);
558
                      DoAddPlayer(Player);
505
                    end;
559
                    end;
506
                  end;
560
                  end;
Line 602... Line 656...
602
  if Assigned(FOnSendComplete) then FOnSendComplete(Self, MessageID, Result, SendTime);
656
  if Assigned(FOnSendComplete) then FOnSendComplete(Self, MessageID, Result, SendTime);
603
end;
657
end;
604
 
658
 
605
function TCustomDXPlay.GetProviders: TStrings;
659
function TCustomDXPlay.GetProviders: TStrings;
606
 
660
 
607
  function EnumProviderCallback(const lpguidSP: TGUID; lpSPName: LPSTR;
661
  function EnumProviderCallback(const lpguidSP: TGUID; lpSPName: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPSTR{$ENDIF};
608
      dwMajorVersion: DWORD; dwMinorVersion: DWORD; lpContext: Pointer):
662
      dwMajorVersion: DWORD; dwMinorVersion: DWORD; lpContext: Pointer):
609
      BOOL; stdcall;
663
      BOOL; stdcall;
610
  var
664
  var
611
    GUID: PGUID;
665
    GUID: PGUID;
612
  begin
666
  begin
Line 619... Line 673...
619
begin
673
begin
620
  if FProviders=nil then
674
  if FProviders=nil then
621
  begin
675
  begin
622
    FProviders := TStringList.Create;
676
    FProviders := TStringList.Create;
623
    try
677
    try
624
      DXDirectPlayEnumerateA(@EnumProviderCallback, FProviders);
678
      DXDirectPlayEnumerate(@EnumProviderCallback, FProviders);
625
    except
679
    except
626
      FProviders.Free; FProviders := nil;
680
      FProviders.Free; FProviders := nil;
627
      raise;
681
      raise;
628
    end;
682
    end;
629
  end;
683
  end;
Line 644... Line 698...
644
      Exit;
698
      Exit;
645
    end;
699
    end;
646
 
700
 
647
    Guid := New(PGUID);
701
    Guid := New(PGUID);
648
    Move(lpThisSD.guidInstance, Guid^, SizeOf(TGUID));
702
    Move(lpThisSD.guidInstance, Guid^, SizeOf(TGUID));
-
 
703
    {$IFDEF UNICODE}
-
 
704
    TStrings(lpContext).AddObject(lpThisSD.lpszSessionNameW, TObject(Guid));
-
 
705
    {$ELSE}
649
    TStrings(lpContext).AddObject(lpThisSD.lpszSessionNameA, TObject(Guid));
706
    TStrings(lpContext).AddObject(lpThisSD.lpszSessionNameA, TObject(Guid));
650
 
707
    {$ENDIF}
651
    Result := True;
708
    Result := True;
652
  end;
709
  end;
653
 
710
 
654
var
711
var
655
  dpDesc: TDPSessionDesc2;
712
  dpDesc: TDPSessionDesc2;
Line 696... Line 753...
696
var
753
var
697
  i: Integer;
754
  i: Integer;
698
  ProviderGUID: TGUID;
755
  ProviderGUID: TGUID;
699
  addressElements: array[0..15] of TDPCompoundAddressElement;
756
  addressElements: array[0..15] of TDPCompoundAddressElement;
700
  dwElementCount: Integer;
757
  dwElementCount: Integer;
-
 
758
  {$IFDEF UNICODE}
-
 
759
  Lobby1: IDirectPlayLobbyW;
-
 
760
  Lobby: IDirectPlayLobby2W;
-
 
761
  {$ELSE}
701
  Lobby1: IDirectPlayLobbyA;
762
  Lobby1: IDirectPlayLobbyA;
702
  Lobby: IDirectPlayLobby2A;
763
  Lobby: IDirectPlayLobby2A;
-
 
764
  {$ENDIF}
703
  lpAddress: Pointer;
765
  lpAddress: Pointer;
704
  dwAddressSize: DWORD;
766
  dwAddressSize: DWORD;
705
begin
767
begin
706
  i := Providers.IndexOf(ProviderName);
768
  i := Providers.IndexOf(ProviderName);
707
  if i=-1 then
769
  if i=-1 then
708
    raise EDXPlayError.CreateFmt(SDXPlayProviderNotFound, [ProviderName]);
770
    raise EDXPlayError.CreateFmt(SDXPlayProviderNotFound, [ProviderName]);
709
  ProviderGUID := PGUID(Providers.Objects[i])^;
771
  ProviderGUID := PGUID(Providers.Objects[i])^;
710
 
772
 
711
  {  DirectPlay address making  }
773
  {  DirectPlay address making  }
712
  if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then
774
  if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then
713
    raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
775
    raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
714
  Lobby := Lobby1 as IDirectPlayLobby2A;
776
  Lobby := Lobby1 as {$IFDEF UNICODE}IDirectPlayLobby2W{$ELSE}IDirectPlayLobby2A{$ENDIF};
715
 
777
 
716
  FillChar(addressElements, SizeOf(addressElements), 0);
778
  FillChar(addressElements, SizeOf(addressElements), 0);
717
  dwElementCount := 0;
779
  dwElementCount := 0;
718
 
780
 
719
  addressElements[dwElementCount].guidDataType := DPAID_ServiceProvider;
781
  addressElements[dwElementCount].guidDataType := DPAID_ServiceProvider;
Line 758... Line 820...
758
      addressElements[dwElementCount].lpData := @TCPIPSetting.FPort;
820
      addressElements[dwElementCount].lpData := @TCPIPSetting.FPort;
759
      Inc(dwElementCount);                                        
821
      Inc(dwElementCount);
760
    end;
822
    end;
761
  end;
823
  end;
762
 
824
 
763
  if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, nil^, dwAddressSize)<>DPERR_BUFFERTOOSMALL then
825
  if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, nil, dwAddressSize)<>DPERR_BUFFERTOOSMALL then
764
    raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
826
    raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
765
 
827
 
766
  GetMem(lpAddress, dwAddressSize);
828
  GetMem(lpAddress, dwAddressSize);
767
  try
829
  try
768
    FillChar(lpAddress^, dwAddressSize, 0);
830
    FillChar(lpAddress^, dwAddressSize, 0);
769
 
831
 
770
    if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, lpAddress^, dwAddressSize)<>0 then
832
    if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, lpAddress, dwAddressSize)<>0 then
771
      raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
833
      raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
772
 
834
 
773
    {  DirectPlay initialization  }
835
    {  DirectPlay initialization  }
774
    if CoCreateInstance(CLSID_DirectPlay, nil, CLSCTX_INPROC_SERVER, IID_IDirectPlay4A, DPlay)<>0 then
836
    if CoCreateInstance(CLSID_DirectPlay, nil, CLSCTX_INPROC_SERVER, IID_IDirectPlay4A, DPlay)<>0 then
775
      raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
837
      raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]);
Line 835... Line 897...
835
    Player.FID := TDPID;
897
    Player.FID := TDPID;
836
    Player.FRemotePlayer := True;
898
    Player.FRemotePlayer := True;
837
 
899
 
838
    with lpName do
900
    with lpName do
839
    begin
901
    begin
-
 
902
      {$IFDEF UNICODE}
-
 
903
      if lpszShortNameW<>nil then
-
 
904
        Player.FName := lpszShortNameW;
-
 
905
      {$ELSE}
840
      if lpszShortNameA<>nil then
906
      if lpszShortNameA<>nil then
841
        Player.FName := lpszShortNameA;
907
        Player.FName := lpszShortNameA;
-
 
908
      {$ENDIF}
842
    end;
909
    end;
843
 
910
 
844
    Result := True;
911
    Result := True;
845
  end;
912
  end;
846
 
913
 
Line 860... Line 927...
860
    FRecvEvent[0] := CreateEvent(nil, False, False, nil);
927
    FRecvEvent[0] := CreateEvent(nil, False, False, nil);
861
 
928
 
862
    FLocalPlayer := TDXPlayPlayer.Create(FPlayers);
929
    FLocalPlayer := TDXPlayPlayer.Create(FPlayers);
863
    FLocalPlayer.FName := NameS;
930
    FLocalPlayer.FName := NameS;
864
 
931
 
865
    if FDPlay.CreatePlayer(FLocalPlayer.FID, Name, FRecvEvent[0], nil^, 0, 0)<>DP_OK then
932
    if FDPlay.CreatePlayer(FLocalPlayer.FID, @Name, FRecvEvent[0], nil, 0, 0)<>DP_OK then
866
      raise EDXPlayError.CreateFmt(SCannotOpened, [FSessionName]);
933
      raise EDXPlayError.CreateFmt(SCannotOpened, [FSessionName]);
867
 
934
 
868
    {  Player enumeration  }
935
    {  Player enumeration  }
869
    FDPlay.EnumPlayers(PGUID(nil)^, @EnumPlayersCallback2, Self, DPENUMPLAYERS_REMOTE);
936
    FDPlay.EnumPlayers(PGUID(nil), @EnumPlayersCallback2, Self, DPENUMPLAYERS_REMOTE);
870
 
937
 
871
    FIsHost := FPlayers.Count=1;
938
    FIsHost := FPlayers.Count=1;
872
 
939
 
873
    FCalledDoOpen := True; DoOpen;
940
    FCalledDoOpen := True; DoOpen;
874
    DoAddPlayer(FLocalPlayer);
941
    DoAddPlayer(FLocalPlayer);
Line 898... Line 965...
898
end;
965
end;
899
 
966
 
900
function TCustomDXPlay.OpenDPlayWithLobby(out Name: string): Boolean;
967
function TCustomDXPlay.OpenDPlayWithLobby(out Name: string): Boolean;
901
var
968
var
902
  DPlay1: IDirectPlay2;
969
  DPlay1: IDirectPlay2;
-
 
970
  {$IFDEF UNICODE}
-
 
971
  Lobby: IDirectPlayLobbyW;
-
 
972
  {$ELSE}
903
  Lobby: IDirectPlayLobbyA;
973
  Lobby: IDirectPlayLobbyA;
-
 
974
  {$ENDIF}
904
  dwSize: DWORD;
975
  dwSize: DWORD;
905
  ConnectionSettings: PDPLConnection;
976
  ConnectionSettings: PDPLConnection;
906
begin
977
begin
907
  Result := False;
978
  Result := False;
908
 
979
 
909
  if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby, nil, nil, 0)<>0 then
980
  if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby, nil, nil, 0)<>0 then
910
    Exit;
981
    Exit;
911
 
982
 
912
  if Lobby.GetConnectionSettings(0, PDPLConnection(nil)^, dwSize)<>DPERR_BUFFERTOOSMALL then
983
  if Lobby.GetConnectionSettings(0, PDPLConnection(nil), dwSize)<>DPERR_BUFFERTOOSMALL then
913
    Exit;
984
    Exit;
914
 
985
 
915
  GetMem(ConnectionSettings, dwSize);
986
  GetMem(ConnectionSettings, dwSize);
916
  try
987
  try
917
    if Lobby.GetConnectionSettings(0, ConnectionSettings^, dwSize)<>0 then
988
    if Lobby.GetConnectionSettings(0, ConnectionSettings, dwSize)<>0 then
918
      Exit;
989
      Exit;
919
 
990
 
920
    with ConnectionSettings^.lpSessionDesc^ do
991
    with ConnectionSettings^.lpSessionDesc^ do
921
    begin
992
    begin
922
      dwFlags := DPSESSION_MIGRATEHOST or DPSESSION_KEEPALIVE or DPSESSION_DIRECTPLAYPROTOCOL;
993
      dwFlags := DPSESSION_MIGRATEHOST or DPSESSION_KEEPALIVE or DPSESSION_DIRECTPLAYPROTOCOL;
Line 931... Line 1002...
931
    FDPlay := DPlay1 as IDirectPlay4A;
1002
    FDPlay := DPlay1 as IDirectPlay4A;
932
    ChangeDPlay;
1003
    ChangeDPlay;
933
 
1004
 
934
    with ConnectionSettings.lpSessionDesc^ do
1005
    with ConnectionSettings.lpSessionDesc^ do
935
    begin
1006
    begin
-
 
1007
      {$IFDEF UNICODE}
-
 
1008
      if lpszSessionNameW<>nil then
-
 
1009
        FSessionName := lpszSessionNameW;
-
 
1010
      {$ELSE}
936
      if lpszSessionNameA<>nil then
1011
      if lpszSessionNameA<>nil then
937
        FSessionName := lpszSessionNameA;
1012
        FSessionName := lpszSessionNameA;
-
 
1013
      {$ENDIF}
938
    end;
1014
    end;
939
 
1015
 
940
    with ConnectionSettings.lpPlayerName^ do
1016
    with ConnectionSettings.lpPlayerName^ do
941
    begin
1017
    begin
-
 
1018
      {$IFDEF UNICODE}
-
 
1019
      if lpszShortNameW<>nil then
-
 
1020
        Name := lpszShortNameW;
-
 
1021
      {$ELSE}
942
      if lpszShortNameA<>nil then
1022
      if lpszShortNameA<>nil then
943
        Name := lpszShortNameA;
1023
        Name := lpszShortNameA;
-
 
1024
      {$ENDIF}
944
    end;
1025
    end;
945
  finally
1026
  finally
946
    FreeMem(ConnectionSettings);
1027
    FreeMem(ConnectionSettings);
947
  end;
1028
  end;
948
 
1029
 
Line 993... Line 1074...
993
  begin
1074
  begin
994
    {  Session connection  }
1075
    {  Session connection  }
995
    FillChar(dpDesc, SizeOf(dpDesc), 0);
1076
    FillChar(dpDesc, SizeOf(dpDesc), 0);
996
    dpDesc.dwSize := SizeOf(dpDesc);
1077
    dpDesc.dwSize := SizeOf(dpDesc);
997
    dpDesc.dwFlags := DPSESSION_MIGRATEHOST or DPSESSION_KEEPALIVE;
1078
    dpDesc.dwFlags := DPSESSION_MIGRATEHOST or DPSESSION_KEEPALIVE;
-
 
1079
    {$IFDEF UNICODE}
-
 
1080
    dpDesc.lpszSessionNameW := {$IFDEF VER12UP}PChar{$ELSE}PWideChar{$ENDIF}(SessionName);
-
 
1081
    {$ELSE}
998
    dpDesc.lpszSessionNameA := PChar(SessionName);
1082
    dpDesc.lpszSessionNameA := PAnsiChar(SessionName);
-
 
1083
    {$ENDIF}
999
    dpDesc.guidApplication := DXPlayStringToGUID(GUID);
1084
    dpDesc.guidApplication := DXPlayStringToGUID(GUID);
1000
    dpDesc.dwMaxPlayers := MaxPlayers;
1085
    dpDesc.dwMaxPlayers := MaxPlayers;
1001
 
1086
 
1002
    hr := FDPlay.Open(dpDesc, DPOPEN_CREATE);
1087
    hr := FDPlay.Open(dpDesc, DPOPEN_CREATE);
1003
    if hr=DPERR_USERCANCEL then Exit;
1088
    if hr=DPERR_USERCANCEL then Exit;
Line 1077... Line 1162...
1077
  begin
1162
  begin
1078
    {  Message to me  }
1163
    {  Message to me  }
1079
    DoMessage(FLocalPlayer, Data, DataSize);
1164
    DoMessage(FLocalPlayer, Data, DataSize);
1080
  end else
1165
  end else
1081
  if FAsync and FAsyncSupported then
1166
  if FAsync and FAsyncSupported then
1082
    FDPlay.SendEx(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED or DPSEND_ASYNC, Data^, DataSize, 0, 0, nil, nil)
1167
    FDPlay.SendEx(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED or DPSEND_ASYNC, Data, DataSize, 0, 0, nil, nil)
1083
  else
1168
  else
1084
    FDPlay.Send(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED, Data^, DataSize);
1169
    FDPlay.Send(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED, Data^, DataSize);
1085
end;
1170
end;
1086
 
1171
 
1087
function TCustomDXPlay.SendMessageEx(ToID: TDPID; Data: Pointer; DataSize: Integer;
1172
function TCustomDXPlay.SendMessageEx(ToID: TDPID; Data: Pointer; DataSize: Integer;
Line 1096... Line 1181...
1096
  if ToID=FLocalPlayer.ID then
1181
  if ToID=FLocalPlayer.ID then
1097
  begin
1182
  begin
1098
    {  Ž©•ªˆ¶‚̃ƒbƒZ[ƒW  }
1183
    {  Ž©•ªˆ¶‚̃ƒbƒZ[ƒW  }
1099
    DoMessage(FLocalPlayer, Data, DataSize);
1184
    DoMessage(FLocalPlayer, Data, DataSize);
1100
  end else
1185
  end else
1101
    FDPlay.SendEx(FLocalPlayer.ID, ToID, dwFlags, Data^, DataSize,
1186
    FDPlay.SendEx(FLocalPlayer.ID, ToID, dwFlags, Data, DataSize,
1102
      0, 0, nil, @Result); // 0 ˆÈŠO‚̓Tƒ|[ƒg‚µ‚È‚¢ƒfƒoƒCƒX‚ ‚é‚Ì‚ÅŽg‚í‚È‚¢
1187
      0, 0, nil, @Result); // 0 ˆÈŠO‚̓Tƒ|[ƒg‚µ‚È‚¢ƒfƒoƒCƒX‚ ‚é‚Ì‚ÅŽg‚í‚È‚¢
1103
end;
1188
end;
1104
 
1189
 
1105
procedure TCustomDXPlay.SetGUID(const Value: string);
1190
procedure TCustomDXPlay.SetGUID(const Value: string);
1106
begin
1191
begin