rapi copy problem

J

John Kirk

Hi all,

I'm using a Type Library in VB6 that I found somewhere through a link in
this group to help copy XML files from my PPC device to the desktop using
RAPI. The copy seems to work fine except that the files I'm copying across
won't open properly when they get to the desktop. If I open the XML file in
Internet Explorer it reports:

End of file reached in invalid state for current encoding.

and then gives me the line number it occurs on (the last one) and the text
"</xml>"

If I open the files in notepad they look fine. So here's the odd thing. If
I don't make any changes to the document while I have it open in notepad but
do a "File / Save" anyway, then the document opens fine in IE.

So I guess the XML file is missing some sort of EOF marker or has the wrong
type of marker or something? If I copy the same file across using
activesync it works fine.

The copy is done by reading the file into a binary array and then writing
that back out using the VB6 'Put' function.

Anyone have any ideas?

John
 
C

Chris Tacke, eMVP

It's probably an ANSI v. Unicode issue. Look at the original and re-saved
working one on a binary level and see if they're different (checking for a
size difference will also tell you).
 
J

John Kirk

Thanks for the pointer Chris, it helped me find the bug.

The version which works (ie I open it in Notepad and save it) is 1 byte
smaller than the original. So I edited the code that creates the file on
the desktop and told it not to write the last byte. Problem solved!

Turns out is was the usual 0 based array problem. I was getting the number
of bytes that had been copied and then looped through the array of bytes
from 0 to that number (instead of the number -1) and writing them out. So I
was writing an empty byte at the end of the file which was obviously causing
problems.

The code I was using is based on that from:
http://www.devbuzz.com/content/zinc_eVB_copy_files_to_device_II_pg1.asp
on page 2 of the article and I notice that the original code also has the
bug.

Thanks again,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top