DPlay8 vs Classes...wtf?

Started by
6 comments, last by Impz0r 22 years, 7 months ago
hi, I''m new to DPlay8, and i''m trying to create an DPlay Server & Client. But i run in problems to do this. The main problem lays in the DPlay Message Callback function : HRESULT WINAPI DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer ) This function won''t work with classes, while it''s __stdcall and not thiscall. I''ve create an internal Message handler in both classes (Client&Server) where i will route all Networkmessages that will arrived at the DPlay Message Callback Funktion. Here is an example how try to do this : // try to rout the messages to the internal message handler cNetwork *pNetInterface = (cNetwork*) pUserContext; if (pNetInterface) return (pNetInterface->NetProc (uiMessageId, pMsgBuffer)); But i don''t know how to set the pvUserContext for the whole runtime of the server or client. Is there a change to encapsule the whole DPlay functionality in classes or is this totaly useless? Pls help, Thanks Imp
Stay Evil & Ugly!
Advertisement
Try making the member function static.
Hi,

you can set pvUserContext when you call the Initialize method of your interface (IDirectPlay8Peer, IDirectPlay8Client and IDirectPlay8Server).


cLE
hi,

Anonymous Poster : i have the method declared as static


cLE : are you sure that works for the lifetime of my Client&Server instance? You say i can add these "this" pointer to the ::Initialize () call, but work that only for the first message? Hmm hard to explain, my english suxx


Thanks Imp
Stay Evil & Ugly!
It comes with every message:

        //On Init	if(FAILED(hr=m_pDPServer->Initialize(this, MsgProc, 0)))		{		TRACE("DPServer Init Failed\n");		return(hr);		}HRESULT WINAPI CNetworkServerDx8::MsgProc(PVOID pvUserContext, DWORD dwMessageID, PVOID pMsgBuffer)	{	CNetworkServerDx8* This = reinterpret_cast<CNetworkServerDx8*>(pvUserContext);	_ASSERT(This);		switch(dwMessageID)		{		case DPN_MSGID_INDICATE_CONNECT:			return This->IndicateConnect(reinterpret_cast<DPNMSG_INDICATE_CONNECT*>(pMsgBuffer));//...        


Magmai Kai Holmlor
- Not For Rent

Edited by - Magmai Kai Holmlor on September 10, 2001 11:31:58 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Hi,

it works always. I''m using the same technique to access my class members.


cLE
Well,

I also use a wrapper class for the DirectPlay8 objects and at first I also had that problem with the DirectPlayMessageHandler.

In the beginning, I made the message handler method static, but then I had to made all members and methods static. That''s because static methods can only access static members (or is this incorrect?).

But just recently (yesterday actually) I rewrote this class so that every member became unstatic. I had to remove the DirectPlayMessageHandler out of the class then and made it a global function. So I just have a prototype of this handler in the class'' header file and the implementation is in my main.

Something like this:

  // NetworkEngine.hpp// function prototype for directplay message handlerHRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);// interface for NetworkEngine classclass NetworkEngine{public:  HRESULT CreatePlayer(PVOID pvUserContext, PVOID pMsgBuffer);...}// Main.cpp// game contains an object of NetworkEngineGame game;...int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow){  ...}HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer){  switch (dwMessageId)  {  // new player joined session  case DPN_MSGID_CREATE_PLAYER:    game.network->CreatePlayer(pvUserContext, pMsgBuffer);    break;  }  ...  return S_OK;}  


Hi,
At first, thanks for your back answers :D
I will use the solution from Magmai Kai, this shows as the best i think of. Thanks Magmai Kai :D

Thanks, Imp
Stay Evil & Ugly!

This topic is closed to new replies.

Advertisement