|
-
September 7th, 2011, 07:14 PM
#1
CString causes crash???
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.
-
September 7th, 2011, 07:26 PM
#2
Re: CString causes crash???
 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]
-
September 7th, 2011, 07:59 PM
#3
Re: CString causes crash???
 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.
-
September 11th, 2011, 02:18 PM
#4
Re: CString causes crash???
 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.
-
September 11th, 2011, 02:27 PM
#5
Re: CString causes crash???
 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.
-
September 11th, 2011, 03:33 PM
#6
Re: CString causes crash???
 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?
Victor Nijegorodov
-
September 12th, 2011, 05:27 AM
#7
Re: CString causes crash???
 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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|