简体   繁体   中英

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). I always get an exception with error code 12029 (cannot connect).

I suspect that I need to use the Connection Manager API to create a connection first. 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. 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 ; nevertheless, I call CInternetSession::OpenURL immediately afterwards and it throws an exception.

Here's some code that works. It uses the lower-level Windows API, not MFC. Perhaps it's not ideal and contains redundancies (do I really need the ConnMgr calls?), but it does work:

// 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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