解决CInternetSession运行异常的问题
来源:互联网 发布:各个协议的端口号列表 编辑:程序博客网 时间:2024/06/05 13:24
最近在做一个小任务,其中有一项功能是获取网页源码,VC中可以用CInternetSession来实现,以下为从MSDN摘下来的
CInternetSession session;
CHttpFile* file = NULL;
file = (CHttpFile *)session.OpenURL(_T("http://www.microsoft.com"));
if (NULL != file)
{
//Do something here with the web request
//Clean up the file here to avoid a memory leak!!!!!!!
file->Close();
delete file;
}
session.Close();
把上面的程序片断加到一个win32程序里,加上#include <afxinet.h>和一些必要的头文件,把项目属性->使用MFC改为“Use MFC in a Shared DLL”
可以编译通过,但在运行总是会出现异常,报告的错误为:
afxwin1.inl
Line: 29
调试跟踪到说AfxCurrentAppName为空。解决办法:
CWinApp app((LPCTSTR)argv[0]);
app.InitApplication();
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
分析:在win32程序中调用MFC中的类,需要初始化(这里写得模糊点,因为目前对MFC实在是一窍不通)。
#include <stdio.h>
#include <afxinet.h>
#include <afx.h>
#include <afxwin.h>
int main(int argc, char **argv)
{
CWinApp app((LPCTSTR)argv[0]);
app.InitApplication();
AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0);
CInternetSession session;
CHttpFile* file = NULL;
file = (CHttpFile *)session.OpenURL(_T("http://www.microsoft.com"));
if (NULL != file)
{
//Do something here with the web request
//Clean up the file here to avoid a memory leak!!!!!!!
file->Close();
delete file;
}
session.Close();
return 0;
}
ps:我遇到的问题,问了同事,在他的帮助下解决的,哈哈
- 解决CInternetSession运行异常的问题
- CInternetSession类OpenURL函数异常问题
- WIn32中CInternetSession运行异常(afxCurrentAppName 为空)
- Win32中CInternetSession运行异常(afxCurrentAppName 为空)
- WIn32中CInternetSession运行异常(afxCurrentAppName 为空)
- 解决tomcat上运行servlet使用jdbc异常的问题
- 调用CInternetSession::OpenURL()时的一个问题。
- WIn32中CInternetSession运行异常,主要是因为获取目前应用程序名出错
- 关于CInternetSession缓存问题
- 关于CInternetSession缓存问题
- 关于CInternetSession缓存问题
- 地税某数据库异常重启和重启后数据库运行缓慢问题的解决过程
- CInternetSession的使用
- CInternetSession的使用
- CInternetSession的简单使用
- CInternetSession的简单使用
- CInternetSession的简单使用
- CInternetSession的简单使用
- s:TextInput优化
- 二、线程API
- java开发环境的搭建-----mysql的下载与安装(四)
- HTTP协议头详解
- MVC 相关
- 解决CInternetSession运行异常的问题
- Android Service 通知Activity更新界面的方法研究
- 用形式化的容器来跑归并排序
- 进程与线程
- PDP
- 软件企业开发过程管理(听visual studio讲座有感)
- mplayer编译安装
- How to Make an HTTP Connection Using TCP/IP with RSocket
- 对LEON开发板进行配置所遇到的问题