An application can use the RasGetEntryProperties function or the RasSetEntryProperties function to copy the configuration data to another entry. The lpszEntryName parameter can be used to change the entry.
The following code example shows how to copy a RAS entry.
BOOL CopyRasEntry (LPTSTR lpszEntryName)
{
BOOL bPasswordSaved;
TCHAR szNewEntryName[100]; // Name for the copied entry
TCHAR szError[100]; // Buffer for the error message
DWORD dwError, // Return code from the functions
dwRasEntrySize, // Size of the RASENTRY structure
dwDevConfigSize, // Size of DevConfigBuf
dwDeviceNum = 0xFFFFFFFF; // Telephony API device number
BYTE DevConfigBuf[128]; // Buffer for device configuration
// data
RASENTRY RasEntry; // RASENTRY structure
RASDIALPARAMS RasDialParams; // RASDIALPARAMS structure
LPVARSTRING lpDevConfig = (LPVARSTRING)&DevConfigBuf;
// Pointer to the memory location of
// the device configuration structure
// Assign the name for the copied phone-book entry.
wsprintf (szNewEntryName, TEXT("%s1"), lpszEntryName);
// Validate the format of a connection entry name.
if (dwError = RasValidateEntryName (NULL, szNewEntryName))
{
wsprintf (szError, TEXT("Unable to validate entry name.")
TEXT(" Error %ld"), dwError);
return FALSE;
}
dwDevConfigSize = sizeof (DevConfigBuf);
dwRasEntrySize = sizeof (RASENTRY);
RasEntry.dwSize = dwRasEntrySize;
// Retrieve the entry properties.
if (dwError = RasGetEntryProperties (NULL,
lpszEntryName,
(LPBYTE)&RasEntry,
&dwRasEntrySize,
DevConfigBuf,
&dwDevConfigSize))
{
wsprintf (szError, TEXT("Unable to read entry properties.")
TEXT(" Error %ld"), dwError);
return FALSE;
}
memset (&RasDialParams, 0, sizeof (RasDialParams));
RasDialParams.dwSize = sizeof (RASDIALPARAMS);
_tcscpy (RasDialParams.szEntryName, lpszEntryName);
// Retrieve the connection data.
if (dwError = RasGetEntryDialParams (NULL, &RasDialParams,
&bPasswordSaved))
{
wsprintf (szError, TEXT("Unable to get the connection information.")
TEXT(" Error %ld"), dwError);
return FALSE;
}
// Create a new phone-book entry.
if (dwError = RasSetEntryProperties (NULL,
szNewEntryName,
(LPBYTE)&RasEntry,
dwRasEntrySize,
DevConfigBuf,
dwDevConfigSize))
{
wsprintf (szError, TEXT("Unable to copy the phonebook entry.")
TEXT(" Error %ld"), dwError);
return FALSE;
}
_tcscpy (RasDialParams.szEntryName, szNewEntryName);
// Change the connection data.
if (dwError = RasSetEntryDialParams (NULL, &RasDialParams, FALSE))
{
wsprintf (szError, TEXT("Unable to set the connection information.")
TEXT(" Error %ld"), dwError);
return FALSE;
}
return TRUE;
}