GENERATE/PREV.gifGENERATE/NEXT.gif

DLL Setup

MAXScript plug-in extensions are packaged as Win32 DLL's in almost exactly the same way as standard MAX plug-ins. They are named with a specific suffix to fit in with the MAX plug-in naming scheme (.DLX) and should be installed in one of the MAX plug-in directories. MAXScript looks for and loads all the *.DLX files it finds in the MAX plug-in directories.

You should be familiar with the section on MAX plug-in construction in the MAX SDK documentation because the following notes primarily describe what is different about setting up MAXScript plug-ins.

The plug-in's external interface is defined with a .DEF file, as are MAX plug-ins, but in this case there are only three entry points:

LIBRARY <plugin_name>

EXPORTS

LibDescription      @1

LibInit      @2

LibVersion      @3

SECTIONS

.data READ WRITE

The LibDescription and LibVersion entry points are the same as for MAX plug-ins. The LibInit entry is called by MAX after MAXScript has loaded itself and all its .DLX plug-ins so that each can perform any runtime initialization. MAXScript is fully functional at the time these init functions are called.

The following code shows a typical DLX entry point implementation (this is from sample.cpp in the SDK). All of the required headers are included by the master header file, MAXscrpt.h, including Max.h for MAX SDK-related code.

#include "MAXScrpt.h"

 

HMODULE hInstance;

 

BOOL APIENTRY

DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)

{

     static BOOL controlsInit = FALSE;

     switch (ul_reason_for_call)

     {

          case DLL_PROCESS_ATTACH:

               // Hang on to this DLL's instance handle.

               hInstance = hModule;

               if (!controlsInit)

               {

                    controlsInit = TRUE;

                    // Initialize Win95 controls

                    InitCommonControls();

               }

               break;

     }

     return(TRUE);

}

 

__declspec( dllexport ) void

LibInit()

{

     // do any setup here. MAXScript is fully up at this point.

}

 

__declspec( dllexport ) const TCHAR *

LibDescription()

{

return _T("Sample MAXscript DLX");

}

 

__declspec( dllexport ) ULONG

LibVersion()

{

return VERSION_3DSMAX;

}

 

If any Win32 common controls or MAX custom controls are to be used in the DLL, you should initialize them during process attach, in the same way you would in a MAX DLL. For the LibVersion entry point, you should return the current 3DSMAX version as shown.