Deferred Loading of Plug-ins

3DS Max Plug-In SDK

Deferred Loading of Plug-ins

See Also: Class DataClassDesc, Class ClassEntry.

Overview

It is possible to indicate to 3ds max that certain plug-ins should not be loaded at startup. Each deferred plug-in will be loaded when and if needed, which will happen when one or more of the 3ds max classes implemented by the plug-in is actually created. It might also happen when detailed information about the plug-in is requested. The principal benefit of deferral is that the Windows resources used by the plug-in will not be consumed unless there is some specific use or interrogation of the plug-in. Time taken at startup to load the plug-in, assign its virtual memory, etc. is also saved, or at least deferred.

Deferral is governed by entries in the Windows Registry. These entries contain critical information about each plug-in to be deferred, and about each 3ds max class implemented by each such plug-in. (See details below.) This information must agree with the corresponding values returned by API calls to the plug-in itself. Disagreement can seriously impair the integrity of 3ds max itself. Typically the Registry entries are created by an installer program or by 3ds max itself if the plug-in supports AutoDefer, but in special cases they could be created by run-time code in a plug-in, or by manual use of a Registry editor.

AutoDefer

If a plug-in supports deferred loading it can let 3ds max automatically register it. This is done by implementing a new function exported from the DLL itself. This function is called CanAutoDefer() and is an addition to the four other required DLL exported functions: LibNumberClasses(), LibVersion(), LibDescription() and LibClassDesc(). Example:

// Let the plug-in register itself for deferred loading

__declspec( dllexport ) ULONG CanAutoDefer()

{

return 1;

}

You will also need to add this line to the *.DEF file. Example:

CanAutoDefer @5

Before adding this function to a plug-in you have to make sure that the plug-in actually supports deferral.

When 3ds max starts up it loads all the plug-in that are not listed as deferred in the registry. If a plug-in is not found in the registry, 3ds max will ask the plug-in if it can be deferred by checking the implementation of CanAutoDefer(). If the function is defined, and it returns a non-zero value, then 3ds max continues to load the plug-in and queries it for all the values needed to store in the registry. 3ds max will then write the needed registry information so that next time it starts up, the plug-in will be deferred, i.e. it will not be loaded until it is needed.

When a plug-in is registered by AutoDefer a timestamp is added to the registry. During start-up, if the timestamp of the DLL doesn’t match the one in the registry, then the registry information about that plug-in is deleted, the plug-in is loaded, and the plug-in is registered again.

The format of the timestamp is taken from the lpLastWriteTime member of the Win32 function GetFileTime(). The timestamp is devided into two entries, TimeStampHigh and TimeStampLow, referencing the dwLowDateTime and dwHighDateTime members of the FILETIME structure.

Registry Key Structure

The following chain of Registry keys establishes the base for all plug-in descriptions:

\\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\3ds max\4.0\Plug-ins

and

\\HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\3ds max\4.0\Plug-ins\Discreet

Under the ‘Plugins’ key, there can be one key for each supplier of plug-ins; for the internal 3ds max plug-ins, this key is ‘Discreet’. Under the key for a supplier there will be one key per deferrable plug-in, with a name that is distinct from all other plug-in key names from that supplier.

This ‘plug-in key’ has certain mandatory values, and under it there will be one key per 3ds max class implemented by the plug-in. The name of each class key must be distinct, at least within the given plug-in. Each such ‘class key’ has a set of values, describing certain important properties of the class.

Plug-in Key Values(all must be supplied)

Value Type Example

DLLFile REG_SZ vrmlimp.dli

LibDescription REG_SZ VRML Scene Importer

LibVersion REG_DWORD 0xbb80600

TimeStampHigh REG_DWORD 0x1be7679 (optional, only supplied for AutoDefer plug-ins)

TimeStampLow REG_DWORD 0x2d8172f2 (optional, only supplied for AutoDefer plug-ins)

Notes: The DLLFile value gives the name of the DLL file that this key describes; case is disregarded. The name must be unique, and must not match two different files, even if they are in different directories.

Class Key Values

Value Type Example Required for:

ClassIDA REG_DWORD 0x35da0f0a All

ClassIDB REG_DWORD 0x10ce4af8 All

ClassName REG_SZ VrmlImp All

Category REG_SZ SceneImport All

SuperClassID REG_DWORD 0xa10 All

IsPublic REG_DWORD 1 All

OKToCreate REG_DWORD 1 All

ShortDesc REG_SZ VRML Importers, exporters, bitmap loaders

SupportsOptions REG_DWORD 0 Exporters

LongDesc REG_SZ BMP Image File Bitmap loaders

Capability REG_DWORD 0 Bitmap loaders

ExtCount REG_DWORD 2 Importers, exporters, bitmap loaders

Ext REG_SZ WRL;WRZ Importers, exporters, bitmap loaders

InputTypeA REG_DWORD 0x10 Modifiers

InputTypeB REG_DWORD 0x00 Modifiers

InternalName REG_SZ BitmapTex All plug-ins using

   ParamBlock2/ClassDesc2

Notes: The IsPublic and OKToCreate values should be 0 (no) or 1 (yes). The Ext value consists of upper-case file extensions (without the leading dot); if there are more than one, they are separated by semicolons, with no spaces before or after. The number of extensions given in the Ext value must agree with the ExtCount value. The InternalName value should not be defined if it returns NULL.

Deferrable Plug-ins

To be eligible for deferred loading, a plug-in must meet all of the following criteria.

· All 3ds max classes that it implements must be subclasses of superclasses in the list below.

· All required values must be supplied, and must be constant. Values must not depend on run-time circumstances.

· If values depend on build configurations (e.g. Debug vs. Release), results may be undefined.

· The plug-in must not implement any keyboard accelerators.

Supported Superclasses are: Scene Import, Scene Export, Utility, Bitmap Loader, Helper, Geometric Object, Material/Texture, Image Filter, OSM (Modifiers), WSM/WSMObjects (Space Warps)

A plug-in that does not meet these requirements must not be described for deferral in the Registry.