passing an IP address to an DirectPlay Address object

Started by
5 comments, last by leggyguy 22 years, 7 months ago
Hi, another DP question Hope no one gets board of me asking. I am asking my user for the target ip address. All the SP details necassary are already in the address objects, but I need to pass to the app the IP address we want to connect to. Now, I can set in Peer::EnumHosts the flag "oktoqueryforaddressing" in which case the app will bring up a dialog box which asks for the remote machine's address. This is fine, but my app is DirectDraw based and the dialog box crashes the app. So I am now asking the user for the IP address directly through the app. But I need to know where that IP address should be stored, and if I should modify the string containing that IP address before I call the function that will store it. I am sure it goes somewhere in the hostAddress, but I cannot think how to put it there. Can anyone point me in the right direction? Oh yes, I should mention that I also do NOT want to copy over or delete the SP info already contained within the Address object. Edited by - Leggyguy on September 19, 2001 3:27:50 PM
Advertisement
with VB:

    objDPServerAddress.AddComponentString DPN_KEY_HOSTNAME, strServerIP    objDPServerAddress.AddComponentLong DPN_KEY_PORT, intServerPort        AppDesc.guidApplication = AppGuid    ''AppDesc.lFlags = DPNSESSION_NODPNSVR    objDPClient.Connect AppDesc, objDPServerAddress, objDPClientAddress, 0, UserString, Len(UserString) 

www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
Ah, I should have mentioned that I am working in C++, and using DirectX 8.

But thanks for the reply, ajoling.

If anyone else knows how to do what I am trying, I am still trying to figure it out.

Thanks.

You can supply the address in string format, i.e. "" for a null address (used when doing an enumeration and you just want to do a general LAN search) or "10.0.0.25" say if you are refering to a specific address.

You can use the AddComponent() method of your IDirectPlay8Address object with pwszName=DPNA_KEY_HOSTNAME and dwDataType=DPNA_DATATYPE_STRING.

Remember that it expects a wide format Unicode string and not an Ansi string so you must convert your string first.

Your code might look something like this, where szIPAddress is the provided active parameter:



WCHAR* wszHostName = NULL;


// Set the remote host name (if provided)
if( (szIPAddress!=NULL) && (szIPAddress[0]!=0) )
{
wszHostName = new WCHAR[strlen(szIPAddress)+1];

DXUtil_ConvertGenericStringToWide( wszHostName, szIPAddress, (strlen(szIPAddress)+1)*sizeof(WCHAR) );

if( FAILED( hr = pDP8AddressHost->AddComponent( DPNA_KEY_HOSTNAME, wszHostName, (wcslen(wszHostName)+1)*sizeof(WCHAR), DPNA_DATATYPE_STRING ) ) )
{
goto CLEANUP;
}
}


Hope this helps.

The C++ code is almost the same (Like FVector4 shows), that''s why I posted it...
www.persistentrealities.com for Inline ASM for VB, VB Fibre, and other nice code samples in C++, PHP, ASP, etc.<br/>Play Yet Another Laser Game!<br/>
As Ajoling says the "BASIC"''s is there and they both equate to the same thing.

That is BASIC_VERSION==C++_VERSION is TRUE.

>8)
I just want to say, thanks a lot guys.

I am at work, and haven''t tried it out yet, but it does clarify some of the documentation that I didn''t quite follow.

I am pretty sure that will clear up that detail for me. So again, thanks. I really appreciate the help. And it really nice to find people who want to help others learn.

This topic is closed to new replies.

Advertisement