_com_error 클래스와 HRESULT 에러 처리
#import 지시어가 생성하는 .TLI 파일의 메서드 구현 코드는 다음 예와 같이 HRESULT 값을 검사하여 실패한 경우에 _com_issue_error 또는 _com_issue_errorex 함수를 호출한다.

inline HRESULT IHello::sayHello(unsigned short * name, unsigned short ** message) {

HRESULT _hr = raw_sayHello(name, message);

if(FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));

return _hr;

}


_com_issue_error

단순히 HRESULT 값을 매개변수로 취하여 _com_error 데이터형의 예외를 던짐


_com_issue_errorex

HRESULT 값과 함께 인터페이스 포인터와 IID를 매개변수로 취하여 해당 인터페이스가 IErrorInfo 인터페이스를 지원하면 IErrorInfo 객체를 구하여 HRESULT와 함께 IErrorInfo 객체 정보를 포함시켜 _com_error 데이터형의 예외를 던짐

예외 처리

_com_ptr_t 스마트 포인터 클래스를 통하여 COM 객체를 사용할 때 발생하는 에러를 처리할 수 있다.

try {

IHelloPtr pIHello(__uuidof(Hello));

// ….

pIHello->sayHello(name, &message);

// …

}

catch (_com_error & e) {

cout << e.ErrorMessage << endl;

}

_com_error 예외 타입 클래스 멤버


ErrorMessage : 에러를 설명하는 const TCHAR * 리턴


Error : HRESULT 값, 즉 에러 코드값 리턴


Source : IErrorInfo::GetSource 멤버 함수의 호출 결과(_bstr_t) 즉, 에러 소스 리턴


Description : IErrorInfo::GetDescription 멤버 함수의 호출 결과(_bstr_t) 리턴

만일 IErrorInfo가 저장되어 있지 않은 경우 빈 _bstr_t를 리턴하며, IErrorInfo 멤버 함수를 호출하는 동안 발생한 실패는 무시된다.

예외의 발생

다음 예제와 같이 _error_issue_error 함수를 사용

IHelloPtr {

HRESULT hr = p.CreateInstance(__uuidof(Hello));

if(FAILED(hr))

_com_issue_error(hr);

}

catch (_com_error & e) {

cout << e.ErrorMessage() << endl;

}

 

25 Replies to “ATL, _com_error 클래스와 HRESULT 에러 처리,error”

  1. I simply want to say I am beginner to blogging and site-building and truly loved this web site. Likely I’m want to bookmark your blog . You surely have impressive posts. Kudos for sharing your blog site.

  2. Great blog! Do you have any suggestions for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally confused .. Any ideas? Thanks!

  3. An impressive share, I simply provided this onto a colleague who was doing a little analysis on this. And he as a matter of fact bought me morning meal due to the fact that I located it for him. smile. So let me rephrase that: Thnx for the treat! Yet yeah Thnkx for spending the time to review this, I really feel highly regarding it as well as enjoy reading more on this topic. If possible, as you end up being proficiency, would certainly you mind updating your blog site with even more information? It is very helpful for me. Large thumb up for this post!

  4. A remarkable share, I simply provided this onto a coworker that was doing a little analysis on this. And he actually got me breakfast because I located it for him. smile. So let me reword that: Thnx for the treat! Yet yeah Thnkx for spending the moment to discuss this, I really feel highly concerning it and also like finding out more on this subject. Ideally, as you end up being knowledge, would you mind upgrading your blog with more details? It is very practical for me. Big thumb up for this article!

  5. Oh my benefits! an impressive short article dude. Thank you However I am experiencing problem with ur rss. Don?t understand why Not able to subscribe to it. Is there any person obtaining the same rss problem? Any person that knows kindly react. Thnkx

  6. I?m impressed, I have to say. Actually rarely do I run into a blog site that?s both educative as well as enjoyable, and also let me inform you, you have hit the nail on the head. Your idea is impressive; the problem is something that insufficient people are speaking wisely around. I am very delighted that I stumbled across this in my look for something connecting to this.

  7. Oh my goodness! an incredible short article dude. Thanks Nevertheless I am experiencing concern with ur rss. Don?t recognize why Not able to register for it. Exists any individual obtaining similar rss trouble? Any person who knows kindly respond. Thnkx

  8. Can I simply claim what a relief to discover someone who actually understands what theyre talking about on the internet. You most definitely understand exactly how to bring a problem to light and make it vital. More people require to read this and understand this side of the story. I cant believe youre not more popular since you absolutely have the present.

  9. I found your blog website on google and inspect a few of your early messages. Continue to maintain the great run. I simply additional up your RSS feed to my MSN News Reader. Looking for forward to finding out more from you later on!?

  10. Youre so trendy! I don’t intend Ive check out anything like this before. So good to locate somebody with some original ideas on this subject. realy thanks for starting this up. this internet site is something that is needed online, a person with a little originality. beneficial work for bringing something new to the net!

  11. I?m amazed, I must say. Actually rarely do I come across a blog site that?s both enlightening as well as amusing, as well as let me tell you, you have struck the nail on the head. Your concept is exceptional; the problem is something that not nearly enough people are talking smartly around. I am very pleased that I stumbled across this in my search for something relating to this.

댓글 남기기

이메일은 공개되지 않습니다.