要使用哪种函数比较好?该如何解决
要使用哪种函数比较好?
编写组件,引入外部组件(#import)。
在.tlh中,有两种接口函数-- "Wrapper methods for error-handling "和 "Raw methods provided by interface "。
要使用哪种函数比较好?
假设有组件Math.
在要实现的组件App中要用到Math组件。
-->."Wrapper methods" -- 通过抛异常来返回错误信息。
在组件程序中,为了捕获错误需要这样作:
//
#import Math.dll
//
HRESULT App::Test()
try{
.....
MathPtr m;
...
m.Add();
....
}catch{
...
return E_ERROR;
}
}
.而"Raw methods" --通过HRESULT返回错误代码。
#include Math.tlh
//
HRESULT App::Test()
....
Math 8
...
return E_ERROR;
}
}
------解决方案--------------------
这个看习惯了.
------解决方案--------------------
如果你需要返回错误信息,那么使用第2种,但还要实现 ISupportErrorInfo 接口。
这样别人使用你组件的时候就可以catch到你的异议并封装称对象,如 CException
编写组件,引入外部组件(#import)。
在.tlh中,有两种接口函数-- "Wrapper methods for error-handling "和 "Raw methods provided by interface "。
要使用哪种函数比较好?
假设有组件Math.
在要实现的组件App中要用到Math组件。
-->."Wrapper methods" -- 通过抛异常来返回错误信息。
在组件程序中,为了捕获错误需要这样作:
//
#import Math.dll
//
HRESULT App::Test()
try{
.....
MathPtr m;
...
m.Add();
....
}catch{
...
return E_ERROR;
}
}
.而"Raw methods" --通过HRESULT返回错误代码。
#include Math.tlh
//
HRESULT App::Test()
....
Math 8
...
return E_ERROR;
}
}
------解决方案--------------------
这个看习惯了.
------解决方案--------------------
如果你需要返回错误信息,那么使用第2种,但还要实现 ISupportErrorInfo 接口。
这样别人使用你组件的时候就可以catch到你的异议并封装称对象,如 CException