User Guide
374 Chapter 4: C-Level Extensibility
{ \
extern void MM_Init(); \
\
char **envPtr = (char **)env; \
char **mmPtr = (char **)(&mmEnv); \
char **envEnd = (char **)((char *)envPtr + envSize); \
char **mmEnd = (char **)((char *)mmPtr + sizeof(MM_Environment));
\
\
/* Copy fields from env to mmEnv, one pointer at a time */ \
while (mmPtr < mmEnd && envPtr < envEnd) \
*mmPtr++ = *envPtr++; \
\
/* If env doesn't define all of mmEnv's fields, set extras to NULL */
\
while (mmPtr < mmEnd) \
*mmPtr++ = (char *)0; \
\
/* Call user's MM_Init function */ \
MM_Init(); \
} \
#endif /* _MM_JSAPI_H_ */
Sample implementation
Included with this documentation is a set of files (Sample.zip for Windows, Sample.sit for
Macintosh) that you can use to test the process of building a DLL. (You can download the file at
www.macromedia.com/go/jsapi_info_en).
To see how the process works without actually building the DLL, you can do the following:
• Store the Sample.jsfl file in the Commands directory (see “Overview of the Macromedia Flash
JavaScript API” on page 17).
• Store the Sample.dll file in the External Libraries directory (see “How integrating C functions
works” on page 369).
• In the Flash authoring environment, select Commands > Sample. The trace statement in the
JSFL file sends the results of the function defined in Sample.dll to the Output panel.
This section discusses the development of the sample. In this case, the DLL contains only one
function, which adds two numbers. The C code is shown in the following example:
// Source code in C
// Save the DLL or shared library with the name "Sample"
#include <windows.h>
#include <stdlib.h>
#include "mm_jsapi.h"
// A sample function
// Every implementation of a Javascript function must have this signature
JSBool computeSum(JSContext *cx, JSObject *obj, unsigned int argc, jsval
*argv, jsval *rval)
{