下面的例子中,回调函数SetUnloadProgramFunction传入的函数参数有么这一段注释:
/*------------------------------------------------------------------ | If the value of unloadType is negative, then MicroStation ignores | the return value of this function. In this case, we can assume | that MicroStation is shutting down or was terminated so this | function should not attempt to abort the unload. +------------------------------------------------------------------*/
老师能帮忙解释下是什么意思不?例子中如果myapp_unloadFunction的返回值为true的话,发现应用程序就无法卸载。
Public bool myapp_unloadFunction(UnloadProgramReason unloadType) { /*------------------------------------------------------------------ | If the value of unloadType is negative, then MicroStation ignores | the return value of this function. In this case, we can assume | that MicroStation is shutting down or was terminated so this | function should not attempt to abort the unload. +------------------------------------------------------------------*/ if (unloadType < 0) { return true; } OUTPUT("Unload......"); return false; } extern "C" DLLEXPORT void MdlMain(int, WCharCP[]) { SystemCallback::SetUnloadProgramFunction(myapp_unloadFunction); }
unloadType是系统传递进来的值,表明你的MDL应用程序被卸载的原因,定义如下:
enum UnloadProgramReason { SYSTEM_TERMINATED_UNLOADING_APPDOMAIN = -6, SYSTEM_TERMINATED_ENTERING_RESTRICTED_RIGHTS_MODE = -5, SYSTEM_TERMINATED_UNLOAD_UI_SERVERS = -4, SYSTEM_TERMINATED_LIBRARY_UNLOAD = -3, SYSTEM_TERMINATED_SHUTDOWN = -2, SYSTEM_TERMINATED_FATAL = -1, SYSTEM_TERMINATED_COMMAND = 1, SYSTEM_TERMINATED_EXIT = 2, SYSTEM_TERMINATED_BY_APP = 3, SYSTEM_TERMINATED_EXCEPTION = 4 };
而该函数的返回值决定了是否要阻止当前MDL应用程序的卸载,正如你观察到的,返回true表示阻止卸载(只有当退出整个MicroStation时才会被卸载),返回false允许卸载。
有些重要的程序(比如自定义元素Handler等)是不能被卸载的,一旦卸载将会导致异常出现(系统不认识自定义元素了)。对于这些程序,要在其unload回调函数中返回true。
Answer Verified By: 管华明
好的,非常感谢老师的解疑。