TC7.50: Message box problem when unloading FS plugin

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

TC7.50: Message box problem when unloading FS plugin

Post by *tbeu »

The MKS SI Browser FS plugin displays a message box when unloading the plugin / closing TC. The relevant message box code is

Code: Select all

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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Hmm, no idea - a MessageBox function has its own message loop, so I don't see any reason why it wouldn't react...
Author of Total Commander
https://www.ghisler.com
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Please try to reproduce. I also could create a dummy FS plugin if needed for debugging.
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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Why do I need to do that? Just remove the MessageBox from DLL_PROCESS_DETACH to fix it. It's annoying anyway to get a MessageBox on each shutdown...
Author of Total Commander
https://www.ghisler.com
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

ghisler(Author) wrote:Why do I need to do that?
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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Sorry, I really don't know why the MessageBox fails here. If I had an idea, I wouldn't suggest that you remove it.
Author of Total Commander
https://www.ghisler.com
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

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
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Just as a late response: This problem was only present in TC 7.5RC1, 7.5RC2, 7.50 and 7.50a. It is fixed in all newer versions including TC 8PB3.
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
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

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).
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

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
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

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
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50479
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

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.
Author of Total Commander
https://www.ghisler.com
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

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.
User avatar
tbeu
Power Member
Power Member
Posts: 1354
Joined: 2003-07-04, 07:52 UTC
Location: Germany
Contact:

Post by *tbeu »

Yes, that's the reason we need PluginUnloading() functions to have a clean plugin API.
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
Post Reply