I have this code in C++/CLI project:
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 )
last line throws this exception:
RPC Server in not available
What may causing this exception?
ABBYY FRE is a COM object. GetEngineObject()
behaves like a normal COM interface method except it's a separate function. Which means the following: it doesn't allow exceptions propagate outside. To achieve this it catches all exceptions, translates them into appropriate HRESULT
values and possibly sets up IErrorInfo
.
You trying to analyze the exception thrown inside a method have no chances to find what the problem is. That's because internally it might work like this:
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() );
}
}
so the actual call can catch exceptions and translate them to provide meaningful diagnostics. In order to obtain tha diagnostics you need to retrieve IErrorInfo*
after the function retuns. Use code from check()
function from the same example project for that. Just don't stare at the exception being thrown - you have no chances with that, let it propagate and be translated.