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

DirectPlay in objects...

Started by Analazon Jan 26, 2003 at 11:27 AM 1 replies 300+ views
Original Post
Analazon
Analazon
I am just beginning to experiment with DirectPlay, and I am trying to create a server. Most of my programs use an engine object that controls all of the other objects, and this method has seemed to work with all of the other parts of DirectX. Now my current problem is is that when you initalize DPlay, I need to specify the name of a message loop for it. I have been cutting code out of one of the examples, and I have the line of code:
g_pDPServer->Initialize(NULL, DirectPlayMessageHandler, 0 )
  
and this is in my engine object. When I try to compile, it tells me that: ...\MMOserver\engine.cpp(71) : error C2664: ''Initialize'' : cannot convert parameter 2 from ''long (void *,unsigned long,void *)'' to ''long (__stdcall *const )(void *,unsigned long,void *)'' None of the functions with this name in scope match the target type Now, with what I know about programming, it is basiclly telling me that it really doesn''t like being in an object. If someone could tell me how to make this work, I would be very appreciative. (because if I can get it to work, then I can add it to my little library of wrapper classes for DirectX...) (note: I posted this on the beginners forum, and didn''t seem to generate much of a response...) ___________________ ~Analazon
_______~Analazon
MindWipe
MindWipe
Well, here how I did it in my class. The thing is that the message handler need to be static(I think!?) Well, I solved it nicely;

quote:


HRESULT WINAPI __stdcall CNetwork::StaticMessageHandler( PVOID pvUserContext,
DWORD dwMessageId, PVOID pMsgBuffer )
{
CNetwork* network=(CNetwork*)pvUserContext;

return network->MessageHandler( pvUserContext, dwMessageId, pMsgBuffer);

}

HRESULT WINAPI CNetwork::MessageHandler( PVOID pvUserContext,
DWORD dwMessageId, PVOID pMsgBuffer )
{

HRESULT hr = S_OK;

switch (dwMessageId)
{
...
}
}



But if you do like this you need to set the pointer to you non-static message handler like this:

hr = m_pDPServer->Initialize( this, StaticMessageHandler, 0);

But this is for my DPlay class

/MindWipe
"To some its a six-pack, to me it's a support group."
Analazon
Analazon
:/

Didn''t work for me...


  
// in my directplay initilization function...

if( FAILED( hr = g_pDPServer->Initialize(this, StaticDirectPlayMessageHandler, 0 ) ) )
{
return 0;
}
//---------------------------

HRESULT WINAPI __stdcall engine::StaticDirectPlayMessageHandler(PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
engine *theengine = (engine*)pvUserContext;
return theengine->MessageHandler( pvUserContext, dwMessageId, pMsgBuffer);
}
//-----------------------------

HRESULT WINAPI engine::MessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;

switch(dwMessageId)
{
// do stuff...

default:
break;
}

}


I am rather confused by this...

___________________
~Analazon
_______~Analazon

Topic Locked

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

Sign in to reply to this topic.