【问题标题】:Loading ABBYY Engine加载 ABBYY 引擎
【发布时间】:2010-07-08 13:59:35
【问题描述】:

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

什么可能导致这个异常?

【问题讨论】:

  • ABBYY FRE 是哪个版本的? LoadLibraryEx() 和 GetEngineObject 是否成功?您如何看待异常?
  • ABBYY Fine Reader Engine 9.0 Visual Studio 在 pGetEngineObject 调用期间抛出异常。
  • 你的意思是调试器说有异常抛出?如果是这样 - 在 GetEngineObject() 返回后,使用您在 check() 函数中找到的代码来检索 IErrorInfo* 和描述文本。该文本将解释问题所在。

标签: abbyy finereader


【解决方案1】:

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() 函数中的代码。只是不要盯着抛出的异常 - 你没有机会,让它传播并被翻译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-31
    • 2022-07-12
    • 2012-10-13
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多