CString m_pchData is null

I have a class that is derived from CCmdTarget.  I have a bunch of CString 
class members.  In the class constructor I am assigning values to them.  
There is one member that has m_pchData = null at the time of assignment.  
This is causing the program to crash.

Anybody have any ideas as to why this one member is exhibiting this behavior?
0
JR1 (208)
8/2/2006 1:52:01 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
1154 Views

Similar Articles

[PageSpeed] 52

This looks suspiciously like you are managing to overwrite some part of the heap.  I'd
suggest the following approach:

At the earliest possible point in the constructor, set a breakpoint.  Examine the member
variables.  If the pointer is NULL at that point, it indicates a deeper problem.  But if
it isn't NULL, then all you have to do is keep single-stepping until it becomes NULL and
that tells you who is clobbering things. 

I've never seen this happen to a CString.  Is this perhaps the first member in the class?
If not, where is it, and what precedes it?  Is there any manipulation of anything that
precedes it before you see the pointer being NULL?  

There really isn't enough information here to make a good guess, but it smells deeply of
storage damage.  Look for buffer overruns.  Without seeing the code that's the best guess
I can give.
					joe

On Tue, 1 Aug 2006 18:52:01 -0700, JR <JR@discussions.microsoft.com> wrote:

>I have a class that is derived from CCmdTarget.  I have a bunch of CString 
>class members.  In the class constructor I am assigning values to them.  
>There is one member that has m_pchData = null at the time of assignment.  
>This is causing the program to crash.
>
>Anybody have any ideas as to why this one member is exhibiting this behavior?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15973)
8/2/2006 2:18:23 AM
You were right.  I was overwriting it.  A very easy solution...one I should 
have seen but was obviously blind to until pushed in the right direction.  
Thanks!

"Joseph M. Newcomer" wrote:

> This looks suspiciously like you are managing to overwrite some part of the heap.  I'd
> suggest the following approach:
> 
> At the earliest possible point in the constructor, set a breakpoint.  Examine the member
> variables.  If the pointer is NULL at that point, it indicates a deeper problem.  But if
> it isn't NULL, then all you have to do is keep single-stepping until it becomes NULL and
> that tells you who is clobbering things. 
> 
> I've never seen this happen to a CString.  Is this perhaps the first member in the class?
> If not, where is it, and what precedes it?  Is there any manipulation of anything that
> precedes it before you see the pointer being NULL?  
> 
> There really isn't enough information here to make a good guess, but it smells deeply of
> storage damage.  Look for buffer overruns.  Without seeing the code that's the best guess
> I can give.
> 					joe
> 
> On Tue, 1 Aug 2006 18:52:01 -0700, JR <JR@discussions.microsoft.com> wrote:
> 
> >I have a class that is derived from CCmdTarget.  I have a bunch of CString 
> >class members.  In the class constructor I am assigning values to them.  
> >There is one member that has m_pchData = null at the time of assignment.  
> >This is causing the program to crash.
> >
> >Anybody have any ideas as to why this one member is exhibiting this behavior?
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
> 
0
JR1 (208)
8/2/2006 4:34:02 AM
Reply:

Similar Artilces:

NULL DATE
This works fine if there is a date in the textbox, but if the textbox is empty or null, I get an error. This is part of an SQL statement. What can I do if it's Null so that it still works. Thanks DS Format(Forms!frmBSDiscountNames![TxtExpDate], "\#mm\/dd\/yyyy\#") Change you line to Nz(Format(Forms!frmBSDiscountNames![TxtExpDate], "\#mm\/dd\/yyyy\#")) This will return a zero legnth string instead of a null value, and will allow your code to process it. Note that if at any point you are comparing that field to Null, it will fail, and you will have to compar...

sending CString to CStatic label control from worker thread
I need to send a CString from a thread to a static label on the main dialog form. I think I have the thread working okay, but I am unsure how to send the CString to the dialog control. I have seen information on using PostMessage and SendMessage, but I don't really understand how to use these functions. Obviously I can't do like I tried below and I can't get a pointer to the control from the thread function, so just how do I say send the word "hello" to the SetWindowText() function of the label control on the dialog form. I have looked on the Internet and in se...

