Re: Strange Error




"Mike C#" <xyz@xxxxxxx> wrote in message
news:%23sF3dL01GHA.3464@xxxxxxxxxxxxxxxxxxxxxxx

"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
length
of 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
effectively
limit the input as well, no?

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
just
before you call wcscpy (again, wcscpy_s is a better alternative).

Hmmm. Your guess there would be wrong. The AuthorCode string is
L"982091",
which is far less than 256 characters. Again, it works fine when run from
Visual Studio, but gives that error when compiled to an exe and run from
the
command line. That leads me to believe that the problem isn't necessarily
a
coding issue on my part. But I could be wrong there too.

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
length
of the string is 6 and the actual string is L"982091", indicating that the
problem doesn't lie with the code. The fact that it runs perfectly fine
in
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.



.



Relevant Pages

  • Re: Strange Error
    ... My guess would be that your AuthorCode is longer than 256--I suggest you ... The AuthorCode string is L"982091", ... Visual Studio, but gives that error when compiled to an exe and run from the ... from the command line. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Truss rod basic Q
    ... I have eyeballed the relief when I fret the low e string at the first ... tune up right after you make the adjustment (to bring it back up to the ... The truss rod is typically 8 or 10/32 thread, ... nut may save it from one day refusing to move smoothly, causing you to ...
    (alt.guitar.beginner)
  • Re: nullpointer exception
    ... how do you find out what variable is causing a NullPointerException please.. ... the null reference must be one of those mentioned ... String s = foo.toString+ bar.toString ...
    (comp.lang.java.help)
  • Re: String.valueOf() Memory Leak inside of thread.
    ... Thomas Hawtin wrote: ... This is causing a memory leak. ... If I change the line to read "String ... inside the loop but outside of the thread, ...
    (comp.lang.java.programmer)
  • Re: Run Time error 2448, You cannot assign a value to this object !!
    ... The line causing the problem is: ... Forms!frmMainMenu.frmCustomers_edit!contactID = contactID 'value ... >> Dim stLinkCriteria As String ...
    (microsoft.public.access.forms)

Loading