RasSetEntryProperties函数返回632错误:
目前在修改一个mfc网络程序(使其支持windows7),其中用到网络虚拟拨号功能,但是我在调用RasSetEntryProperties这个方法时,总是会报错误
“632”,我在错误查找里了解是“The requested interface is not supported”,可是网络上搜索却有人说是数据参数结构错误。
代码如下
DWORD CreateRASEntry()
{
DWORD Err = ERROR_SUCCESS;
RASENTRY* pRasEntry = (RASENTRY*)malloc(SIZEOF_RASENTRY);
if (!pRasEntry)
{
DebugPrintString("Error: CreateRASEntry - Could not allocate memory for pRasEntry");
return ERROR_NOT_ENOUGH_MEMORY;
}
memset(pRasEntry,0,SIZEOF_RASENTRY);
pRasEntry->dwSize = sizeof(pRasEntry)/*SIZEOF_RASENTRY*/;
strcpy(pRasEntry->szLocalPhoneNumber,LOCAL_PHONE_NUMBER);
pRasEntry->dwfOptions = RASEO_ShowDialingProgress | RASEO_SwCompression;
pRasEntry->dwfNetProtocols = RASNP_Ip;
pRasEntry->dwFramingProtocol = RASFP_Ppp;
strcpy(pRasEntry->szDeviceType, RASDT_Isdn);
char szSystemLastDeviceName[255];
dwGetSystemLastRasDevice(szSystemLastDeviceName, 255);
strcpy(pRasEntry->szDeviceName, szSystemLastDeviceName);
pRasEntry->dwSubEntries = 0;
pRasEntry->dwType = RASET_Phone;
Err = ERROR_SUCCESS;
szRasentryName[0] = '\0';
if(IsWin64())
{
strncat(szRasentryName,RASENTRY_NAME_64,128);
}
else
{
strncat(szRasentryName,RASENTRY_NAME_32,128);
}
Err = RasSetEntryProperties (NULL, szRasentryName, pRasEntry,pRasEntry->dwSize, NULL, 0);
if (ERROR_SUCCESS != Err)
{
DebugPrintString("Error: CreateRASEntry - failed, errorcode = %d", Err);
free(pRasEntry);
return Err;
}
DebugPrintString("Info: CreateRASEntry - Success");
free(pRasEntry);
vSetRASAutoDialDefault(szRasentryName);
return Err;
}
这段代码在windowsxp下面执行没问题,但是到了windows7就会报错
哪位大虾帮忙看一下,到底有什么问题。
------解决方法--------------------------------------------------------
应该使用RasGetEntryProperties取得size
参考:
The size of the RASENTRY structure on the build plaform (WINVER). Use
RasGetEntryProperties() to get the size of a RAS entry in a
platform-independent way...
DWORD dwEntryInfoSize = 0;
(void) RasGetEntryProperties(NULL, NULL, NULL, &dwEntryInfoSize, NULL,
NULL);
....and use dwEntryInfoSize instead of sizeof(RASENTRY).