🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Listing available modems

Started by
4 comments, last by ByteMe95 23 years, 9 months ago
I''m trying to set up multiplayer in my game wihtout using annoying window dialog boxes, and I have to get the modem connection working. So I need to be able to get the list of modems installed on the computer in order to do this. I found that GetPlayerAddress(...) will give you a list of modems if you pass 0 for the player ID, but I still dont know how to use it. What variable should I pass in as the buffer for the modem name data? A string? an array of strings? etc. And if I want a list of modems, do I have to figure out the buffersize first too or it''s different if I just want the modems? Thanks in advance. A little code snippet would be helpful too. - Rob ByteMe95::~ByteMe95() Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
Advertisement
I don''t know how far you''re into programming it, but there is the RasApi that is for this stuff. The function RasEnumConnections will return an array of connections. Then you can go through each one checking ->szDeviceType and
->szDeviceName. I hope that answers your question.
Code to do just that from my project (DX6).

dp - Pointer to DIRECTPLAY4
dp_lobby - Pointer to DIRECTPLAYLOBBY3

Hope you'll figure it out...

    //--------------------------------------------------------------------------------------------------------//	PUBLIC:		DP_enum_modems//	//	PURPOSE:	Enumerate available modems.//				Array of modem infos is allocated ind filled. This array has to be freed by the caller.//--------------------------------------------------------------------------------------------------------//	Static variables to pass into callback.#define MAX_MODEMS				10typedef struct DP_MODEMINFO_STRUCT{	char				name[64];}DP_MODEMINFO_STRUCT;static DP_MODEMINFO_STRUCT*		_modem_infos;static int*						_num_modems;bool DP_enum_modems( DP_MODEMINFO_STRUCT** modem_infos, int* num_modems ){	HRESULT				result;	void*				buf = 0;	DWORD				size;	LPDIRECTPLAY4		temp_dp;		assert( modem_infos );	assert( num_modems );	if( !is_initialized )		{ SetLastError( DPERR_UNINITIALIZED ); return false; }		//	Allocate array of infos.		*num_modems = 0;	*modem_infos = ( DP_MODEMINFO_STRUCT* )malloc( sizeof( DP_MODEMINFO_STRUCT ) * MAX_MODEMS );	if( *modem_infos == 0 )		{ SetLastError( ERROR_OUTOFMEMORY ); return false; }		_modem_infos = *modem_infos;	_num_modems = num_modems;		//	Create modem provider.		result = dp_lobby->CreateAddress( DPSPGUID_MODEM, DPAID_TotalSize, 0, 0, 0, &size );	if( result != DPERR_BUFFERTOOSMALL )		goto error;		buf = malloc( size );	if( buf == 0 )		{ result = ERROR_OUTOFMEMORY; goto error; }		result = dp_lobby->CreateAddress( DPSPGUID_MODEM, DPAID_TotalSize, 0, 0, buf, &size );	if( result != DP_OK )		goto error;		//	Select modem provider.		#ifdef UNICODE	result = CoCreateInstance( CLSID_DirectPlay, 0, CLSCTX_ALL, IID_IDirectPlay4, ( void** )&temp_dp );	#else	result = CoCreateInstance( CLSID_DirectPlay, 0, CLSCTX_ALL, IID_IDirectPlay4A, ( void** )&temp_dp );	#endif		result = temp_dp->InitializeConnection( buf, 0 );	free( buf ); buf = 0;	if( result != DP_OK )		goto error;		//	Enumerate modems.		result = temp_dp->GetPlayerAddress( 0, 0, &size );	if( result != DPERR_BUFFERTOOSMALL )		goto error;		buf = malloc( size );	if( buf == 0 )		{ result = ERROR_OUTOFMEMORY; goto error; }		result = temp_dp->GetPlayerAddress( 0, buf, &size );	if( result != DP_OK )		goto error;			result = dp_lobby->EnumAddress( enum_address_callback, buf, size, *modem_infos );	if( result != DP_OK )		goto error;		//	Done.		free( buf );	return true;	error:		SetLastError( result );	if( buf ) free( buf );	if( *modem_infos ) { free( *modem_infos ); *modem_infos = 0; }	return false;}BOOL PASCAL enum_address_callback( REFGUID guid, DWORD size, const void* data, void* ){	char*	str;		if( memcmp( &guid, &DPAID_Modem, sizeof( GUID ) ) != 0 )		return true;		if( *_num_modems >= MAX_MODEMS )		return false;		str = ( char* )data;		while( lstrlen( str ) )	{		memset( _modem_infos[ *_num_modems ].name, 0, sizeof( _modem_infos[ *_num_modems ].name ) );		strncpy( _modem_infos[ *_num_modems ].name, str, sizeof( _modem_infos[ *_num_modems ].name ) - 1 );		( *_num_modems )++;		str += lstrlen( str ) + 1;	}		return true;}    


Cheers
Meduzza

Edited by - Meduzza on September 12, 2000 7:28:55 PM

Edited by - Meduzza on September 12, 2000 7:30:29 PM
Meduzza
thanx a lot for the code
it looks good, I''m gonna have to try it (or some version of it)

I never thought to create a temp DP object for the first initializeconnection call, that kinda threw me off


ByteMe95::~ByteMe95()
Cerebrum Software
ByteMe95::~ByteMe95()My S(h)ite
Yeah, that DirectPlay crap is really freaky... It took me awhile to figure it out. I hope they made API easier in DX8.
Oopsie... i think i forget to release temp_dp.

This topic is closed to new replies.

Advertisement