Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

DirectPlay

Started by vgo Apr 7, 2005 at 10:32 AM 0 replies 2.2k views
Original Post
vgo
vgo
I downloaded the Clootie's DirectX 9 header conversions and wanted to try out the DirectPlay stuff, but I ran into problems with my message handling callback routine. Here's my callback routine:

function TDirectPlayServer.DPMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;
begin
	Result := S_OK;
end;
I try to use it like this (like I've done with the Windows API callbacks before):

...
hr := DPServer.Initialize(NIL, @DPMessageHandler, 0);
...
The problems is that my code won't compile, the error message that I get is "Variable required". The initialize function is declared like this:

function Initialize(pvUserContext: Pointer; pfn: TFNDPNMessageHandler; dwFlags: DWORD): HResult; stdcall;
And the callback is declared like this:

TFNDPNMessageHandler = function (pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;
  {$NODEFINE TFNDPNMessageHandler}
  {$HPPEMIT 'typedef PFNDPNMESSAGEHANDLER TFNDPNMessageHandler;'}
The solution is simple, but I just can't grasp it right now. :P Any help greatly appreciated. EDIT I can easily set the handler if I declare it outside the class like this:

function DirectPlayMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;
begin
	Result := S_OK;
end;
But it's kinda useless, because I can't access the private methods/variables on my server class. :) [Edited by - vgo on April 7, 2005 11:55:45 AM]
vgo
vgo
Problem solved.

I created a static method for the handler and pass it to the DPServer object.

function TDirectPlayServer.DPMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;begin	Result := S_OK;end;function StaticDirectPlayMessageHandler(pvUserContext: Pointer; dwMessageType: DWORD; pMessage: Pointer): HRESULT; stdcall;begin	Result := TDirectPlayServer(pvUserContext).DPMessageHandler(pvUserContext, dwMessageType, pMessage);end;...hr := DPServer.Initialize(@Self, @StaticDirectPlayMessageHandler, 0);...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.