Raise positive VB style error codes via COM interop from C#

隐身守侯 提交于 2019-12-06 02:25:27

The "positive" VB style error numbers are translated to HRESULTs with a "FAILURE" severity and a facility of FACILITY_CONTROL/0xA, i.e. 0x800AAFC9.

You can get a suitable HRESULT using:

int HResult = (int)(0x800A0000 | (int)errorCode);

This can then be raised back to the calling process using a plain COMException, or by throwing your own subclass of COMException:

/// <summary>
/// Exception that returns an ICIO error wrapped in an exception.
/// </summary>
internal class ICIOErrorException : COMException {
    internal ICIOErrorException(ICIO.IOErrors errorCode, string message)
        : base(message) {
        this.HResult = (int)(0x800A0000 | (int)errorCode);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!