Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to avoid \r\n after strings from FormatMessage?

866 views
Skip to first unread message

Peter Haumann

unread,
Jul 5, 2004, 2:30:18 PM7/5/04
to
Hi.

Why is there always a \r\n (newline) after strings that came from
FormatMessage?

I don't want it. :-P
Is there a way to avoid it?

Or if not, is there an API function that removes the newline?

Bye, Peter.

Alf P. Steinbach

unread,
Jul 5, 2004, 2:48:20 PM7/5/04
to
* Peter Haumann:

>
> Why is there always a \r\n (newline) after strings that came from
> FormatMessage?

Because.


> I don't want it. :-P
> Is there a way to avoid it?

Yes, remove them.


> Or if not, is there an API function that removes the newline?

No, but just remove them.

Also be aware that FormatMessage doesn't automatically check for
Net and Ras modules. If you want those messages you'll have to
check the error-code against relevant ranges and dynamically
load those modules and use try-fail method.

On the other hand, if you do not have particular requirements but
just want hard and fast FormatMessage-functionality and you're
using Visual C++ then check out the built-in COM-support classes.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

tom...@gmail.com

unread,
Feb 19, 2015, 9:08:04 PM2/19/15
to
On Monday, July 5, 2004 at 7:48:20 PM UTC+1, Alf P. Steinbach wrote:
> * Peter Haumann:
> >
> > Why is there always a \r\n (newline) after strings that came from
> > FormatMessage?
>
> Because.
>
>
> > I don't want it. :-P
> > Is there a way to avoid it?
>
> Yes, remove them.
>
>
> > Or if not, is there an API function that removes the newline?
>
> No, but just remove them.

Wow, you're so helpful.

Geoff

unread,
Feb 19, 2015, 9:33:52 PM2/19/15
to
... he said, replying to a thread that's almost 10 years dead.

In fact, FormatMessage never introduces newlines unless they are in
the strings being passed to it or part of the format string of the
message. Removing them before passing the strings to the function is
the correct solution.

JJ

unread,
Feb 20, 2015, 2:20:02 AM2/20/15
to
On Thu, 19 Feb 2015 18:33:47 -0800, Geoff wrote:
>
> ... he said, replying to a thread that's almost 10 years dead.

Well, it's one of those... users. Blurting things out without proper
inspection first. I bet their code are all try-catch with almost no actual
error handling.

> In fact, FormatMessage never introduces newlines unless they are in
> the strings being passed to it or part of the format string of the
> message. Removing them before passing the strings to the function is
> the correct solution.

That only applies to FORMAT_MESSAGE_FROM_STRING.
It doesn't apply for FORMAT_MESSAGE_FROM_SYSTEM.
With FORMAT_MESSAGE_FROM_SYSTEM, there's actually a way to tell
FormatMessage not to append the new line.
However, it appends a space instead of a new line.
This FormatMessage behaviour is the one that can't be disabled.
0 new messages