Listing 10

void SaveMapBitmap(CHAR* szData)
{
    HBITMAP hBmp = NULL;
    CHAR* pszStart = strstr(szData, "<Bits>");
    if (pszStart)
    {
        pszStart+= strlen("<Bits>" );
        CHAR* pszEnd = strstr(szData, "</Bits>");
        int nLen = pszEnd-pszStart;
        CHAR* pBits = new CHAR[nLen];
        strncpy(pBits,pszStart, nLen );
        BYTE *pConvertedBuffer = NULL;      
        int nSize = 0;
        Base64Decode(pBits, nLen, NULL, &nSize);
        pConvertedBuffer = new BYTE[nSize+1];
        Base64Decode(pBits, nLen, pConvertedBuffer, &nSize);
        HANDLE hFile = CreateFile(_T("C:\\MapImage.bmp"), GENERIC_WRITE, 
            0, NULL, CREATE_ALWAYS, 0, 0);
        if (hFile != INVALID_HANDLE_VALUE) 
        { 
            DWORD dwBytes = 0;
            WriteFile(hFile, pConvertedBuffer, nSize, &dwBytes,NULL);
            CloseHandle(hFile);
        }
        delete [] pConvertedBuffer;
        delete [] pBits;
    }
}