CString包含“ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" -如何检测? [英] CString contains "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" - how to detect?

查看:69
本文介绍了CString包含“ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" -如何检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在包装一个COM dll,该dll已加载到商业应用程序的进程空间中.
它以我显示的CStrings的形式向我发送数据.应用有时会向我发送CString中的垃圾,如下所示:

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

在我看来,这也许是未初始化的CString.

CStringname.IsEmpty()无法检测到这种情况.

CStringname ==ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ"可以,但是显然不是检测它的方法,因为虽然发送的垃圾始终是这些0xcc值的一堆,但我不能依赖于长度.坦率地说,我不能依赖于0xcc的值,但现在愿意为更好的方式保存它.

什么是检测此状况的正确方法,以便我可以可靠地忽略它?

谢谢,

:Ron

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

推荐答案

您不应尝试检测到这一点.这是或可能是您面临的一个严重问题.这里有几种可能性,没有一种是好的.您会看到一些已被破坏的对象的警告.您正在使用的CString是已取消引用的对象,在该对象上调用了指针的删除操作,或者考虑到您正在使用COM,您也可能会遇到其他问题. Considder,例如:

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());
}



再过一会儿,您从BSTR中创建一个CString,您会发现BSTR m_TheString已被销毁.为了防止这种情况,您必须调用CComBSTR(value.c_str()).Detach();

请注意,您稍后必须自己释放内存!!

反正;如果您没有遇到这种情况,请尝试运行Microsoft应用程序验证程序.会警告您可能面临的任何内存问题.

=========>编辑< =================

我必须在这里纠正自己.我只是进行了一次小测试,尽管我提到了一些可以确保您的应用无法正常运行的事情,但是可以通过以下方式轻松创建您看到的问题:



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);



=========> /编辑< =================

希望这会有所帮助,

欢呼AT



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

Hope this helps,

Cheers AT


不幸的是,其原因并非源于CString.问题是有人将未初始化的缓冲区加载到CString中,这就是您得到的垃圾.不幸的是,没有可靠的方法对此进行测试,因为垃圾可能并不总是一致的.最好的办法是验证该值在上下文中是否有意义.例如,如果它是文件名,请确保它存在(依此类推).
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).


我认为您必须先初始化变量.
I think you must initialized your variable first..


这篇关于CString包含“ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ" -如何检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