Jump to content
  • Advertisement
Sign in to follow this  
Jarlax

Help wirh networking (msg handler function)

This topic is 4857 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

Hello all, I am rather new to DirectX and have been working my way through a book I bought to learn some concepts. I am trying to enhance an example and have run into trouble. I am creating a server and client application using DirectPlay. I created a network class to encapsulate some of the functionality for reuse but I am having trouble with the ServerMessageHandler function. I have the prototype in my resource file like this: class cNetwork { private: IDirectPlay8Server *m_pDPServer; static HRESULT WINAPI NetworkMsgHandler(PVOID context, DWORD msgid, PVOID data); public: cNetwork(); ~cNetwork(); }; The problem I have is that every time the handle function is called the context is null. It does not matter if the message is coming from the server or a client application. Without the context I cannot get a handle to the server variable and so I cannot do anything. Here is the basic setup of the code: HRESULT WINAPI cNetwork::NetworkMsgHandler(PVOID context, DWORD msgid, PVOID data) { // Get a pointer to the calling network object. cNetwork *network = (cNetwork*)context; if(network == NULL) { return E_FAIL; } DPNMSG_CREATE_PLAYER *CreatePlayer; DPNMSG_DESTROY_PLAYER *DestroyPlayer; DPNMSG_RECEIVE *ReceiveData; switch(msgid) { case DPN_MSGID_CREATE_PLAYER: break; case DPN_MSGID_DESTROY_PLAYER: DestroyPlayer = (DPNMSG_DESTROY_PLAYER*)data; break; case DPN_MSGID_RECEIVE: ReceiveData = (DPNMSG_RECEIVE*)data; break; } return S_OK; } Can anyone help me on where to look or what is going on? I really cannot go any further with my exercise at this point. Thanks, Jarlax

Share this post


Link to post
Share on other sites
Advertisement
Does anyone have any ideas? Is there anything more I can/should post to help find my issue?

Thanks!

Share this post


Link to post
Share on other sites
Dude are you creating the DirectPlay8Server component with CoCreateInstance? You HAVE to do this (and call the initialize method) before you can do anything with it.

I strongly urge you to find the old DirectPlay8 samples that came with the DX81 SDK...

They go through all the necessities of getting a client/server pair going that could really help you out.

hth,

Share this post


Link to post
Share on other sites
I am using the CoCreateInstance to create the DirectPLay8Server. I have a simple client application that has a connect/Disconnect feature and button which makes a sendto call. In the server code I added message boxes in the switch statement like such:

switch(msgid) {
case DPN_MSGID_CREATE_PLAYER:
CreatePlayer = (DPNMSG_CREATE_PLAYER*)date;
MessageBox(NULL, "Player joining", "Join", MB_OK);
break;
case DPN_MSGID_DESTROY_PLAYER:
DestroyPlayer = (DPNMSG_DESTROY_PLAYER*)data;
MessageBox(NULL, "Player leaving", "Leave", MB_OK);
break;
case DPN_MSGID_RECEIVE:
ReceiveData = (DPNMSG_RECEIVE*)data;
MessageBox(NULL, "Player sending message", "Message", MB_OK);
break;
}

I am getting the right message boxes to popup as I would expect them but because the context parameter is null all the time I cannot get a handle to my server object. I need to call network->m_DirectPlayServer->{desired function} but since network is populated by context and context is null I get errors. If I put all the code in .cpp file I can make it work but I am trying to break out the networking stuff to be its own class and with the method static I need the handle to the server object and that is what I cannot figure out.

I am sure that I missed something but I cannot figure out what. I can try to check the DX8.1 samples to see if they help. Any other ideas are welcome.

Share this post


Link to post
Share on other sites
When you Initialize the DirectPlay8Server component, try using the "this" keyword as the 3rd parameter (or is it first?) in order to have the object come through as your context instead of NULL.

Check the DX docs for more on that method...

Share this post


Link to post
Share on other sites
Oh that sounds very promising! From your recommendation I took a look at the CoCreateInstance and noticed that the context (third parameter) is set to CLSCTX_INPROC:

if(FAILED(CoCreateInstance(CLSID_DirectPlay8Address, NULL, CLSCTX_INPROC, IID_IDirectPlay8Address, (void**)&pDPAddress)))
return FALSE;

Looking at the API there appear to be a number of predefined values. I will see of one of the other values will solve my issue. I will post what I find.

Thanks!

[Edited by - Jarlax on August 29, 2005 11:26:05 AM]

Share this post


Link to post
Share on other sites
Thanks a lot TheOther! You were right and the problem appears to be in the initialization. I changed the server to initialize from this:

m_pDPServer->Initialize(NULL, NetworkMsgHandler, 0)

to this:

m_pDPServer->Initialize((PVOID)this, NetworkMsgHandler, 0)

and now the server appears to be behaving correctly. I am in the process of modifying the client to initialize the same way.

I appreciate your help!

Jarlax

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!