COM中的error handling机制及示例(ISupportEfforInfo,ICreateErrorInfo,IErrorInfo)

COM采取通过返回HRESULT code的方式来获取COM调用的结果。但是往往返回的HRESULT非常抽象。为了使返回的Error information 更加具有可读性,COM支持ISupportErrorInfo interface来对Error information进行具体描述。

在COM service中返回一个具体的Error information过程如下所示:

 

参阅文章:http://msdn.microsoft.com/en-us/library/ms221062.aspx

在COM client 中检索error information的过程如下所示:

参阅文章:http://msdn.microsoft.com/en-us/library/ms221026.aspx

如何实现这种基于IErrorInfo的错误处理机制,可以参阅Microsoft Support KB:http://support.microsoft.com/kb/139073/en-us

下面的demo演示了通过ISupportErrorInfo interface, ICreateErrorInfo interface, IErrorInfo interface,以及CreateErrorInfo() API, SetErrorInfo() API和smart pointer来实现Error Handling .

COM service side:

=========
COM IDL File

 

Code

 SimpleClass Header File:

Code

SimpleClass Implementation:

Code

 

COM Client:

============
Client code:

Code

 

关于此demo的source code,点击此处下载

posted on 2009-06-06 16:11  飞天舞者  阅读(690)  评论(0编辑  收藏  举报

导航

For more information about me, feel free email to me winston.he@hotmail.com