Sets a handler procedure for the case of abnormal termination.
void ACAPI_SetDllTermHookProc ( APIDllTermHookProc* dllTermHookProc );
Parameters
- dllTermHookProc
- [in] Handler function pointer
Remarks
Normally the FreeData function of the add-on is called before the add-on module is unloaded from the memory. However in some exceptional cases the application terminates without properly unloading the add-ons. For handling these situations you can set a hook procedure with the ACAPI_SetDllTermHookProc
function. This might be useful if, for example, you have loaded additional modules (DLLs) from your add-on, and you want to unload them even in the case of abnormal termination.
Example
#include "IOUtilities.hpp" static IOUtil::ModuleFile* additionalModule = nullptr; //------------------------------------------------------ // Called in case of abnormal termination //------------------------------------------------------ static void __ACENV_CALL MyDllTermHookProc (void) { if (additionalModule != nullptr) { additionalModule->UnLoad (); delete additionalModule; additionalModule = nullptr; } return; } //------------------------------------------------------ // Called when the Add-On has been loaded into memory // to perform an operation //------------------------------------------------------ GSErrCode __ACENV_CALL Initialize (void) { additionalModule = new IOUtil::ModuleFile (IO::Location("AdditionalLibrary.DLL")); if (additionalModule != nullptr) { if (additionalModule->Load () != NoError || additionalModule->GetProcAddress ("ExportedAdditionalFunction") == nullptr) { additionalModule->UnLoad (); delete additionalModule; additionalModule = nullptr; } } ACAPI_SetDllTermHookProc (MyDllTermHookProc); return NoError; } //------------------------------------------------------ // Called when the Add-On is going to be unloaded //------------------------------------------------------ GSErrCode __ACENV_CALL FreeData (void) { if (additionalModule != nullptr) { additionalModule->UnLoad (); delete additionalModule; additionalModule = nullptr; } return NoError; }
Requirements
- Version: API 10 or later
- Header: ACAPinc.h