locked
Cannot load xml file larger than 32768 chars in Windows Mobile 5.0 application on an HP iPAQ RRS feed

  • Question

  • Hello,

    I am currently debugging a C++ application on an HP iPAQ running Windows Mobile 5.0.

    The app loads an xml file (in text format) and parses it to create a menu to control devices remotely.

    The buffer for the xml file has the constant size of BUFFERSIZE=32768 which is too small to hold an newer extended version of the xml file:

        char buffer[BUFFERSIZE];

        int size=0;
        int cursize=0;
        do{
            cursize=fread(buffer+size, 1, 1024, file);
            size+=cursize;
        }while(cursize==1024&&size<BUFFERSIZE);

    When loading the xml from this buffer (IXMLDOMDocument::loadXML()), the app returns a sytax error because it misses the closing tags near the end of the file. It just stops reading at BUFFERSIZE.

    However, when increasing BUFFERSIZE the app won't start.

    How large can a char array be in an mobile application?

    Where does the BUFFERSIZE=32768 limitation come from?

    How can I avoid it?

    I would prefer not having to migrate the whole application to a newer os version but if that is the only option please let me know.

     

    Thank you for your help :)

     

    Christian

    Monday, November 22, 2010 1:43 PM

Answers

  • Windows CE (and Mobile) are Unicode based systems so all strings should be 16 bit Unicode (WCHAR* or equivalent). If for some reason you prefer 8 bit strings then, as you need to use them with pretty much any OS function, you would need to convert them to/from Unicode.

    I'm not sure what A2BSTR() does (seems like a casting macro), but the proper way to convert is to use MultiByteToWideChar() API.

    I would suggest changing all 8 bit strings to Unicode instead so it would be easy to use and would be globalization friendly.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, November 23, 2010 5:46 PM

All replies

  • Not sure why that is (you should debug to find out) but simply get rid of the buffer and load file into DOM directly from the file using IXMLDOMDocument.load().

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, November 22, 2010 4:43 PM
  • How do I declare the VARIANT argument for the IXMLDOMDocument.load() function?

    I cannot find coherent information on this data type anywhere.

    The file name is stored in char menuname[256].

    Sth. like this?

        BSTR bstr = NULL;
        LPCWSTR lpcwstr_menuname = A2BSTR(menuname);
        bstr = SysAllocString ( lpcwstr_menuname );
        VARIANT vFile;
        vFile.bstrVal = bstr;
        hr = spXMLDOM->load(vFile, &bSuccess);

    But the string turns up empty and nothing is loaded.

    Tuesday, November 23, 2010 11:53 AM
  • Windows CE (and Mobile) are Unicode based systems so all strings should be 16 bit Unicode (WCHAR* or equivalent). If for some reason you prefer 8 bit strings then, as you need to use them with pretty much any OS function, you would need to convert them to/from Unicode.

    I'm not sure what A2BSTR() does (seems like a casting macro), but the proper way to convert is to use MultiByteToWideChar() API.

    I would suggest changing all 8 bit strings to Unicode instead so it would be easy to use and would be globalization friendly.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, November 23, 2010 5:46 PM
  • Like this?:

        int wideMenuNameSize = strlen(menuname) * 2;
        WCHAR* pWideMenuName = new WCHAR[wideMenuNameSize];
        BSTR bstr = NULL;
        MultiByteToWideChar( CP_ACP, 0, menuname, -1, pWideMenuName, wideMenuNameSize);
        bstr = SysAllocString ( pWideMenuName );
        VARIANT vFile;
        VariantInit(&vFile);
        VariantChangeType(&vFile, &vFile, VARIANT_NOUSEROVERRIDE, VT_BSTR);
        vFile.bstrVal = bstr;

    vField.bstrVal is still empty though.

    Also, when debugging this I cannot look at the values of simple variables such as wideMenuNameSize. Says "CXX0017: Error: Symbol not found" when added to the watch list.

    Same goes when trying to watch pWideMenuName.

    However, the value of menuname is watchable.

    When stepping through the code, the debugger skips the line vFile.bstrVal = bstr; entirely. what is going on?

    Wednesday, November 24, 2010 8:07 AM
  • Maybe vField.bstrVal just didn't show in the watch window.

    So I just tried it on the iPAQ and it works :)

    Thanks for the help, it is much appreciated :)

    Wednesday, November 24, 2010 9:07 AM