DirectPlay Delphi Application

I'm have problem using DirectPlay... this is my first DirecPlay application and i try to find how DirectPlay works. DirectX 9 SDK is great but when I try to covert tutorials and samples to Delphi 7 almost every function that is part of some DirectPlay interface returns E_POINTER error.

This is main (and only) in my program.

///////////////////////////////////////////////

unit Main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SyncObjs;

type
TMainForm = class(TForm)
HostButton: TButton;
ExitButton: TButton;
PlayerListBox: TListBox;
procedure ExitButtonClick(Sender: TObject);
procedure HostButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
Critical:TCriticalSection;
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

uses
DirectPlay8, ActiveX;

const
ServerGUID:TGUID='{EDE9493E-6AC8-4f15-8D01-8B163200B966}';
ServerPort:DWORD=2507;
ServerName='Flash-Chat Server';

var
DPServer:IDirectPlay8Server;
DPAddress:IDirectPlay8Address;
IsHosting:Boolean;
AppDesc:DPN_APPLICATION_DESC;

function DirectPlayMessageHandler(pvUserContext:Pointer;dwMessageId:DWORD;pMsgBuffer:Pointer):HRESULT; stdcall;
var
Info:Pointer;
InfoSize,TempSize:DWord;
r:hresult;
begin
Case dwMessageId of
DPN_MSGID_CREATE_PLAYER:
begin
r:=DPServer.GetClientInfo(PDPNMSG_CREATE_PLAYER(pMsgBuffer)^.dpnidPlayer,nil,@TempSize,0);
if r=DPNERR_BUFFERTOOSMALL then
begin
InfoSize:=TempSize;
GetMem(Info,InfoSize);
DPServer.GetClientInfo(PDPNMSG_CREATE_PLAYER(pMsgBuffer).dpnidPlayer,Info,@TempSize,0);
MainForm.Critical.Enter;
MainForm.PlayerListBox.AddItem(PDPN_PLAYER_INFO(Info).pwszName,Pointer(PDPNMSG_CREATE_PLAYER(pMsgBuffer).dpnidPlayer));
MainForm.Critical.Leave;
FreeMem(Info,InfoSize);
end;
Result:=S_OK;
end;
end;
end;

procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;

procedure TMainForm.HostButtonClick(Sender: TObject);
begin
if IsHosting then
begin
DPServer.Close(0);
HostButton.Caption:='Host';
IsHosting:=False;
end
else
begin
DPServer.Initialize(nil,DirectPlayMessageHandler,0);
DPServer.Host(AppDesc,@DPAddress,1,nil,nil,nil,0);
HostButton.Caption:='Terminate';
IsHosting:=True;
end;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
Critical:=TCriticalSection.Create;
CoInitializeEx(nil,COINIT_MULTITHREADED);
FillChar(AppDesc,SizeOf(AppDesc),0);
AppDesc.dwSize:=SizeOf(DPN_APPLICATION_DESC);
AppDesc.dwFlags:=DPNSESSION_CLIENT_SERVER or DPNSESSION_NODPNSVR;
AppDesc.guidApplication:=ServerGUID;
AppDesc.pwszSessionName:=ServerName;
IsHosting:=False;
CoCreateInstance(CLSID_DirectPlay8Server,nil,CLSCTX_INPROC_SERVER,IID_IDirectPlay8Server,DPServer);
CoCreateInstance(CLSID_DirectPlay8Address,nil,CLSCTX_ALL, IID_IDirectPlay8Address,DPAddress);
DPAddress.SetSP(CLSID_DP8SP_TCPIP);
DPAddress.AddComponent(DPNA_KEY_PORT,@ServerPort,SizeOf(ServerPort),DPNA_DATATYPE_DWORD);
end;

procedure TMainForm.FormDestroy(Sender: TObject);
begin
DPServer.Close(0);
if DPAddress<>nil then DPAddress:=nil;
if DPServer<>nil then DPServer:=nil;
CoUninitialize;
Critical.Free;
end;

end.

///////////////////////////////////////////////

Every thing is working ok, except DPServer.GetClientInfo function. This function returns E_POINTER error. What should I do to make it work properly?

P.S. I'm using DirectX9 and DirectX 9 units downloaded from http://clootie.narod.ru/delphi/ (Project JEDI)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories