DirectPlay

Started by
0 comments, last by vgo 19 years, 1 month ago
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]
Advertisement
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);...

This topic is closed to new replies.

Advertisement