RasSetEntryProperties returns error 816 in Vista

E

erajaysharma

Hi,

I am trying to make a dial up connection in Vista using
RasSetEntryProperties function...but it is returning error code
816.... it runs fine in XP...I am using the following code....Can any
one please tell why this is happening and what should i do to get rid
of it....

Many thanks in advance...
Ajay

struct DIALUP_ICON_PROPERTIES
{
RASENTRY *rasEntry;
DWORD rasEntrySize;
BYTE *deviceInfo;
DWORD deviceInfoSize;
}props;

//getIconProperties returns successfully. problem is with
RasSetEntryProperties
void createDialup()
{
const char *dialupName;
char* driverType;
char* vci;
char* vpi;
char* encapsulation;

dialupName = "Centragate";
driverType = "\"WAN\"";
vci = "0";
vpi = "77";
encapsulation = "8";

if (getIconProperties(_T(""), &props))
{
printf("Can't get default connecton id");
return;
}

props.rasEntry->dwfOptions = RASEO_RemoteDefaultGateway |
RASEO_ModemLights |
RASEO_SecureLocalFiles; // disables file and print
sharing and ms networks
props.rasEntry->dwFramingProtocol = RASFP_Ppp;
props.rasEntry->dwfNetProtocols = RASNP_Ip;
props.rasEntry->dwIdleDisconnectSeconds =
RASIDS_Disabled;
_stprintf(props.rasEntry->szLocalPhoneNumber, _T("%s,%s"), vpi, vci);

// Which dialup device are we going to use?

LPRASDEVINFO lpRasDevInfo = NULL;
DWORD nRasDevInfoSize = 0;
DWORD cRasDevices = 0;

DWORD nRet = RasEnumDevices(NULL, &nRasDevInfoSize, &cRasDevices);
if (nRet == ERROR_BUFFER_TOO_SMALL && nRasDevInfoSize > 0)
{
lpRasDevInfo = (LPRASDEVINFO) new BYTE[nRasDevInfoSize];
lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
nRet = RasEnumDevices(lpRasDevInfo, &nRasDevInfoSize, &cRasDevices);
}

if (nRet != 0 || cRasDevices == 0)
{
printf("No RAS devices found");
return;
}

_tcscpy(props.rasEntry->szDeviceType, RASDT_Modem);
_tcscpy(props.rasEntry->szDeviceName, "Conexant USB ADSL WAN Modem");

nRet = RasSetEntryProperties(NULL, dialupName,
props.rasEntry, props.rasEntrySize,
props.deviceInfo, props.deviceInfoSize);

if (nRet != 0)
{
printf("Can't set RAS properties\n");
return;
}
return;
}

//Returns TRUE if failes FALSE if succeeds
BOOL getIconProperties(LPCTSTR iconName, struct DIALUP_ICON_PROPERTIES
*iconProps)
{
RASENTRY *rasEntry = NULL;
BYTE *deviceInfo = NULL;
DWORD rasEntrySize = 0;
DWORD deviceInfoSize = 0;

DWORD nRet
RasGetEntryPropertiesNULL,iconName,NULL,&rasEntrySize,NULL,&deviceInfoSize);

if (nRet != ERROR_BUFFER_TOO_SMALL || rasEntrySize == 0)
{
printf("RasGetEntryProperties error:
ret=%d,name=%s", nRet, iconName);
return TRUE;
}

rasEntry = (RASENTRY *) new BYTE[rasEntrySize];
if (rasEntry == NULL)
{
return TRUE;
}

rasEntry->dwSize = rasEntrySize;
nRet =
RasGetEntryProperties(NULL,iconName,rasEntry,&rasEntrySize,NULL,&deviceInfoSize);

if (deviceInfoSize)
{
deviceInfo = new BYTE[deviceInfoSize];
if (deviceInfo == NULL)
{
delete [] rasEntry;
return TRUE;
}
}

// now get the actual properties
nRet = RasGetEntryProperties
(NULL,iconName,rasEntry,&rasEntrySize,deviceInfo,&deviceInfoSize);

// See if we got one.
if (rasEntry == NULL || nRet != 0)
{
if (deviceInfo)
delete [] deviceInfo;
if (rasEntry)
delete [] rasEntry;
printf("RasGetEntryProperties error: ret=%d,name=%s", nRet,
iconName);
return TRUE;
}

iconProps->rasEntry = rasEntry;
iconProps->rasEntrySize = rasEntrySize;
iconProps->deviceInfo = deviceInfo;
iconProps->deviceInfoSize = deviceInfoSize;
return FALSE;
}
 
E

erajaysharma

Hi,

I am trying to make a dial up connection in Vista usingRasSetEntryPropertiesfunction...but it is returning error code816.... it runs fine in XP...I am using the following code....Can any
one please tell why this is happening and what should i do to get rid
of it....

Many thanks in advance...Ajay

struct DIALUP_ICON_PROPERTIES
{
RASENTRY *rasEntry;
DWORD rasEntrySize;
BYTE *deviceInfo;
DWORD deviceInfoSize;

}props;

