Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am wrapping up a COM dll that is loaded into a commercial app's process space.
It sends me data in CStrings that I display. Some of the time the app sends me garbage in the CString that looks like:

"ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ"

Which seems to me to be an uninitialized CString perhaps.

CStringname.IsEmpty() does not detect this condition.

CStringname == "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" does however but is obviously not the way to detect it as while the garbage that is sent is always a bunch of these 0xcc values, I cannot rely on the length. Frankly I cannot rely on the value being 0xcc but am willing to chance it right now save for a better way.

What would be the proper way to detect this condition so I can reliably ignore it?

Thanks,

:Ron
Posted
Comments
Sergey Alexandrovich Kryukov 18-Dec-11 12:32pm    
I don't think you really need to detect it (after all, this is merely a string, valid data), but you need to fix the bug. But how to help you without looking at your code? Try to isolate the problem, narrow down...
--SA
Ron Anders 18-Dec-11 12:48pm    
Ok,

Thank you.

You should not try to detect this. This is, or might be, a serious issue you are facing. There are several posibilities here and non of them are good. You are seeing a warning of some object that has been destroyed. Either the CString you are using is a dereferenced object where a delete was called on the pointer or considering you are using COM, you could also be facing something else. Considder e.g.:

BSTR m_TheString;

Do::This(string value)
{
  m_TheString = CComBSTR(value.c_str());
}


and a bit later you are making a CString from the BSTR you'll find that the BSTR m_TheString is already destroyed. In order to prevent this you'll have to call CComBSTR(value.c_str()).Detach();

note that you'll have to free the memory later yourself!!

Anyway; if you'r not facing this try running the Microsoft application verifier. that will warn you of any memory issues you might be facing.

=========> Edit <==================

I have to correct myself here; I just ran a small test and though I mentioned a few things that would make sure that your app will not function correctly, the issue you are seeing can easily be created in the following manner:

char test[20];
CString apple(test);


=========> /Edit <==================

Hope this helps,

Cheers AT
 
Share this answer
 
v2
Comments
[no name] 18-Dec-11 21:04pm    
my 5!
Mohibur Rashid 19-Dec-11 0:31am    
I completely disagree with you.
Addy Tas 19-Dec-11 2:41am    
You are correct though i pointed out many things that could be wrong, the following is wrong.

char test[20];
CString apple(test);


I updated my answer accordingly.
Cheers, AT
Unfortunately, the cause of this doesn't originate with CString. The problem is that someone loaded an uninitialized buffer into a CString and this is the garbage you get. Unfortunately, there is no reliable way to test for this because the garbage may not always be consistent. Best thing to do is verify if the value makes sense in the context. For example, if its a filename, make sure it exists (and so on).
 
Share this answer
 
I think you must initialized your variable first..
 
Share this answer
 
Comments
Mohibur Rashid 19-Dec-11 0:33am    
Correct Answer
Albert Holguin 19-Dec-11 8:13am    
His problem is that he has no control of that variable. It's being passed over a COM interface.
Use memset[^] function to set zero value to all the characters in the array.

When you define a string(character array) your each array is filled with Ì (char value is -52 and unsigned char value 204)
 
Share this answer
 
v2
Comments
Albert Holguin 19-Dec-11 8:10am    
I think he's saying that's the way the CString is loaded, in another words, he has no control of the char buffer to CString conversion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900