@@ -59,7 +59,7 @@ PM_STATUS(*pFunc_pmDiagnosticUnblockWaitingThread_)() = nullptr;
5959// pointers to runtime-resolved internal functions
6060_CrtMemState (*pFunc_pmCreateHeapCheckpoint__)() = nullptr;
6161LoggingSingletons (*pFunc_pmLinkLogging__)(std::shared_ptr<pmon::util::log::IChannel>,
62- pmon::util::log::IdentificationTableCallbacks ) = nullptr;
62+ std::function< pmon::util::log::IdentificationTable&()> ) = nullptr;
6363void (*pFunc_pmUnlinkLogging__)() = nullptr ;
6464void (*pFunc_pmFlushEntryPoint__)() = nullptr ;
6565void (*pFunc_pmSetupODSLogging__)(PM_DIAGNOSTIC_LEVEL , PM_DIAGNOSTIC_LEVEL , bool ) = nullptr ;
@@ -79,7 +79,7 @@ bool middlewareLoadedSuccessfully_ = false;
7979
8080// loader-internal implementation functions
8181// inner impl of method for deriving the mangled name of a cpp-linkage function and loading it
82- void * GetCppProcAddress_Impl_ (HMODULE h,const char * name, const char * mangledEmbeddedSignature)
82+ void * GetCppProcAddress_Impl_ (HMODULE h, const char * name, const char * mangledEmbeddedSignature, bool required )
8383{
8484 // don't bother including receiving template function name
8585 std::string Signature = mangledEmbeddedSignature + 22 ;
@@ -92,13 +92,20 @@ void* GetCppProcAddress_Impl_(HMODULE h,const char* name, const char* mangledEmb
9292 if (auto pFunc = GetProcAddress (h, funName.c_str ())) {
9393 return pFunc;
9494 }
95- throw LoaderExcept_ (PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT );
95+ if (required) {
96+ throw LoaderExcept_ (PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT );
97+ }
98+ return nullptr ;
9699}
97100// load a cpp linkage function from a dll module
98101template <typename F>
99- F GetCppProcAddress_ (HMODULE h, const char * name)
102+ F GetCppProcAddress_ (HMODULE h, const char * name, bool required = true )
100103{
101- return reinterpret_cast <F>(GetCppProcAddress_Impl_ (h, name, __FUNCDNAME__));
104+ void * pFunc = GetCppProcAddress_Impl_ (h, name, __FUNCDNAME__, required);
105+ if (!pFunc) {
106+ return nullptr ;
107+ }
108+ return reinterpret_cast <F>(pFunc);
102109}
103110// load a c-linkage function
104111FARPROC GetProcAddress_ (HMODULE h, const char * name)
@@ -134,7 +141,7 @@ PRESENTMON_API2_EXPORT PM_STATUS LoadLibrary_(bool versionOnly = false)
134141 }
135142 }
136143#define RESOLVE (f ) pFunc_##f##_ = reinterpret_cast <decltype (pFunc_##f##_)>(GetProcAddress_(hMod_, #f))
137- #define RESOLVE_CPP (f ) pFunc_##f##_ = GetCppProcAddress_<decltype (pFunc_##f##_)>(hMod_, #f)
144+ #define RESOLVE_CPP_OPTIONAL (f ) pFunc_##f##_ = GetCppProcAddress_<decltype (pFunc_##f##_)>(hMod_, #f, false )
138145 // resolve version endpoint first as it is needed here
139146 RESOLVE (pmGetApiVersion);
140147 // if this load operation was instigated by calling version, don't do version check or load other endpoints
@@ -188,14 +195,14 @@ PRESENTMON_API2_EXPORT PM_STATUS LoadLibrary_(bool versionOnly = false)
188195 RESOLVE (pmDiagnosticFreeMessage);
189196 RESOLVE (pmDiagnosticWaitForMessage);
190197 RESOLVE (pmDiagnosticUnblockWaitingThread);
191- // internal
192- RESOLVE_CPP (pmCreateHeapCheckpoint_);
193- RESOLVE_CPP (pmLinkLogging_);
194- RESOLVE_CPP (pmUnlinkLogging_);
195- RESOLVE_CPP (pmFlushEntryPoint_);
196- RESOLVE_CPP (pmSetupODSLogging_);
197- RESOLVE_CPP (pmSetupFileLogging_);
198- RESOLVE_CPP (pmStopPlayback_);
198+ // internal (optional: older middleware may omit refactored hooks)
199+ RESOLVE_CPP_OPTIONAL (pmCreateHeapCheckpoint_);
200+ RESOLVE_CPP_OPTIONAL (pmLinkLogging_);
201+ RESOLVE_CPP_OPTIONAL (pmUnlinkLogging_);
202+ RESOLVE_CPP_OPTIONAL (pmFlushEntryPoint_);
203+ RESOLVE_CPP_OPTIONAL (pmSetupODSLogging_);
204+ RESOLVE_CPP_OPTIONAL (pmSetupFileLogging_);
205+ RESOLVE_CPP_OPTIONAL (pmStopPlayback_);
199206 // if we make it here then we have succeeded
200207 middlewareLoadResult_ = PM_STATUS_SUCCESS ;
201208 }
@@ -339,21 +346,27 @@ PRESENTMON_API2_EXPORT _CrtMemState pmCreateHeapCheckpoint_()
339346 throw LoaderExcept_ (status);
340347 }
341348 }
349+ if (!pFunc_pmCreateHeapCheckpoint__) {
350+ throw LoaderExcept_ (PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT );
351+ }
342352 return pFunc_pmCreateHeapCheckpoint__ ();
343353}
344354PRESENTMON_API2_EXPORT LoggingSingletons pmLinkLogging_ (std::shared_ptr<pmon::util::log::IChannel> pChannel,
345- pmon::util::log::IdentificationTableCallbacks idTableCallbacks )
355+ std::function< pmon::util::log::IdentificationTable& ()> getIdTable )
346356{
347357 if (!middlewareLoadedSuccessfully_) {
348358 if (auto status = LoadLibrary_ (); status != PM_STATUS_SUCCESS ) {
349359 throw LoaderExcept_ (status);
350360 }
351361 }
352- return pFunc_pmLinkLogging__ (pChannel, idTableCallbacks);
362+ if (!pFunc_pmLinkLogging__) {
363+ return {};
364+ }
365+ return pFunc_pmLinkLogging__ (pChannel, std::move (getIdTable));
353366}
354367PRESENTMON_API2_EXPORT void pmUnlinkLogging_ () noexcept
355368{
356- if (middlewareLoadedSuccessfully_) {
369+ if (middlewareLoadedSuccessfully_ && pFunc_pmUnlinkLogging__ ) {
357370 pFunc_pmUnlinkLogging__ ();
358371 }
359372}
@@ -363,7 +376,7 @@ PRESENTMON_API2_EXPORT void pmFlushEntryPoint_() noexcept
363376 // flush is called even in cases where the dll hasn't been loaded
364377 // allow it to be elided in this case since it has no effect without
365378 // other functions being called previously anyways
366- if (middlewareLoadedSuccessfully_) {
379+ if (middlewareLoadedSuccessfully_ && pFunc_pmFlushEntryPoint__ ) {
367380 pFunc_pmFlushEntryPoint__ ();
368381 }
369382}
@@ -375,6 +388,9 @@ PRESENTMON_API2_EXPORT void pmSetupODSLogging_(PM_DIAGNOSTIC_LEVEL logLevel,
375388 throw LoaderExcept_ (status);
376389 }
377390 }
391+ if (!pFunc_pmSetupODSLogging__) {
392+ throw LoaderExcept_ (PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT );
393+ }
378394 pFunc_pmSetupODSLogging__ (logLevel, stackTraceLevel, exceptionTrace);
379395}
380396PRESENTMON_API2_EXPORT PM_STATUS pmDiagnosticSetup (const PM_DIAGNOSTIC_CONFIGURATION * pConfig)
@@ -437,12 +453,18 @@ PRESENTMON_API2_EXPORT PM_STATUS pmSetupFileLogging_(const char* file, PM_DIAGNO
437453 PM_DIAGNOSTIC_LEVEL stackTraceLevel, bool exceptionTrace)
438454{
439455 LoadEndpointsIfEmpty_ ();
456+ if (!pFunc_pmSetupFileLogging__) {
457+ return PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT ;
458+ }
440459 return pFunc_pmSetupFileLogging__ (file, logLevel, stackTraceLevel, exceptionTrace);
441460}
442461
443462PRESENTMON_API2_EXPORT PM_STATUS pmStopPlayback_ (PM_SESSION_HANDLE hSession)
444463{
445464 LoadEndpointsIfEmpty_ ();
465+ if (!pFunc_pmStopPlayback__) {
466+ return PM_STATUS_MIDDLEWARE_MISSING_ENDPOINT ;
467+ }
446468 return pFunc_pmStopPlayback__ (hSession);
447469}
448470
0 commit comments