我在C++/CLI项目中有以下代码:
CSafePtr<IEngine> engine;
HMODULE libraryHandle;
libraryHandle = LoadLibraryEx("FREngine.dll", 0, LOAD_WITH_ALTERED_SEARCH_PATH);
typedef HRESULT (STDAPICALLTYPE* GetEngineObjectFunc)(BSTR, BSTR, BSTR, IEngine**);
GetEngineObjectFunc pGetEngineObject = (GetEngineObjectFunc)GetProcAddress(libraryHandle, "GetEngineObject");
pGetEngineObject( freDeveloperSN, 0, 0, &engine )最后一行抛出此异常:
不可用的
RPC服务器
是什么导致了这一异常?
发布于 2010-07-22 05:37:58
ABBYY是一个COM对象。GetEngineObject()的行为就像一个普通的COM接口方法,只是它是一个单独的函数。这意味着:它不允许异常在外部传播。为了实现这一点,它捕获所有异常,将它们转换为适当的HRESULT值,并可能设置IErrorInfo。
试图分析方法中抛出的异常没有机会找到问题所在。这是因为在内部,它可能是这样工作的:
HRESULT GetEngineObject( params )
{
try {
//that's for illustartion, code could be more comlex
initializeProtection( params );
obtainEngineObject( params );
} catch( std::exception& e ) {
setErrorInfo( e ); //this will set up IErrorInfo
return translateException( e ); // this will produce a relevant HRESULT
}
return S_OK;
}
void intializeProtection()
{
try {
doInitializeProtection();//maybe deep inside that exception is thrown
///blahblahblah
} catch( std::exception& e ) {
//here it will be translated to a more meaningful one
throw someOtherException( "Can't initialize protection: " + e.what() );
}
}因此,实际调用可以捕获异常并将它们转换为提供有意义的诊断。为了获得tha诊断信息,您需要在函数复述之后检索IErrorInfo*。为此使用来自同一个示例项目的check()函数的代码。只是不要盯着被抛出的异常-你没有这个机会,让它传播和翻译。
https://stackoverflow.com/questions/3204320
复制相似问题