How to trace COM objects exceptions?

南笙酒味 提交于 2019-12-13 20:15:31

问题


I have a DLL with some COM objects. Sometimes, this objects crashes and register an error event in the Windows Event Log with lots of hexadecimal informations. I have no clue why this crashes happens.

So, How can I trace those COM objects exceptions?


回答1:


The first step is to lookup the Fail code's hex value (E.G. E_FAIL 0x80004005). I've had really good luck with posting that value in Google to get a sense of what the error code means.

Then, I just use trial and error to try to isolate the location in code that's failing, and the root cause of the failure.




回答2:


If you just want a really quick way to find out what the error code means, you could use the "Error Lookup" tool packaged with Visual Studio (details here). Enter the hex value, and it will give you the string describing that error code.

Of course, once you know that, you've still got to figure out why it's happening.




回答3:


A good way to look up error (hresult) codes is HResult Plus or welt.exe (Windows Error Lookup Tool).

I use logging internally in the COM-classes to see what is going on. Also, once the COM-class is loaded by the executable, you can attach the VS debugger to it and debug the COM code with breakpoints, watches, and all that fun stuff.




回答4:


COM objects don't throw exceptions. They return HRESULTs, most of which indicate a failure. So if you're looking for the equivalent of an exception stack trace, you're out of luck. You're going to have to walk through the code by hand and figure out what's going on.



来源:https://stackoverflow.com/questions/10935/how-to-trace-com-objects-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!