views:

50

answers:

3

Ok, let's see if this all makes sense. Today, as I began working on a small project, I ran into an error I can't seem to get over. The function of the program I am working on is to read data from a pipe (which is the output of another program) and update an HWND ("edit") control dialog using WinAPI. Now, I've been successful at updating the dialog: sort of. If I send the character buffer from the ::ReadFile() function to the dialog, I get the proper output but with a ton of extra characters I don't want. So how can I simply strip it to the output I'm looking for, or is there a better way to accomplish what I'm attempting? Perhaps take the output and WriteFile(); or something similar to decipherable text?

Here is what's happening:

some output...'Hola Mondo' means... Hello word!ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ$

Here is what I want to happen:

some output...'Hola Mondo' means...

Hello word!

Thanks so much for your help!

Regards,
Dennis M.

+4  A: 

Check the "Bytes Read" output argument of ReadFile so you know how long the string is, then put a terminating NUL (`'\0') character at that offset.

Ben Voigt
You guys are fantastic! Thanks so much. Such a little thing just escaping me. I really appreciate it.
RageD
A: 

Most likely you're not 0-terminating your buffer before passing it to the text updating function.

Check the 'Example: Open a File for Reading' from here.

Eugen Constantin Dinca
A: 

It looks like you just need to add a '\0' termination character to the string you're passing to the edit control.

But your question should show the code including the ReadFile() and where you pass the data to the edit control so someone can say for sure (and give a better suggestion).

Michael Burr