CString
How can I covert argv[0] to LPCSTR? Hi, Shouldn't CString(argv[0]) do the trick? Sander Verhagen [ Verhagen@nonono.Sander.com ] "Oliver Young" <please@no.spam.com> wrote in message news:er3JuEogDHA.616@TK2MSFTNGP11.phx.gbl... > > How can I covert argv[0] to LPCSTR? > > > Shouldn't CString(argv[0]) do the trick? OK. And how can I convert CString into LPCSTR? I need LPCSTR. I need to convert from char** ( argv[0] ) into LPCSTR. Please, forget CString, and MFC if possible. > How can I covert argv[0] to LPCSTR? LPCSTR...

OnCtlColorDlg & return NULL
The MS documentation about WM_CTLCOLORDLG says: "If an application processes this message, it must return the handle of a brush. The system uses the brush to paint the background of the dialog box." The documentation about "CWnd::OnCtlColor" says something quite similar. But then when the wizzard generates OnCtlColor the included comment says: "TODO: Return a different brush if the default is not desired". Now I wonder if really a brush MUST(!) be returned. Returning NULL works. Nevertheless, that doesn't mean it's valid to do so. Finally, if I can re...

std::string vs Cstring
Hello, I have recently been encouraged to utilise String classes, as opposed to C type char arrays due to some difficulty debugging some buffer overflows. I have looked into std::string and CString, but what are the benefits and drawbacks? The main problem I have is that I do a lot of data formatting using sprintf, for which I see no substitute using std::string, - MR On Thu, 30 Dec 2004 23:25:21 -0000, "Mark Randall" <strike@rapiercom.freeserve.co.uk> wrote: >Hello, > >I have recently been encouraged to utilise String classes, as opposed to C >type cha...

CString (again)
I have a class: class TestClass{ public: TestClass(){}; virtual ~TestClass(){}; BOOL CalcArea(double * pArea); void ReversePoints(); void OrderFromLowest(); std::vector<CoordinateClass> Pts; double OrientationType; BOOL XFlip; BOOL YFlip; double LTilt; double RTilt; double Buffer; int Style; CString Name; }; Now when I go like this: TestClass * pNew = new TestClass; pNew->Name = "anything in here will cause an error"; At runtime i get an unhandled exception which is comign from CString::AssignCopy() How do i fix this? Can't seem to reproduce this ...

How to covert CString to TCHAR and CString to LPCWSTR?
How to covert CString to TCHAR and CString to LPCWSTR? Where can I read about this? See my essay on CStrings on my MVP Tips site. joe On Mon, 30 Jun 2003 04:33:56 -0700, "julych" <julych@msn.com> wrote: >How to covert CString to TCHAR and CString to LPCWSTR? >Where can I read about this? Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm ...

Using Multislect on feilsd with null value
I have a query that gets its criteria from a form with 4 multiselct list boxs. The problem i have is that some of the freilds can have null value. The fields that I am using are [Site id], [Primary function], Secondary_function], and [tertiarty fuctin] teh Second and Ter funcs may have null value, when you select multi feilds and multiple items teh query doe snot produce the desired results. exmaple, if you select a specfic location, and gyms in the primary fuction and run the query, you do not get all of tthe areas that are classified as gym, there are 5 entries and 3 have not secondary ot te...

How to convert a BSTR to CString ??
I'm sure I'm missing something easy but..... How does one convert a BSTR to a CString? More specifically, I am processing the returned VARIANT value from an ActiveX control and it's value is a BSTR that I would like to move to a CString. Thanks in advance for your help. Bob Curry BSTR bstrValue; CString szValue; szValue = (LPCWSTR)bstrValue; Sreeram. Bob Curry wrote: > I'm sure I'm missing something easy but..... How does one convert a BSTR > to a CString? More specifically, I am processing the returned VARIANT value > from an ActiveX control and it...

