[BUG] TC calls plugin functions before DLLMain returned
Moderators: Hacker, petermad, Stefan2, white
[BUG] TC calls plugin functions before DLLMain returned
As written in the title. I think this shouldn't happen..
How could it do that? I mean, if DLLMain of a plugin hasn't returned yet, the corresponding LoadLibrary call hasn't returned as well - so TC doesn't have a handle for the library yet, so it can't GetProcAddress it and call its exported function...
Even if you meant thread attaching, I can't imagine a way... so, do you have any more information about your problem?
Even if you meant thread attaching, I can't imagine a way... so, do you have any more information about your problem?
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Sorry, I have no idea how this could happen. TC calls LoadLibrary and then GetProcAddress for all the functions. Then it calls ContentSetDefaultParams (if present) and then any other functions.
What does your plugin do in DLLMain?
What does your plugin do in DLLMain?
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
What exactly are you calling in DLLMain? For example, you should not call LoadLibrary there in any case!
From MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp
So if you need to load any DLLs, please do it in the ContentGetSupportedField and ContentGetValue functions.
Just set a variable "DllLoaded" to false in DLLMain when it is called with DLL_PROCESS_ATTACH, and then load your dlls on the first call to ContentGetSupportedField or ContentGetValue.
From MSDN:
You can find a list of what you should/should not do here:The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code. Similarly, the entry-point function must not call the FreeLibrary function (or a function that calls FreeLibrary) during process termination, because this can result in a DLL being used after the system has executed its termination code.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/dllmain.asp
So if you need to load any DLLs, please do it in the ContentGetSupportedField and ContentGetValue functions.
Just set a variable "DllLoaded" to false in DLLMain when it is called with DLL_PROCESS_ATTACH, and then load your dlls on the first call to ContentGetSupportedField or ContentGetValue.
Yes, maybe I can find ou what is going wrong.If you find it important (or maybe interesting), I can send you my sources.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
No I don't. This is during loading of the DLL. Loading should be as fast as possible. Slowly loading DLLs should only be loaded when needed, which would be on the first call to an actual dll function. Sometimes they don't even need to be called on ContentGetSupportedField (the plugin may already know what it supports), only on ContentGetValue. This way, such additional dlls wouldn't be loaded e.g. in the multi-rename tool when opening the entire list of plugins...
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
Well I used the suggested mechanism once in one of my plug-ins but recieved mainly complaints from 3rd party tool creators...
Beside that I'm not aware of case where TC loads the library without calling ContentGetSupportedFields.
In all other cases you are of course right but I guess these cases are quite rare.
Beside that I'm not aware of case where TC loads the library without calling ContentGetSupportedFields.
In all other cases you are of course right but I guess these cases are quite rare.
Would be helpful to read this statement in the plugin interface documentations. I was not aware of this coding policy.ghisler(Author) wrote:For example, you should not call LoadLibrary in DLLMain in any case!
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
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
This isn't a problem with Total Commander, it's a general Windows problem with DLLs.Would be helpful to read this statement in the plugin interface documentations. I was not aware of this coding policy.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com