CInternetSession :: OpenURL on Windows Mobile raises error 12029 (unable to connect)
I am trying to access data using HTTP by calling CInternetSession :: OpenUrl on Windows Mobile 5 (C ++ encoding with MFC). I always get an exception with error code 12029 (can't connect).
I suspect that I need to use the Connection Manager API first to create a connection. Can anyone confirm this?
I'm going to try to code it based on the information here ( http://msdn.microsoft.com/en-us/magazine/dd263096.aspx ) and I'll share my experiences as an answer if needed. It would be nice to get some other input as well.
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 it worked because it sets the status CONNMGR_STATUS_CONNECTED
; however, I call CInternetSession::OpenURL
right after that and throws an exception.
Here's the code that works. It uses the Windows low level API, not MFC. It may not be perfect and contains redundancy (do I really need ConnMgr calls?), But it works:
// 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, which I can read with InternetReadFile and then close with InternetCloseHandle.