Null Field to Interupt Closing
I am using this code to check for blank fields in BeforeUpdate: If NZ(Trim(Me!Date),vbnullstring) = vbnullstring then Msgbox "PLEASE ENTER DATE",,"Missing date" Me!Date.setfocus Cancel = True Exit Sub End if It almost works, except the form goes ahead and closes anyway. The user clicks the close button and the message box pops up if the field is empty, they click OK and instead of keeping the form open and then setting focus on the empty field, it closes the form. How can I get it to interupt the close and keep the form open? Thank you in advance for any...

CString...
What is the maximum characters a CString variable can hold? Is there anyway to increase a CString variables capacity to hold more characters? Thanks, RABMissouri As all index and length parameters are int variables, and there is no checking on assignment, the limit would be 2147483647 on a 32bit machine. If that's not big enough, rethink what you're doing. Jase "RBert" <drbert@microcore.net> wrote in message news:OB24du6FEHA.2308@tk2msftngp13.phx.gbl... > What is the maximum characters a CString variable can hold? Is there anyway > to increase a CString va...

CString in DLL
When I try to use CString in an MFC DLL, it gives the following error: error LNK2019: unresolved external symbol "public: __thiscall CString::~CString(void)" (??1CString@@QAE@XZ) referenced in function "public: virtual int __thiscall CMfcDllApp::InitInstance(void)" (?InitInstance@CMfcDllApp@@UAEHXZ) How can I use CString? Forgot to mention that the Env used is VC++ .NET "ajd" <ajaydhar@hotmail.com> wrote in message news:eLGoiPFMEHA.2388@TK2MSFTNGP09.phx.gbl... > When I try to use CString in an MFC DLL, it gives the following error: > > error L...

