BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_DETACH :
if (IDYES == MessageBox(NULL,
"Disconnect and exit all MKS Integrity Client applications?",
PLUGIN,
MB_YESNO | MB_ICONQUESTION))
{
_snprintf(mksCMD, sizeof(mksCMD) - 1, "%s exit --yes", mksEXE);
mksHandler->runCmd(mksCMD);
}
break;
case ...
}
...
}
The message box correctly pops up for TC up to version 7.50PB8 when closing TC. Since TC 7.50RC1 the message box also pops up but cannot be clicked at. Hence the TC process hangs and needs to be killed. It still works for cm_UnloadPlugins but not if TC is closed.
Any ideas?
According to HISTORY.TXT there is a possible fix in TC 7.50RC1 that might affect the plugin unloading.
12.08.09 Fixed: Crash on exit after using Startup Guard plugin (due to a bug in the plugin, still occurs when using cm_UnloadPlugins)
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
Because it worked in previous versions (up to TC7.50PB8). So TC changed the FS unloading behaviour. And obviously this was not by your intention but a side effect I assume (since cm_UnloadPlugins still works but not TC closing).
ghisler(Author) wrote:Just remove the MessageBox from DLL_PROCESS_DETACH to fix it. It's annoying anyway to get a MessageBox on each shutdown...
You cannot stipulate how to program and how not. A MessageBox might be annoying but it is not forbidden to use one here. Furthermore deleting the MessageBox does not solve the actual problem. It merely is a workaround.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
Here is the sampleplugin.zip that demonstrates the bug introduced with TC 7.5RC1. To reproduce install fsplugin.wfx as FS plugin navigate to Network Neighbourhood -> Drives and close TC.
In the case of the MKS SI Browser FS plugin a configuration option ShowDisconnectMKSDlgAtExit exists that disables the MessageBox when unloading the plugin.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
I got same problem with my Virtual Panel plugin (I displayed message box on error writing INI), but it is a bad idea to do something serious in DllMain (e.g. you must not initialize/finalize OLE etc), so I removed it (moved into another place).
MVV wrote:I got same problem with my Virtual Panel plugin (I displayed message box on error writing INI), but it is a bad idea to do something serious in DllMain (e.g. you must not initialize/finalize OLE etc), so I removed it (moved into another place).
Yes, I moved serious initialization calls to FsSetDefaultParams(), ListSetDefaultParams(), PackSetDefaultParams() or ContentSetDefaultParams(), respectively. But for finalization there is no such function for wcx, wlx and wfx, only ContentPluginUnloading() exists for wdx. For that reason I used DllMain() to call finalization functions of wfx.
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
2ghisler
Which plugin function do you recommend for crucial finalization calls (like CoUninitialize()) if DllMain() is not the right choice? Shouldn't there be a PluginUnloading() function for each type of plugin and not just ContentPluginUnloading()?
TC plugins: Autodesk 3ds Max / Inventor / Revit Preview, FileInDir, ImageMetaData (JPG Comment/EXIF/IPTC/XMP), MATLAB MAT-file Viewer, Mover, SetFolderDate, Solid Edge Preview, Zip2Zero and more
There is no need to call CoInitialize in your dll. TC calls OleInitialize at startup, and OleInitialize calls CoInitializeEx. The only exception is when you create a thread: You need to call CoInitialize for each of your own threads.
That's the problem:) we need to call it for every thread but we can't do it in DllMain, and we can't call CoUninitialize in DllMain too, so we can't call it on plugin unload for background threads.