|
[公告]《2015MSC移动安全挑战赛(第二届)》15万奖金等你赢![比赛结束]
占楼围观,说不定就中了呢 |
|
[求助]com智能指针疑问
找到了一种解释,我书看的不仔细啊。~ 在使用ATL中所带智能指针CComPtr和CComQIPtr时要小心。 以下代码假设存在一个组件TESTCOMPtr,其组件的CLSID为CLSID_TESTCOMPtr, 向客户曝露一个接口ITestCOMPtr。 int main() { HRESULT l_hr; CoInitialize(NULL); CComPtr <ITestCOMPtr> l_spTestCOMPtr; l_hr = l_spTestCOMPtr.CreateInstance(CLSID_ TESTCOMPtr); if(FAILED(l_hr)) { return l_hr; } //dosomething of ITestCOMPtr CoUninitialize(); } 初看这段代码是没有任何问题的,但是运行还是会崩溃。如果我们在 CoInitialize(NULL);下行加上"{"和CoUninitialize();上行加上"}"就不会出错了。为什么呢? 原因在于原来的CoInitialize所开的套间在CoUninitialize();后已经被关闭。 而智能指针的组件对象却并没有释放,直到程序调用CComPtr<ITestCOMPtr>的析构函数时才调用 ITestCOMPtr的Release方法,但是这时候,套间已经不在了,所以导致了程序的崩溃。在组件 的生命周期很短的时候,智能指针的使用基本是无害的,并且有时是非常方便的。 所以在使用智能指针时有以下建议: 1. 当对象的生命周期很长要小心使用。 2. 当对象的生命周期不确定时不要使用。 3. 千万不要使用全局的智能指针。 |
|
[求助]com智能指针疑问
在MFC里是不崩溃的,在win32崩溃,好奇怪啊。 |
|
[求助]com智能指针疑问
为什么多一对括号就不崩溃了呢?智能指针不需要我release啊~~ |
|
[求助]com智能指针疑问
果然不崩溃了,但是为什么呢? |
|
[原创]伪创业两年多,突然感悟,上天对我不薄!
灵魂链接已加 |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值