//getIconProperties returns successfully. problem is withRasSetEntryProperties
void createDialup()
{
const char *dialupName;
char* driverType;
char* vci;
char* vpi;
char* encapsulation;

dialupName = "Centragate";
driverType = "\"WAN\"";
vci = "0";
vpi = "77";
encapsulation = "8";

if (getIconProperties(_T(""), &props))
{
printf("Can't get default connecton id");
return;
}

props.rasEntry->dwfOptions = RASEO_RemoteDefaultGateway |
RASEO_ModemLights |
RASEO_SecureLocalFiles; // disables file and print
sharing and ms networks
props.rasEntry->dwFramingProtocol = RASFP_Ppp;
props.rasEntry->dwfNetProtocols = RASNP_Ip;
props.rasEntry->dwIdleDisconnectSeconds =
RASIDS_Disabled;
_stprintf(props.rasEntry->szLocalPhoneNumber, _T("%s,%s"), vpi, vci);

// Which dialup device are we going to use?

LPRASDEVINFO lpRasDevInfo = NULL;
DWORD nRasDevInfoSize = 0;
DWORD cRasDevices = 0;

DWORD nRet = RasEnumDevices(NULL, &nRasDevInfoSize, &cRasDevices);
if (nRet == ERROR_BUFFER_TOO_SMALL && nRasDevInfoSize > 0)
{
lpRasDevInfo = (LPRASDEVINFO) new BYTE[nRasDevInfoSize];
lpRasDevInfo->dwSize = sizeof(RASDEVINFO);
nRet = RasEnumDevices(lpRasDevInfo, &nRasDevInfoSize, &cRasDevices);
}

if (nRet != 0 || cRasDevices == 0)
{
printf("No RAS devices found");
return;
}

_tcscpy(props.rasEntry->szDeviceType, RASDT_Modem);
_tcscpy(props.rasEntry->szDeviceName, "Conexant USB ADSL WAN Modem");

nRet =RasSetEntryProperties(NULL, dialupName,
props.rasEntry, props.rasEntrySize,
props.deviceInfo, props.deviceInfoSize);

if (nRet != 0)
{
printf("Can't set RAS properties\n");
return;
}
return;

}

//Returns TRUE if failes FALSE if succeeds
BOOL getIconProperties(LPCTSTR iconName, struct DIALUP_ICON_PROPERTIES
*iconProps)
{
RASENTRY *rasEntry = NULL;
BYTE *deviceInfo = NULL;
DWORD rasEntrySize = 0;
DWORD deviceInfoSize = 0;

DWORD nRet
RasGetEntryPropertiesNULL,iconName,NULL,&rasEntrySize,NULL,&deviceInfoSize);

if (nRet != ERROR_BUFFER_TOO_SMALL || rasEntrySize == 0)
{
printf("RasGetEntryProperties error:
ret=%d,name=%s", nRet, iconName);
return TRUE;
}

rasEntry = (RASENTRY *) new BYTE[rasEntrySize];
if (rasEntry == NULL)
{
return TRUE;
}

rasEntry->dwSize = rasEntrySize;
nRet =
RasGetEntryProperties(NULL,iconName,rasEntry,&rasEntrySize,NULL,&deviceInfoSize);

if (deviceInfoSize)
{
deviceInfo = new BYTE[deviceInfoSize];
if (deviceInfo == NULL)
{
delete [] rasEntry;
return TRUE;
}
}

// now get the actual properties
nRet = RasGetEntryProperties
(NULL,iconName,rasEntry,&rasEntrySize,deviceInfo,&deviceInfoSize);

// See if we got one.
if (rasEntry == NULL || nRet != 0)
{
if (deviceInfo)
delete [] deviceInfo;
if (rasEntry)
delete [] rasEntry;
printf("RasGetEntryProperties error: ret=%d,name=%s", nRet,
iconName);
return TRUE;
}

iconProps->rasEntry = rasEntry;
iconProps->rasEntrySize = rasEntrySize;
iconProps->deviceInfo = deviceInfo;
iconProps->deviceInfoSize = deviceInfoSize;
return FALSE;

}


I have solved this problem....I just added one line "memset(rasEntry,
0,rasEntrySize);" and it started working... Acutally there were some
garbage values in rasEntry structure. Memsetting it solved the
problem...Search for memset(rasEntry,0,rasEntrySize); in the code
below....

BOOL getIconProperties(LPCTSTR iconName, struct
DIALUP_ICON_PROPERTIES
*iconProps)
{
RASENTRY *rasEntry = NULL;
BYTE *deviceInfo = NULL;
DWORD rasEntrySize = 0;
DWORD deviceInfoSize = 0;

DWORD nRet
RasGetEntryPropertiesNULL,iconName,NULL,&rasEntrySize,NULL,&deviceInfoSize);

if (nRet != ERROR_BUFFER_TOO_SMALL || rasEntrySize == 0)
{
printf("RasGetEntryProperties error:
ret=%d,name=%s", nRet, iconName);
return TRUE;
}

rasEntry = (RASENTRY *) new BYTE[rasEntrySize];
/***********************************************/
memset(rasEntry,0,rasEntrySize);
/***********************************************/
if (rasEntry == NULL)
{
return TRUE;
}

rasEntry->dwSize = rasEntrySize;
nRet =
RasGetEntryProperties(NULL,iconName,rasEntry,&rasEntrySize,NULL,&deviceInfoSize);

if (deviceInfoSize)
{
deviceInfo = new BYTE[deviceInfoSize];
if (deviceInfo == NULL)
{
delete [] rasEntry;
return TRUE;
}
}

// now get the actual properties
nRet = RasGetEntryProperties
(NULL,iconName,rasEntry,&rasEntrySize,deviceInfo,&deviceInfoSize);

// See if we got one.
if (rasEntry == NULL || nRet != 0)
{
if (deviceInfo)
delete [] deviceInfo;
if (rasEntry)
delete [] rasEntry;
printf("RasGetEntryProperties error: ret=%d,name=%s", nRet,
iconName);
return TRUE;
}

iconProps->rasEntry = rasEntry;
iconProps->rasEntrySize = rasEntrySize;
iconProps->deviceInfo = deviceInfo;
iconProps->deviceInfoSize = deviceInfoSize;
return FALSE;
}
 

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

Similar Threads


Top