简体   繁体   English

Windows Mobile上的CInternetSession :: OpenURL导致错误12029(无法连接)

[英]CInternetSession::OpenURL on Windows Mobile causes error 12029 (cannot connect)

I'm trying to access data using HTTP by calling CInternetSession::OpenUrl on Windows Mobile 5 (coding in C++ with MFC). 我试图通过在Windows Mobile 5上调用CInternetSession :: OpenUrl(使用MFC在C ++中进行编码)使用HTTP访问数据。 I always get an exception with error code 12029 (cannot connect). 我总是收到错误代码为12029的异常(无法连接)。

I suspect that I need to use the Connection Manager API to create a connection first. 我怀疑我需要首先使用连接管理器API创建连接。 Can someone confirm that? 有人可以确认吗?

I am going to try coding it up, based on information here ( http://msdn.microsoft.com/en-us/magazine/dd263096.aspx ), and I'll report my experiences as an answer if appropriate. 我将根据此处的信息( http://msdn.microsoft.com/zh-cn/magazine/dd263096.aspx )尝试对其进行编码,如果合适,我将报告我的经验作为答案。 It would be nice to get other input too. 也可以得到其他输入。

I have successfully opened a connection using this code: 我已经使用以下代码成功打开了连接:

// Find out which type of connection is needed for this URL.
GUID guid;
HRESULT hresult = ConnMgrMapURL((LPCTSTR)url,&guid,NULL);
if (!SUCCEEDED(hresult))
{
delete [] url;
aError = CartoType::KErrorInternetIo;
return NULL;
}

// Get a connection.
CONNMGR_CONNECTIONINFO cinfo;
memset(&cinfo,0,sizeof(cinfo));
cinfo.cbSize = sizeof(cinfo);
cinfo.bDisabled = FALSE;
cinfo.bExclusive = FALSE;
cinfo.guidDestNet = guid;
cinfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
cinfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
cinfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
DWORD status;
hresult = ConnMgrEstablishConnectionSync(&cinfo,&iConnectionHandle,15000,&status);

and I know that it worked because it sets status to CONNMGR_STATUS_CONNECTED ; 而且我知道它起作用是因为它将状态设置为CONNMGR_STATUS_CONNECTED ; nevertheless, I call CInternetSession::OpenURL immediately afterwards and it throws an exception. 但是,此后我立即调用CInternetSession::OpenURL并引发异常。

Here's some code that works. 这是一些有效的代码。 It uses the lower-level Windows API, not MFC. 它使用较低级别的Windows API,而不是MFC。 Perhaps it's not ideal and contains redundancies (do I really need the ConnMgr calls?), but it does work: 也许它不是理想的并且包含冗余(我真的需要ConnMgr调用吗?),但是它确实起作用:

// Find out which type of connection is needed for this URL.
GUID guid;
HRESULT hresult = ConnMgrMapURL((LPCTSTR)url,&guid,NULL);
if (!SUCCEEDED(hresult))
    {
    delete [] url;
    aError = CartoType::KErrorInternetIo;
    return NULL;
    }

// Get a connection.
CONNMGR_CONNECTIONINFO cinfo;
memset(&cinfo,0,sizeof(cinfo));
cinfo.cbSize = sizeof(cinfo);
cinfo.bDisabled = FALSE;
cinfo.bExclusive = FALSE;
cinfo.guidDestNet = guid;
cinfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
cinfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
cinfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
DWORD status;
hresult = ConnMgrEstablishConnectionSync(&cinfo,&iConnectionHandle,15000,&status);

HINTERNET hinternet = InternetOpen(_T("CartoType"),INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
HINTERNET hfile = InternetOpenUrl(hinternet,(LPCTSTR)url,NULL,0,0,1);

This returns a valid handle that I can read using InternetReadFile, then close using InternetCloseHandle. 这将返回一个有效的句柄,我可以使用InternetReadFile读取该句柄,然后使用InternetCloseHandle关闭它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM