[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problems with CString class of MFC

Posted on 2003-10-26
7
Medium Priority
?
736 Views
Last Modified: 2013-12-14
Hi all

My application is an MFC dialog based server which calls ATL based dll's on client requests.

I have noticed that my application crashes when many user requests come and many times it gives unknown errors. My friend had said that there is a problem with MFC's CString class having memory leaks.

When i changed the ATL Based dll's to VB dll's it started working fine.

Can anyone please tell me if there is any problem in MFC's CString class or any other class.

Thanks.
0
Comment
Question by:sudeshsh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 672 total points
ID: 9625525
Some problems Listed

1. An access violation may result after using CString::operator+= where the string on the right hand side of the operator is an empty string.

2. GP Fault when Use CString Objects Inside TRACE<x> Macros
eg:
    CString t1("output1");
   
    // Incorrect use of the %s format specifier with a CString object:
    TRACE1("TRACE1 %s\n", t1);

    // Correct is
    TRACE1("TRACE1 %s\n", (LPCTSTR)t1);


3. Chances of GP in *CString::Format* function- while using * (asterik) etc

4. If the CString equality operators (==, !=) are used in an attempt to test whether a CString is NULL, a general protection (GP) fault may occur. The following code fragment demonstrates this:


   CString x = "This is a sample CString";
   if (x != NULL)  // GP Fault for (x == NULL) condition, as well
      AfxMessageBox("The CString is not EMPTY");
   else
      AfxMessageBox("The CString is EMPTY");
Because x is a CString object, not a pointer, it is inappropriate to compare x to a null pointer.

Rosh :)
0
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 664 total points
ID: 9625535
>> When i changed the ATL Based dll's to VB dll's it started working fine.

This means, the problem is in dll's and not in your application?

About MFC CString class - you just try to guess. Whu CString and not something else? I never had problems with CString class.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9625560
I think you are building the components in *Shared* DLLs, this makes problems.

Wrong versions of MFC DLLS (like MSVCRTxx.dll etc) in Client and Development machine makes problems.

To avoid this, Build your ATL DLL in *STATIC*

Rosh :)
0
 
LVL 8

Assisted Solution

by:martynjpearson
martynjpearson earned 664 total points
ID: 9625687
You say you have problems when "many users requests come". Could it be that you are not coordinating access to a CString so that two threads are accessing the same CString at the same time?

One other possible pitfall with CString is the use of GetBuffer() - after calling GetBuffer(), you must call ReleaseBuffer() before you do anything other CString operations.

Hope this helps
Martyn
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question