diff --git a/Projects/Sources/errorhandling.cpp b/Projects/Sources/errorhandling.cpp index 6af00b45..84a3a4c3 100644 --- a/Projects/Sources/errorhandling.cpp +++ b/Projects/Sources/errorhandling.cpp @@ -34,10 +34,13 @@ void errorMessage(char *errorMsg){ #else // Workaround code for Windows, will be removed when a proper solution to // call ModelicaUtilities functions from DLLs is finally delivered + if(ModelicaErrorPtr == nullptr) + ModelicaErrorPtr = tryImportSymbol("ModelicaError"); + if(ModelicaErrorPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx - ModelicaErrorPtr(msg.c_str()); + ModelicaErrorPtr(msg.c_str()); else { // The pointer to ModelicaError is not yet initialized, so all we can do @@ -58,10 +61,13 @@ void warningMessage(char *warningMsg){ #else // Workaround code for Windows, will be removed when a proper solution to // call ModelicaUtilities functions from DLLs is finally delivered + if(ModelicaWarningPtr == nullptr) + ModelicaWarningPtr = tryImportSymbol("ModelicaWarning"); + if(ModelicaWarningPtr) // The pointer to ModelicaError has already been initialized by a previous // call to setState_xx - ModelicaWarningPtr(msg.c_str()); + ModelicaWarningPtr(msg.c_str()); else { // The pointer to ModelicaError is not yet initialized, so all we can do diff --git a/Projects/Sources/importer.h b/Projects/Sources/importer.h index 444e10e8..2c1e0deb 100644 --- a/Projects/Sources/importer.h +++ b/Projects/Sources/importer.h @@ -15,7 +15,7 @@ #include template -T importSymbol(const char *funcName) +T tryImportSymbol(const char *funcName) { /* TODO: we should do caching */ @@ -54,6 +54,16 @@ T importSymbol(const char *funcName) if(pfn) return pfn; } + /* not found */ + return NULL; +} + +template +T importSymbol(const char *funcName) +{ + T result = tryImportSymbol(funcName); + if(result) return result; + fprintf(stderr, "Can't get handle to %s in all loaded modules.\n", funcName); exit(1); }