Shell namespace extensions are quite complex. We have been building a shell namespace extension for the past 10 years; the latest incarnation of which is the Archive Folders feature in MagicRAR (www.magicrar.com).
Unfortunately, there are still occasional crashes with our shell namespace extension, despite extremely careful coding, ensuring threads properly access shared memory, and such. The Explorer host process crashes during or outside of the use of our shell namespace extension.
We have used a variety of tools such as AQTime Pro to troubleshoot our shell namespace extension code. There are no memory overwrites or other similar access problems reported. This leaves only one culprit: the VCL is not thread safe!
Indeed, we are using the VCL as part of our shell namespace extension; the file list in Explorer is actually a hosted control and in the case of our own shell namespace extension, it is actually a VCL window. We are now even wondering (after multiple generations of development) whether this is an allowed scenario in the first place...
The main application object doesn't even exist in our shell namespace extension DLL. Using TThread.Synchronize deadlocks Explorer, since a main VCL thread has not been created anywhere. Do we need to manually create a main VCL thread (how?) - possibly inside another DLL - and re-route all our UI creation/updates/destruction through that DLL?
Remember, Explorer may be showing any number of windows containing our VCL window. Explorer may also be running as multiple independent processes, or as a single process, based on the configuration of the target system.
We have based our shell namespace extension on John Lam's starting point (as most Delphi shell namespace developers would know). Of course, as you can see in the final product, there have been heavy modifications to this starting point. John Lam never even once discusses the issue of the VCL being thread-unsafe in his slides and example projects.
We have also attempted to use multiple versions of ShellPlus components over the past decade. They have done some excellent work, but unfortunately, in our experience, even very elementary efforts based on their code have offered significantly worse results than our own code.
ShellPlus actually also offers the capability to use Explorer's own pre-defined host window, instead of creating a custom VCL window; while this might sidestep any VCL threading issues, in our experience even this has not been a viable solution - because the ShellPlus shell namespace extensions have always been less stable than our home brewed code, whether VCL windowed or not.
So first and foremost; this question is a theoretical one - can the VCL be used in a shell namespace extension that uses a VCL window inside Explorer as a process host?
If so, how is the issue of VCL thread safelessness to be handled in this scenario?