Re: CString causes crash???
Quote:
Originally Posted by
LarryChen
My program crashes with an error like access violation when the following statement is executed,
Code:
str_test = "Test CString";
str_test is defined as CString. I have no clue why such a simple statement can cause a crash. Any guru here can tell me how to find out why? Thanks.
try out
[code=cpp]
CString * str_test="Test CString";
[/code]
Re: CString causes crash???
Quote:
Originally Posted by
Grasshopper.Network
try out
[code=cpp]
CString * str_test="Test CString";
[/code]
Why? I'm sure you mean well, but that makes no sense.
Larry, no a simple assignment isn't going to crash a CString. With 625 posts and six years on the forum, you should be familiar with basic debugging techniques by now.
Re: CString causes crash???
Quote:
Originally Posted by
GCDEF
Why? I'm sure you mean well, but that makes no sense.
Larry, no a simple assignment isn't going to crash a CString. With 625 posts and six years on the forum, you should be familiar with basic debugging techniques by now.
Debugging doesn't help much. It only points out a pointer contained by CString is invalid, so when this invalid pointer points to a literal string, it crashes. I just don't understand why the pointer contaied by the CString is invalid.
Re: CString causes crash???
Quote:
Originally Posted by
LarryChen
Debugging doesn't help much. It only points out a pointer contained by CString is invalid, so when this invalid pointer points to a literal string, it crashes. I just don't understand why the pointer contaied by the CString is invalid.
I'm pretty sure if there was a bug like that MS would have found it and others would have reported. It's safe to say the problem is probably somewhere in your code where you've stepped off an array or something and corrupted it.
Re: CString causes crash???
Quote:
Originally Posted by
LarryChen
Debugging doesn't help much. It only points out a pointer contained by CString is invalid, so when this invalid pointer points to a literal string, it crashes. I just don't understand why the pointer contaied by the CString is invalid.
- What "the pointer contaied by the CString...do you mean?
- Do you somewhere (before the code you were showing is executed) call something like
Code:
str_test.GetBuffer(...);
without the following ReleaseBuffer?
Re: CString causes crash???
Quote:
Originally Posted by
LarryChen
Debugging doesn't help much. It only points out a pointer contained by CString is invalid, so when this invalid pointer points to a literal string, it crashes. I just don't understand why the pointer contaied by the CString is invalid.
In addition to being able to debug, I would expect you also understand that it is nearly impossible to offer any help if you don't provide any context. How is str_test defined? Is it a local variable? A class member? In what context is the code you posted called?
From your description, I would expect that it is a class member and you are calling this code on an invalid instance of the class. In that case, the CString doesn't exist, which explains the invalid internals of the CString reported in the debugger.