Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Impz0r

DPlay8 vs Classes...wtf?

This topic is 6248 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Try making the member function static.

Share this post


Link to post
Share on other sites
Hi,

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


cLE

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 handler

HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer);

// interface for NetworkEngine class

class NetworkEngine
{
public:
HRESULT CreatePlayer(PVOID pvUserContext, PVOID pMsgBuffer);
...
}



// Main.cpp


// game contains an object of NetworkEngine

Game 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;
}


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!