1,33 → 1,13 |
unit DXPlay; |
|
{$INCLUDE DelphiXcfg.inc} |
|
{$IFNDEF UseDirectPlay} |
// If you want to use DXPlay.pas, please enable the IFDEF UseDirectPlay in DelphiXcfg.inc |
interface |
implementation |
{$ELSE} // !UseDirectPlay |
|
interface |
{$INCLUDE DelphiXcfg.inc} |
|
uses |
Windows, SysUtils, Classes, Forms, DXClass, ActiveX, DXETable, |
{$IfDef StandardDX} |
DirectDraw, |
// Delphi 2010 cannot be use DirectPlay8 because structure was not rewriten |
// {$IfDef DX9} |
// DirectPlay8, DX7toDX8; |
// {$Else} |
DirectPlay; //old wersion, current in directory |
// {$EndIf} |
{$Else} |
DirectX; |
{$EndIf} |
Windows, SysUtils, Classes, Forms, DXClass, ActiveX, DirectX, DXETable; |
|
type |
{$IfDef DX9} |
TDPID = DWORD; |
{$EndIf} |
|
{ TDXPlayPlayer } |
|
108,8 → 88,7 |
|
TCustomDXPlay = class(TComponent) |
private |
FDPlay: //{$IfDef DX7} |
IDirectPlay4A;//{$Else}IDirectPlay8Address{$EndIf}; |
FDPlay: IDirectPlay4A; |
FGUID: string; |
FIsHost: Boolean; |
FLocalPlayer: TDXPlayPlayer; |
137,11 → 116,7 |
FAsync: Boolean; |
FAsyncSupported: Boolean; |
procedure ChangeDPlay; |
procedure CreateDPlayWithoutDialog(out DPlay: |
//{$IfDef DX7} |
IDirectPlay4A; |
//{$Else}IDirectPlay8Address{$EndIf}; |
const ProviderName: string); |
procedure CreateDPlayWithoutDialog(out DPlay: IDirectPlay4A; const ProviderName: string); |
function OpenDPlayWithLobby(out Name: string): Boolean; |
function OpenDPlayWithoutLobby(out Name: string): Boolean; |
function OpenDPlayWithoutLobby2(const NewSession: Boolean; const ProviderName, SessionName, PlayerName: string): Boolean; |
216,10 → 191,7 |
function DXPlayMessageType(P: Pointer): DWORD; |
|
function DXPlayStringToGUID(const S: string): TGUID; |
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: |
//{$IfDef DX7} |
IDirectPlay; |
//{$Else}IDirectPlay8Server{$EndIf}; |
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: IDirectPlay; |
pUnk: IUnknown): HRESULT; |
|
implementation |
252,10 → 224,7 |
CoTaskMemFree(P); |
end; |
|
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: |
//{$IfDef DX7} |
IDirectPlay; |
//{$Else}IDirectPlay8Server{$EndIf}; |
function DXDirectPlayCreate(const lpGUID: TGUID; out lplpDP: IDirectPlay; |
pUnk: IUnknown): HRESULT; |
type |
TDirectPlayCreate= function(const lpGUID: TGUID; out lplpDP: IDirectPlay; pUnk: IUnknown): HRESULT; stdcall; |
263,27 → 232,9 |
Result := TDirectPlayCreate(DXLoadLibrary('DPlayX.dll', 'DirectPlayCreate')) |
(lpGUID, lplpDP, pUnk); |
end; |
{$IFDEF UNICODE} |
function DXDirectPlayEnumerate(lpEnumDPCallback: TDPEnumDPCallbackW; lpContext: Pointer): HRESULT; |
type |
TDirectPlayEnumerateW= function(lpEnumDPCallback: TDPEnumDPCallbackW; lpContext: Pointer): HRESULT; stdcall; |
begin |
Result := TDirectPlayEnumerateW(DXLoadLibrary('DPlayX.dll', 'DirectPlayEnumerateW')) |
(lpEnumDPCallback, lpContext); |
end; |
|
function DXDirectPlayLobbyCreate(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyW; |
lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; |
function DXDirectPlayEnumerateA(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT; |
type |
TDirectPlayLobbyCreateW = function(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyW; |
lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; stdcall; |
begin |
Result := TDirectPlayLobbyCreateW(DXLoadLibrary('DPlayX.dll', 'DirectPlayLobbyCreateW')) |
(lpguidSP, lplpDPL, lpUnk, lpData, dwDataSize); |
end; |
{$ELSE} |
function DXDirectPlayEnumerate(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT; |
type |
TDirectPlayEnumerateA= function(lpEnumDPCallback: TDPEnumDPCallbackA; lpContext: Pointer): HRESULT; stdcall; |
begin |
Result := TDirectPlayEnumerateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayEnumerateA')) |
290,7 → 241,7 |
(lpEnumDPCallback, lpContext); |
end; |
|
function DXDirectPlayLobbyCreate(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA; |
function DXDirectPlayLobbyCreateA(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA; |
lpUnk: IUnknown; lpData: Pointer; dwDataSize: DWORD): HRESULT; |
type |
TDirectPlayLobbyCreateA = function(const lpguidSP: TGUID; out lplpDPL: IDirectPlayLobbyA; |
299,7 → 250,7 |
Result := TDirectPlayLobbyCreateA(DXLoadLibrary('DPlayX.dll', 'DirectPlayLobbyCreateA')) |
(lpguidSP, lplpDPL, lpUnk, lpData, dwDataSize); |
end; |
{$ENDIF} |
|
{ TDXPlayPlayers } |
|
constructor TDXPlayPlayers.Create; |
365,16 → 316,10 |
end; |
|
var |
{$IFDEF UNICODE} |
Lobby1: IDirectPlayLobbyW; |
Lobby: IDirectPlayLobby2W; |
DPlay: IDirectPlay4W; |
{$ELSE} |
Lobby1: IDirectPlayLobbyA; |
Lobby: IDirectPlayLobby2A; |
DPlay1: IDirectPlay; |
DPlay: IDirectPlay4A; |
{$ENDIF} |
DPlay1: IDirectPlay; |
lpAddress: Pointer; |
dwAddressSize: DWORD; |
begin |
382,16 → 327,16 |
begin |
FModemNames := TStringList.Create; |
try |
if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then |
if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then |
raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]); |
Lobby := Lobby1 as {$IFDEF UNICODE}IDirectPlayLobby2W{$ELSE}IDirectPlayLobby2A{$ENDIF}; |
Lobby := Lobby1 as IDirectPlayLobby2A; |
|
if DXDirectPlayCreate(DPSPGUID_MODEM, DPlay1, nil)<>0 then |
raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]); |
DPlay := DPlay1 as {$IFDEF UNICODE}IDirectPlay4W{$ELSE}IDirectPlay4A{$ENDIF}; |
DPlay := DPlay1 as IDirectPlay4A; |
|
{ get size of player address for all players } |
if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, nil, dwAddressSize)<>DPERR_BUFFERTOOSMALL then |
if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, nil^, dwAddressSize)<>DPERR_BUFFERTOOSMALL then |
raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired); |
|
GetMem(lpAddress, dwAddressSize); |
399,7 → 344,7 |
FillChar(lpAddress^, dwAddressSize, 0); |
|
{ get the address } |
if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, lpAddress, dwAddressSize)<>0 then |
if DPlay.GetPlayerAddress(DPID_ALLPLAYERS, lpAddress^, dwAddressSize)<>0 then |
raise EDXPlayError.Create(SDXPlayModemListCannotBeAcquired); |
|
{ get modem strings from address and put them in the combo box } |
525,12 → 470,12 |
|
try |
repeat |
hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer, dwMsgBufferSize); |
hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer^, dwMsgBufferSize); |
|
if hr=DPERR_BUFFERTOOSMALL then |
begin |
ReAllocMem(lpvMsgBuffer, dwMsgBufferSize); |
hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer, dwMsgBufferSize); |
hr := FDPlay.Receive(idFrom, idTo, DPRECEIVE_ALL, lpvMsgBuffer^, dwMsgBufferSize); |
end; |
|
if (hr=0) and (dwMsgBufferSize>=SizeOf(TDPMSG_GENERIC)) then |
552,13 → 497,8 |
|
with Msg_CreatePlayerOrGroup.dpnName do |
begin |
{$IFDEF UNICODE} |
if lpszShortNameW<>nil then |
Player.FName := lpszShortNameW; |
{$ELSE} |
if lpszShortNameA<>nil then |
Player.FName := lpszShortNameA; |
{$ENDIF} |
end; |
|
DoAddPlayer(Player); |
664,7 → 604,7 |
|
function TCustomDXPlay.GetProviders: TStrings; |
|
function EnumProviderCallback(const lpguidSP: TGUID; lpSPName: {$IFDEF UNICODE}LPCTSTR{$ELSE}LPSTR{$ENDIF}; |
function EnumProviderCallback(const lpguidSP: TGUID; lpSPName: LPSTR; |
dwMajorVersion: DWORD; dwMinorVersion: DWORD; lpContext: Pointer): |
BOOL; stdcall; |
var |
681,7 → 621,7 |
begin |
FProviders := TStringList.Create; |
try |
DXDirectPlayEnumerate(@EnumProviderCallback, FProviders); |
DXDirectPlayEnumerateA(@EnumProviderCallback, FProviders); |
except |
FProviders.Free; FProviders := nil; |
raise; |
706,11 → 646,8 |
|
Guid := New(PGUID); |
Move(lpThisSD.guidInstance, Guid^, SizeOf(TGUID)); |
{$IFDEF UNICODE} |
TStrings(lpContext).AddObject(lpThisSD.lpszSessionNameW, TObject(Guid)); |
{$ELSE} |
TStrings(lpContext).AddObject(lpThisSD.lpszSessionNameA, TObject(Guid)); |
{$ENDIF} |
|
Result := True; |
end; |
|
761,13 → 698,8 |
ProviderGUID: TGUID; |
addressElements: array[0..15] of TDPCompoundAddressElement; |
dwElementCount: Integer; |
{$IFDEF UNICODE} |
Lobby1: IDirectPlayLobbyW; |
Lobby: IDirectPlayLobby2W; |
{$ELSE} |
Lobby1: IDirectPlayLobbyA; |
Lobby: IDirectPlayLobby2A; |
{$ENDIF} |
lpAddress: Pointer; |
dwAddressSize: DWORD; |
begin |
777,9 → 709,9 |
ProviderGUID := PGUID(Providers.Objects[i])^; |
|
{ DirectPlay address making } |
if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then |
if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby1, nil, nil, 0)<>0 then |
raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]); |
Lobby := Lobby1 as {$IFDEF UNICODE}IDirectPlayLobby2W{$ELSE}IDirectPlayLobby2A{$ENDIF}; |
Lobby := Lobby1 as IDirectPlayLobby2A; |
|
FillChar(addressElements, SizeOf(addressElements), 0); |
dwElementCount := 0; |
828,7 → 760,7 |
end; |
end; |
|
if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, nil, dwAddressSize)<>DPERR_BUFFERTOOSMALL then |
if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, nil^, dwAddressSize)<>DPERR_BUFFERTOOSMALL then |
raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]); |
|
GetMem(lpAddress, dwAddressSize); |
835,7 → 767,7 |
try |
FillChar(lpAddress^, dwAddressSize, 0); |
|
if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, lpAddress, dwAddressSize)<>0 then |
if Lobby.CreateCompoundAddress(addressElements[0], dwElementCount, lpAddress^, dwAddressSize)<>0 then |
raise EDXPlayError.CreateFmt(SCannotInitialized, [SDirectPlay]); |
|
{ DirectPlay initialization } |
905,13 → 837,8 |
|
with lpName do |
begin |
{$IFDEF UNICODE} |
if lpszShortNameW<>nil then |
Player.FName := lpszShortNameW; |
{$ELSE} |
if lpszShortNameA<>nil then |
Player.FName := lpszShortNameA; |
{$ENDIF} |
end; |
|
Result := True; |
935,11 → 862,11 |
FLocalPlayer := TDXPlayPlayer.Create(FPlayers); |
FLocalPlayer.FName := NameS; |
|
if FDPlay.CreatePlayer(FLocalPlayer.FID, @Name, FRecvEvent[0], nil, 0, 0)<>DP_OK then |
if FDPlay.CreatePlayer(FLocalPlayer.FID, Name, FRecvEvent[0], nil^, 0, 0)<>DP_OK then |
raise EDXPlayError.CreateFmt(SCannotOpened, [FSessionName]); |
|
{ Player enumeration } |
FDPlay.EnumPlayers(PGUID(nil), @EnumPlayersCallback2, Self, DPENUMPLAYERS_REMOTE); |
FDPlay.EnumPlayers(PGUID(nil)^, @EnumPlayersCallback2, Self, DPENUMPLAYERS_REMOTE); |
|
FIsHost := FPlayers.Count=1; |
|
948,7 → 875,7 |
|
{ Thread start } |
FRecvThread := TDXPlayRecvThread.Create(Self); |
FRecvThread.{$IFDEF VER14UP}Start{$ELSE}Resume{$ENDIF}; |
FRecvThread.Resume; |
except |
Close; |
raise; |
973,25 → 900,21 |
function TCustomDXPlay.OpenDPlayWithLobby(out Name: string): Boolean; |
var |
DPlay1: IDirectPlay2; |
{$IFDEF UNICODE} |
Lobby: IDirectPlayLobbyW; |
{$ELSE} |
Lobby: IDirectPlayLobbyA; |
{$ENDIF} |
dwSize: DWORD; |
ConnectionSettings: PDPLConnection; |
begin |
Result := False; |
|
if DXDirectPlayLobbyCreate(PGUID(nil)^, Lobby, nil, nil, 0)<>0 then |
if DXDirectPlayLobbyCreateA(PGUID(nil)^, Lobby, nil, nil, 0)<>0 then |
Exit; |
|
if Lobby.GetConnectionSettings(0, PDPLConnection(nil), dwSize)<>DPERR_BUFFERTOOSMALL then |
if Lobby.GetConnectionSettings(0, PDPLConnection(nil)^, dwSize)<>DPERR_BUFFERTOOSMALL then |
Exit; |
|
GetMem(ConnectionSettings, dwSize); |
try |
if Lobby.GetConnectionSettings(0, ConnectionSettings, dwSize)<>0 then |
if Lobby.GetConnectionSettings(0, ConnectionSettings^, dwSize)<>0 then |
Exit; |
|
with ConnectionSettings^.lpSessionDesc^ do |
1010,24 → 933,14 |
|
with ConnectionSettings.lpSessionDesc^ do |
begin |
{$IFDEF UNICODE} |
if lpszSessionNameW<>nil then |
FSessionName := lpszSessionNameW; |
{$ELSE} |
if lpszSessionNameA<>nil then |
FSessionName := lpszSessionNameA; |
{$ENDIF} |
end; |
|
with ConnectionSettings.lpPlayerName^ do |
begin |
{$IFDEF UNICODE} |
if lpszShortNameW<>nil then |
Name := lpszShortNameW; |
{$ELSE} |
if lpszShortNameA<>nil then |
Name := lpszShortNameA; |
{$ENDIF} |
end; |
finally |
FreeMem(ConnectionSettings); |
1082,11 → 995,7 |
FillChar(dpDesc, SizeOf(dpDesc), 0); |
dpDesc.dwSize := SizeOf(dpDesc); |
dpDesc.dwFlags := DPSESSION_MIGRATEHOST or DPSESSION_KEEPALIVE; |
{$IFDEF UNICODE} |
dpDesc.lpszSessionNameW := {$IFDEF VER12UP}PChar{$ELSE}PWideChar{$ENDIF}(SessionName); |
{$ELSE} |
dpDesc.lpszSessionNameA := PAnsiChar(SessionName); |
{$ENDIF} |
dpDesc.lpszSessionNameA := PChar(SessionName); |
dpDesc.guidApplication := DXPlayStringToGUID(GUID); |
dpDesc.dwMaxPlayers := MaxPlayers; |
|
1170,7 → 1079,7 |
DoMessage(FLocalPlayer, Data, DataSize); |
end else |
if FAsync and FAsyncSupported then |
FDPlay.SendEx(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED or DPSEND_ASYNC, Data, DataSize, 0, 0, nil, nil) |
FDPlay.SendEx(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED or DPSEND_ASYNC, Data^, DataSize, 0, 0, nil, nil) |
else |
FDPlay.Send(FLocalPlayer.ID, ToID, DPSEND_GUARANTEED, Data^, DataSize); |
end; |
1189,7 → 1098,7 |
{ ©ª¶ÌbZ[W } |
DoMessage(FLocalPlayer, Data, DataSize); |
end else |
FDPlay.SendEx(FLocalPlayer.ID, ToID, dwFlags, Data, DataSize, |
FDPlay.SendEx(FLocalPlayer.ID, ToID, dwFlags, Data^, DataSize, |
0, 0, nil, @Result); // 0 ÈOÍT|[gµÈ¢foCX éÌÅgíÈ¢ |
end; |
|
1234,6 → 1143,4 |
CoInitialize(nil); |
finalization |
CoUninitialize; |
{$ENDIF} // UseDirectPlay |
|
end. |
end. |