RasSetEntryProperties函数返回632错误

zjcdxx2000 2009-08-24 10:27:02
目前在修改一个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就会报错
哪位大虾帮忙看一下,到底有什么问题。
...全文
404 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcdxx2000 2009-08-25
  • 打赏
  • 举报
回复
搞定了,感谢楼上的帮忙
在windows7下面不可以用malloc来申请空间,奇怪吧
最后我是直接声明一个RASENTRY pRasEntry 来处理的
宝_爸 2009-08-25
  • 打赏
  • 举报
回复
难道windows7不支持。我google了下,没又发现相关内容。

估计最好直接问微软
宝_爸 2009-08-25
  • 打赏
  • 举报
回复
不会吧malloc不是C的库吗
宝_爸 2009-08-24
  • 打赏
  • 举报
回复
我转帖的内容不是写了不能用sizeof(pRasEntry)吗
zjcdxx2000 2009-08-24
  • 打赏
  • 举报
回复
可是我也有写啊,请看
pRasEntry->dwSize = sizeof(pRasEntry)/*SIZEOF_RASENTRY*/;
两个我都试的,sizeof和0
但是都不行。
宝_爸 2009-08-24
  • 打赏
  • 举报
回复
应该使用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).



zjcdxx2000 2009-08-24
  • 打赏
  • 举报
回复
之前我也使用一个DWORD的值来作为参数赋值的,就是后面注释的那个“SIZEOF_RASENTRY”,其值为0,这个程序在win2k/winxp下面运行正常
但是到了windows7死活就不行了,debug的返回值是632,我才改来该去的
而且使用RasGetEntryProperties获得的size也不行,依然是632错误

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