加载ABBYY Engine

时间:2010-07-08 13:59:36

标签: abbyy finereader

我在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服务器不可用

可能导致此例外的原因是什么?

1 个答案:

答案 0 :(得分:2)

ABBYY FRE是一个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() );
    }
}

因此实际调用可以捕获异常并转换它们以提供有意义的诊断。为了获得诊断,您需要在函数返回后检索IErrorInfo*。使用来自同一示例项目的check()函数中的代码。只是不要盯着抛出的异常 - 你没有机会,让它传播并被翻译。