A question of pointers..

J

JariTapio

Hei!

I explored DirectX 8.1 SDK and found TUT09_ClientServer it includes the
following code as a part of the tutorial...

//----

HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;

switch (dwMessageId)
{
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;

pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;

printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);
break;
}
}
return hr;
}

//----

And, now the actual question : How do i change the pMsg->pReceiveData to
point to my pointer " int *g_myData " and load the data to my pointer..

Well, thats about it, not that bad..

Thank you greatly for your helping tips.

Yours : JariTapio / Helsinki / 06 July 2005
 
V

velthuijsen

And, now the actual question : How do i change the pMsg->pReceiveData to
point to my pointer " int *g_myData " and load the data to my pointer..

Do you mean:
int *g_myData
// fill g_myData here.
PDPNMSG_RECEIVE pMsg;
PMsg = static_cast<PDPNMSG_RECEIVE>(g_myData);

or do you mean
PDPNMSG_RECEIVE pMsg;
pMsg = static_cast<PDPNMSG_RECEIVE>(pMsgBuffer);
int* g_myData = static_cast<int*>(pMsg);
Which can be shortened to:
int* g_myData = static_cast<int*>(pMsgBuffer);
 
J

JariTapio

Hei!

hmm.. im still not talantet enough.. Dam hell..
well lets try again..
I have two functions (both workin fine) one for sending strings and one for
receivin ones ( DX8.1SDK TUT09_ClientServer )..

If we watch the CLIENT code we can find my question i received some help
from mr Velthuijsen but i did not get my code running properly...


SERVER CODE FOLLOWS::
//-----------------------------------------------------------------------------
// Name: SendDirectPlayMessage()
// Desc: Sends a DirectPlay message to all players
//-----------------------------------------------------------------------------
HRESULT SendDirectPlayMessage()
{
HRESULT hr = S_OK;
DPN_BUFFER_DESC dpnBuffer;
WCHAR wszData[256];

// Get the data from the user
printf("\nPlease Enter a String.\n");
wscanf(L"%ls", wszData);


dpnBuffer.pBufferData = (BYTE*) wszData;
dpnBuffer.dwBufferSize = 2 * (wcslen(wszData) + 1);

if( FAILED( hr = g_pDPServer->SendTo(DPNID_ALL_PLAYERS_GROUP, // dpnid
&dpnBuffer, //
pBufferDesc
1, //
cBufferDesc
0, //
dwTimeOut
NULL, //
pvAsyncContext
NULL, //
pvAsyncHandle
DPNSEND_SYNC | //
dwFlags
DPNSEND_NOLOOPBACK ) ) )
{
printf("Failed Sending Data: 0x%x\n", hr);
}
return hr;
}

CLIENT CODE FOLLOWS::
//-----------------------------------------------------------------------------
// Name: DirectPlayMessageHandler
// Desc: Handler for DirectPlay messages.
//-----------------------------------------------------------------------------
HRESULT WINAPI DirectPlayMessageHandler(PVOID pvUserContext, DWORD
dwMessageId, PVOID pMsgBuffer)
{
HRESULT hr = S_OK;

switch (dwMessageId)
{
case DPN_MSGID_RECEIVE:
{
PDPNMSG_RECEIVE pMsg;

pMsg = (PDPNMSG_RECEIVE) pMsgBuffer;

printf("\nReceived Message: %S\n", (WCHAR*)pMsg->pReceiveData);

// HOW DO I CHANGE THE LINE, TOP OF THIS QUESTION, TO FORM TO
RECEIVE DATA TO "char/word/int g_MyData[256]"
// I TRYED THE CODE *g_MyData = (char *) pMsg->pReceiveData; BUT IT
GIVES ME AN ERROR.

break;
}
}
return hr;
}


Thank you greatly for your helping tips.

Yours : JariTapio / Helsinki / 06 July 2005
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,164
Messages
2,570,901
Members
47,439
Latest member
elif2sghost

Latest Threads

Top