CInternetSession and OpenURL on Windows Mobile fails
Hi there
I am trying to establish an Internet session (HTTP GET) with a MFC
application on a Windows Mobile 6 platform. First I tried with
OpenRequest() and SendRequest(), but when the code reached SendRequest
() the application crashed in the evil way. Secondily I tried to use
OpenURL() but it keeps saying that it cannot find the server. I have
even connected the device to my WLAN to ensure I had a stable Internet
connection.
-- snip --
CString GoogleMap::getMapUrl(int width, int height, double lng, double
lat, int zoom, CString format)
{
char * szUrl = (char*)malloc(256);
char * szFormat = "http://maps.google.com/staticmap?center=%f,
%f&format=%s&zoom=%d&size=%dx%d&key=%s";
sprintf(szUrl, szFormat, lat, lng, format, zoom, width, height,
m_szAPIKey);
CString s = CString(szUrl);
return s;
}
BYTE* GoogleMap::loadHttpFile(CString url, long &length /* length of
bytes received */)
{
BYTE* buffer = NULL;
CInternetSession session;
CHttpConnection * hc = NULL;
hc = session.GetHttpConnection(_T("maps.google.com"), 0, 80, NULL,
NULL);
if (!hc) return NULL;
//CHttpFile* pFile = hc->OpenRequest(CHttpConnection::HTTP_VERB_GET,
_T("index.html") /* file */);
//pFile->SendRequest();
CHttpFile* pFile = (CHttpFile*)session.OpenURL(url);
length = (long)pFile->GetLength();
if (!length) return NULL;
buffer = (BYTE*)malloc(length + 1);
memset(buffer, 0, length +1);
for (DWORD dwRead1;dwRead1=pFile->Read(buffer,length););
return buffer;
}
-- snip --
Could someone please tell me what I do wrong?
Thanks in advance,
Jess