Domanda

Ho questo codice nel progetto 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 )
.

L'ultima riga getta questa eccezione:

.

Server RPC in non disponibile

Cosa può causare questa eccezione?

È stato utile?

Soluzione

ABBYY FRE è un oggetto COM.GetEngineObject() si comporta come un normale metodo di interfaccia Com tranne che è una funzione separata.Il che significa quanto segue: Non consente alle eccezioni si propagano all'esterno.Per raggiungere questo obiettivo, prende tutte le eccezioni, le traduce in valori di HRESULT appropriati e possibilmente imposta IErrorInfo.

Stai cercando di analizzare l'eccezione lanciata all'interno di un metodo non ha possibilità di trovare ciò che il problema è.Questo perché internamente potrebbe funzionare in questo modo:

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() );
    }
}
.

Quindi la chiamata effettiva può catturare eccezioni e tradurle per fornire diagnostica significativa.Per ottenere la diagnostica THA è necessario recuperare IErrorInfo* dopo la funzione Retuns.Utilizzare il codice dalla funzione check() dallo stesso progetto di esempio per quello.Basta non fissare l'eccezione lanciata - non hai possibilità con questo, lascia che si propaga ed essere tradotta.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top