How to correctly fill the LPVOID Buffer in ReadFile() (C language)

280 views
Skip to first unread message

Sylvain Friquet

unread,
Sep 13, 2010, 6:12:02 AM9/13/10
to Dokan
Hi,

I am writing a FS connected to a remote server, based on the C Mirror
example.

If I understood the ReadFile correctly, Windows is requesting to read
a file from a given Offset and is expecting me to fill its Buffer,
with a maximum length of 4096.

My remote server is then reading the file and sending the requested
part, using send() and recv() calls.

I am currently doing ok with text files (.txt, .html ...) but I can't
get it to work with other format (such as music or image files).

I guess that I am not correctly filling the Buffer windows gives me,
and/or not dealing properly with encoding/charset issue.

I'd like to know what type Windows is expecting me to fill its Buffer
with?
I am receiving chars and obviously I can't just strcpy them into the
Buffer which is unfortunate :)

Thanks in advance for helping out,

Sylvain.




Fowl

unread,
Sep 13, 2010, 6:38:26 AM9/13/10
to do...@googlegroups.com
You should be dealing with bytes, not chars,

hth,
James





--
You received this message because you are subscribed to the Google Groups "Dokan" group.
To post to this group, send email to do...@googlegroups.com.
To unsubscribe from this group, send email to dokan+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dokan?hl=en.


Sylvain Friquet

unread,
Sep 13, 2010, 5:45:30 PM9/13/10
to Dokan
Hi James,

Thank you for the reply.

I'm now using BYTE (unsigned char) and I'm copying the data I receive
in recv() into windows' buffer using _mbsncpy().
I still can't get anything else than plain text files ...(for
instance, paint will say it can't get any preview, pdf readers will
just show a blank page, etc ...)
Is there something else I am missing (maybe wrong encoding on the
server side? I've tried with binary and ascii ...) .
I also tried giving the LPVOID Buffer parameter of ReadFile() directly
to recv() and it still doesn't work ... don't know what else to
try ...

On Sep 13, 12:38 pm, Fowl <f...@fowlsmurf.net> wrote:
> You should be dealing with bytes, not chars,
>
> hth,
> James
>
> On 13 September 2010 20:12, Sylvain Friquet <sylvain.friq...@gmail.com>wrote:
>
> > Hi,
>
> > I am writing a FS connected to a remote server, based on the C Mirror
> > example.
>
> > If I understood the ReadFile correctly, Windows is requesting to read
> > a file from a given Offset and is expecting me to fill its Buffer,
> > with a maximum length of 4096.
>
> > My remote server is then reading the file and sending the requested
> > part, using send() and recv() calls.
>
> > I am currently doing ok with text files (.txt, .html ...) but I can't
> > get it to work with other format (such as music or image files).
>
> > I guess that I am not correctly filling the Buffer windows gives me,
> > and/or not dealing properly with encoding/charset issue.
>
> > I'd like to know what type Windows is expecting me to fill its Buffer
> > with?
> > I am receiving chars and obviously I can't just strcpy them into the
> > Buffer which is unfortunate :)
>
> > Thanks in advance for helping out,
>
> > Sylvain.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Dokan" group.
> > To post to this group, send email to do...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > dokan+un...@googlegroups.com <dokan%2Bunsu...@googlegroups.com>.

Hiroki Asakawa

unread,
Sep 13, 2010, 7:35:22 PM9/13/10
to do...@googlegroups.com
On Tue, Sep 14, 2010 at 6:45 AM, Sylvain Friquet
<sylvain...@gmail.com> wrote:
> Hi James,
>
> Thank you for the reply.
>
> I'm now using BYTE (unsigned char) and I'm copying the data I receive
> in recv() into windows' buffer using _mbsncpy().
> I still can't get anything else than plain text files ...(for
> instance, paint will say it can't get any preview, pdf readers will
> just show a blank page, etc ...)
> Is there something else I am missing (maybe wrong encoding on the
> server side? I've tried with binary and ascii ...) .
> I also tried giving the LPVOID Buffer parameter of ReadFile() directly
> to recv() and it still doesn't work ... don't know what else to
> try ...

int (DOKAN_CALLBACK *ReadFile) (
LPCWSTR, // FileName
LPVOID, // Buffer
DWORD, // NumberOfBytesToRead
LPDWORD, // NumberOfBytesRead
LONGLONG, // Offset
PDOKAN_FILE_INFO);

Did you fill the buffer until NumberOfBytesToRead? And Is NumberOfBytesToRead
same with NumberOfBytesRead?

> To unsubscribe from this group, send email to dokan+un...@googlegroups.com.

Smurf-IV

unread,
Sep 14, 2010, 3:21:17 AM9/14/10
to Dokan
Please read the documentation on mbsncat
http://publib.boulder.ibm.com/infocenter/aix/v6r1/topic/com.ibm.aix.basetechref/doc/basetrf1/mbsncat.htm
It clearly states that
"Performs operations on a specified number of null-terminated
multibyte characters"
So if you have Binary data,it will contain nulls all over the place
(That's why it called binary !)

Use something like CopyMemory or similiar optimised memory buffer
copies
http://msdn.microsoft.com/en-us/library/aa366535%28VS.85%29.aspx

Sylvain Friquet

unread,
Sep 14, 2010, 6:39:21 PM9/14/10
to Dokan
Thanks,

I realized NumberOfBytesToRead wasn't always the one I expected.

Thanks for all the helpful answers.

On Sep 14, 1:35 am, Hiroki Asakawa <asa...@gmail.com> wrote:
> On Tue, Sep 14, 2010 at 6:45 AM, Sylvain Friquet
>
Reply all
Reply to author
Forward
0 new messages