Problem: plugin management in NC is not very user friendly and fool-proof (+ possibly even buggy).
- Plugins are not accepted in same directory as NC
- It says "Error: Don't know how to read this picture" ... but better message would be "This format needs the plugin" (name) or "Plugin" (name) "failed" (additionally at startup: "Plugin" (name) "DLL load/init failed" or "NOT found")
- Loads same plugin 2 times (5.85: before and after opening the input file) (or even more is possible?) ??? Tries even wrong plugins (5.80) ...
- Very hard to debug, verbose option says nothing about attempts to find or use plugins
So I invented following (pseudo-code) to fix this (run at NC start, before opening any input files):
Code: Select all
X0 = GetFileAttributes ("PLUGINS")
IF (X0 says "exists and is a DIRECTORY") THEN
    PluginSearchPath="PLUGINS\" // The old known behavior 
ELSE
    PluginSearchPath="" // Look in the same directory
ENDIF
PluginIndex := 0
DO
    IF (PluginIndex says "no more plugins") THEN EXIT
    PluginName = ArrayOfPluginNames (PluginIndex)
    PluginMoHaArray (PluginIndex) := 0 // NOT available
    S1 = PluginSearchPath + PluginName + ".DLL"
    IF ("verbose") THEN PRINT "Plugin: " + S1 + " ... "
    X2 = GetFileAttributes (S1)
    IF (X2 says "exists and is a file") THEN
        X3 = LoadLibrary (S1)
        IF (X3 == "success") THEN
            PluginMoHaArray (PluginIndex) := X3 // Save Module Handle
            IF ("verbose") THEN PRINT "Loaded OK"
        ELSE
            IF ("verbose") THEN PRINT "DLL load/init failed" 
            // Most ^^^ likely some stupid 4th party DLL like
            // MSVCxxxx was not found or has wrong version :-(
        ENDIF (X3 == "success") // LoadLibrary result
    ELSE // plugin file existence
        IF ("verbose") THEN PRINT "NOT found"
    ENDIF // plugin file existence
    INC (PluginIndex)
    IF ("verbose") THEN PRINT (EOL)
LOOP
- "Error: Don't know how to read this picture" only if no plugin exists to handle it
- "This format needs the plugin" (name) if plugin could help, but (PluginMoHaArray (PluginIndex) == 0)
- "Plugin" (name) "failed" if plugin returned failure or GetProcAddress return "NOT found" for needed function
Example output:
---------------------------
orPlugin: "webp.dll" ... Loaded OK
Plugin: "CADImage.DLL" ... NOT found
Plugin: "CS_DXF.DLL" ... NOT found
Plugin: "lwf.dll" ... NOT found
Plugin: "ldf.dll" ... DLL load/init failed
---------------------------Plugin: "PLUGINS\webp.dll" ... Loaded OK
Plugin: "PLUGINS\CADImage.DLL" ... Loaded OK
Plugin: "PLUGINS\CS_DXF.DLL" ... Loaded OK
Plugin: "PLUGINS\lwf.dll" ... Loaded OK
Plugin: "PLUGINS\ldf.dll" ... Loaded OK
orThis format needs the plugin "WEBP.DLL"
---------------------------Plugin "WEBP.DLL" failed