是否应该将HRESULT分配给变量?

Jam*_*mes 1 hresult

我有一个关于directshownet示例中的一些演示代码的快速问题.以下是:

// Set the video to stream to pictureBox1
int hr;
hr = this.videoWindow.put_Owner(this.pictureBox1.Handle);
DsError.ThrowExceptionForHR(hr);
Run Code Online (Sandbox Code Playgroud)

优先:

// Set the video to stream to pictureBox1        
DsError.ThrowExceptionForHR(this.videoWindow.put_Owner(this.pictureBox1.Handle));
Run Code Online (Sandbox Code Playgroud)

出于任何原因?如果是这样,为什么?干杯

Eri*_*ert 8

假设代码不正确,方法失败并出现错误HRESULT.您可能会在不久的将来调试此代码.在那种情况下,你更喜欢什么?必须调试到ThrowExceptionForHR来检查返回的HRESULT,或者将监视放在本地hr上?

我知道我更喜欢哪个.

假设hr有时只是一个错误代码.你喜欢什么,在ThrowExceptionForHR中放置一个断点,或者在调用者上放置一个条件断点,只有当hr中存储的值是错误代码时才会中断?

再一次,我知道我更喜欢哪个.

设计您的代码以便于调试.你以后会感谢你自己.