Set focus to a control if it's null
I have a form where there are two controls I want users to fill in but don't want to set the property to required. I want the form to not be able to close if they haven't filled in these two fields and if they tab past the field, it should give you a message box saying you must fill something in and stay in that control until something is chosen from the drop down boxes. The set focus and docmd.gotocontrol are not really working, they can still close the form and tab past that control. Use the BeforeUpdate event procedure of the *form* (not the control's events) to test i...

Anyone suggest why FindWindow returns NULL in release build?
I'm running a service and send information to an application via a CopyData structure HWND hWnd = FindWindow(NULL, "ServiceManager"); if(hWnd) { ... } only FindWindow returns NULL in Release mode. Ta! ah hah... in the Services administrator make sure 'Allow Service To Interact With Desktop' is ticked. ...

Null
I have a database that list clients...I want to create a report that is only open clients and excludes closed clients. I created a query on which to base the report but I cannot seem to eliminate the clients that have been closed. Any suggestions? Pamelia wrote: >I have a database that list clients...I want to create a report that is only >open clients and excludes closed clients. I created a query on which to base >the report but I cannot seem to eliminate the clients that have been closed. Post back with a Copy/Paste of your query's SQL view along with an explanation...

Null value syntax of export XML
Dear all, I use excel 2003 to export a excel file into xml file. For those blank cells in the excel file, I input a ' so that excel can recognize it as a null value when exporting to xml. After exporting, the syntax of null value in the xml file will look liked <remark/> However, I expect the syntax of null value will look liked <remark></remark> Everytime I will use Notepad to modify the syntax. May I ask whether there is any method to modify the xml output syntax? Thanks. Regards, Michael ...

Array of CString s vs. CString Array
Hi all What's the deal with CStringArray? I have used CStringArray in several places but now I'm wondering why can't I use an array of CStrings instead - at least I wouldn't have to bother with SetSize(). TIA Richard C You can use whatever you like. CStringArray has been part of MFC before vector other STL collection became a part of C++. I'd use vector<CString>. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Richard C" <rc@replytogroup.com> wrote in message news:tN97h.67412$rP1.57615@news-server.bigpond.net.au... > Hi all > > What&...

Replace null string with blank cell
I have a large table which was created via lookups from other tables. Many of the entries are (or should be) blank. After the table was created, I converted everything to values (Paste Special/Values) in order to save memory. However, the table now contains a null string or other unprintable character in each of the "blank" cells. Thus, if I use END-DN or END-UP to find the next value in the table, the cursor goes to the end of the table, as it sees something in each cell. If I edit a "Blank" cell, I see no characters, and if I select the formula bar & hit ENTER, ...

Are there any function like ReplaceNoCase for CString?
I can only find CString::Replace, but I need a function like ReplaceNoCase You are correct. Replace is case sensitive. You could convert the string to all upper or lower case first, but then your resulting string would be changed as well. You could also derive your own class from CString and add the new functionality to it. Tom <flyingxu@gmail.com> wrote in message news:1145000483.010766.64070@t31g2000cwb.googlegroups.com... >I can only find CString::Replace, but I need a function like > ReplaceNoCase > ...

Issue with casting CString to LPARAM and recasting it to CString...
Hi, I have developed a custom control with some customizations of the List Control class of MFC (CListCtrl). I have another custom class (MyItem) which is inherited from CItem. Each and every entry in the list control is a MyItem. Every time a new item is added into the LIst control we use the logic of maintaining a unique sequence number which is a CString and member of MyItem class. Here goes the implementation of the 2 main members of MyItem class void MyItem::SetListItemSequence(const CString& seq) { m_sequence = seq; } This member sets the newly added entries sequence value into ...

CString ?
One mine user reported strange error using my DLL. After analizing, the only way error could be mine is if this peace of code is wrong: BSTR p1; hr = pMyCOMObj->get_someProperty(&p1); CString cP1(p1); prop.someProperty = (LPCSTR)cP1; This peace of code is inside of my COM object. "prop" is C-type structure. "someProperty" is "const char*". I'm not working with very long strings. The CString cP1 seems to be a temporary stack object that'll get destroyed when it goes out of scope thereby rendering the pointer passed to prop.someProp...

Query will not open in Design Mode
Access 2007, I've created the following query from two tables: SELECT tblTrnsctn.TxnDate, tblTrnsctn.Amount, tblCoa.AcntNmbr, tblCoa.AcntDscriptn, tblCoa.LeadSheet, tblCoa.qbListID FROM tblTrnsctn LEFT JOIN tblCoa ON tblTrnsctn.AccountRefListID = tblCoa.qbListID; This query seems to run fine, but once I save the query, I no longer can open the query in Design Mode to edit - I can view in sql mode. I modified the above query to return records that do not contain any null values in any fields. When I try to view the query in Design Mode - 'Invalid use of Null' error message is ret...

CString to std::string
Hi, How to convert from CString to stl string? I tried many things and doesn't work. thanks CString Temp = "This is a test"; string Str = (LPCSTR)Temp; AliR. "Derek" <der@yahoo.com> wrote in message news:egz$UubMGHA.3728@tk2msftngp13.phx.gbl... > Hi, > How to convert from CString to stl string? > I tried many things and doesn't work. > thanks > > that I tried, doesn't work. "AliR" <AliR@online.nospam> wrote in message news:jstIf.20753$_S7.12727@newssvr14.news.prodigy.com... > CString Temp = "This is a t...

inherit from CString
I'd like to make a new class that inherits from CString and adds a few new string manipulation functions as well as some other member variables. For constructors, I'd like to simply use the CString constructors and add only my initialization values for my new member variables. Considering that there are multiple constructors for CString, what is an easy way to do this? (I'm a VC++ hobbyist, not a pro). I'd like to avoid having to write separate constructors to match each of the ones for CString. Thanks, Matt -- Remove Xs from address to reply via e-mail. Matt Roos wrot...

CString hex value to CString decimal value
Please bare with me, I am quite new to C++. A CString contains a (large) hexadecimal string value, this value needs to be converted to an decimal value, and then put back as a string into an other CString. Data example: hexadecimal: 93d2f666 = decimal 2480076390 I have googled and found a lot of solutions (hex string to int) but none of them returns the correct decimal value, I suspect that converting a large hex string to int does not work. So if someone could point me to the right direction or could suply a working sample, please do. TIA Alex Your not looking hard enough. ...