Re: Strange Error
- From: "Code Jockey" <gimme@xxxxxxxxxxxx>
- Date: Wed, 13 Sep 2006 12:51:24 -0700
"Mike C#" <xyz@xxxxxxx> wrote in message
news:%23sF3dL01GHA.3464@xxxxxxxxxxxxxxxxxxxxxxx
length
"Ray" <ray_usenet@xxxxxxxxx> wrote in message
news:e1rIMys1GHA.4452@xxxxxxxxxxxxxxxxxxxxxxx
Mike C# wrote:
However I'm not purposely requesting that the Runtime terminate in an
"unusual way." The line that is causing me headaches is:
wcscpy(data, MyCode.c_str());
I'd suggest that you use wcscpy_s, which requires you to supply the
effectivelyof the destination string.
I'll consider that if I can figure out the cause of the error. A basic
copy, afaik, should work. Also I've tried wcsncpy which should
limit the input as well, no?just
Where data and MyCode are defined as:
wchar_t data[256];
std::wstring AuthorCode;
My guess would be that your AuthorCode is longer than 256--I suggest you
step through your code, alternatively, cout the length of AuthorCode
L"982091",before you call wcscpy (again, wcscpy_s is a better alternative).
Hmmm. Your guess there would be wrong. The AuthorCode string is
which is far less than 256 characters. Again, it works fine when run fromthe
Visual Studio, but gives that error when compiled to an exe and run from
command line. That leads me to believe that the problem isn't necessarilya
coding issue on my part. But I could be wrong there too.length
The strange thing is that the program appears to be running fine in
Visual Studio, but generates the error message whenever I try to run it
from the command line. Putting a try...catch block around the line in
question doesn't help - it doesn't catch the exception. I have no idea
what's causing this...
Yeah, wcscpy will just trample the end of the destination string over
without any exception. Try using wcscpy_s, and check for ERANGE (to find
out whether the size is too small for AuthorCode).
I'll try it, but I've already verified inside Visual Studio that the
of the string is 6 and the actual string is L"982091", indicating that thein
problem doesn't lie with the code. The fact that it runs perfectly fine
Visual Studio,
When running under the debugger your program ends up with the string as you
describe, but run from outside the debugger, a different codepath is taken,
which results in either a different string, or the wstring ends up not
initialized with any string.
.
- Follow-Ups:
- Re: Strange Error
- From: Mike C#
- Re: Strange Error
- References:
- Strange Error
- From: Mike C#
- Re: Strange Error
- From: Ray
- Re: Strange Error
- From: Mike C#
- Strange Error
- Prev by Date: MFC Projects
- Next by Date: Re: Strange Error
- Previous by thread: Re: Strange Error
- Next by thread: Re: Strange Error
- Index(es):
Relevant Pages
|
Loading