Win7的服务程序中不能调用WinInet API吗

xqchang 2011-04-15 09:55:09
用VC6编写的服务程序,XP下一切正常,在Win7上也能运行,服务程序中的其它功能都正常,但就是一调用WinInet API就阻塞了,比如,在调用InternetOpen函数时,就阻塞住不继续运行了,不知道什么原因,谁有这方面的经验啊?
...全文
369 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqchang 2011-04-16
  • 打赏
  • 举报
回复
真的有变化了,见MSDN:

Note WinINet does not support server implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP).

谢谢大家了!
ArcRain 2011-04-16
  • 打赏
  • 举报
回复
MSDN里有这么个说明:Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and destructors of global objects.
可以检查看看。
xqchang 2011-04-16
  • 打赏
  • 举报
回复
在普通的应用程序都是好好的,就是在Win7的服务程序中,到这一句就不往下执行了。
	hInternet = InternetOpen("MSIE 6.0",
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
ArcRain 2011-04-16
  • 打赏
  • 举报
回复
因为WinInet的版本不同了,这个文件和IE绑定的,IE版本不同,WinInet的版本也不同,所以工作时可能也会略有差异。
InternetOpen调用返回应该也还快的,不知道你InternetOpen是如何调用的。
xqchang 2011-04-16
  • 打赏
  • 举报
回复
或是SYSTEM用户不能调用WinInet?
xqchang 2011-04-16
  • 打赏
  • 举报
回复
是不是因为Win7对IE的保护加强了,因而对WinInet API的调用也有限制?我的系统是Win7 SP1+IE9,服务程序中其它功能都正常,用Winsock也能通信,但就是不能用WinInet,InternetOpen就进行不下去,阻塞住了。
xqchang 2011-04-16
  • 打赏
  • 举报
回复
谢谢大家的热心回复。不是超时设置或同步异步的问题,在Win7的普通的应用程序中,使用WinInet是没有任何问题的,我现在的情况是,在服务程序中一调用InternetOpen就阻塞了,但在XP下正常的。Win7的服务程序中要使用WinInet API需要注意些什么啊?
Eleven 2011-04-15
  • 打赏
  • 举报
回复
关于InternetSetOption 不能设置超时值的说明:

Calling InternetSetOption (or MFC CHttpFile::SetOption) with INTERNET_OPTION_SEND_TIMEOUT or INTERNET_OPTION_CONNECT_TIMEOUT does not set the specified timeout values.
RESOLUTION
To work around the problem you can use asynchronous WinInet mode, which prevents the WinInet function call from blocking while waiting for a connection. Please see the Internet Client SDK documentation for more information about using WinInet asynchronously.

Another solution may be to create a second thread that would call blocking WinInet API. Closing the handle from within the original thread will cancel blocking API in the second thread. Please see documentation for InternetCloseHandle for more details.
Eleven 2011-04-15
  • 打赏
  • 举报
回复
Eleven 2011-04-15
  • 打赏
  • 举报
回复
Dreadnought 2011-04-15
  • 打赏
  • 举报
回复
在win7里运行调用 InternetSetOption等函数的程序没发现问题...

15,473

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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