540
C-Level Extensibility
Sample DLL implementation
A sample DLL implementation is located in ZIP and SIT files in the ExtendingFlash/
dllSampleComputeSum folder (see
“Sample implementations” on page 19
). 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
“Saving JSFL files” on page 7
).
■
Store the Sample.dll file in the External Libraries directory (see
“Integrating C functions”
on page 534
).
■
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)
{
long a, b, sum;
// Make sure the right number of arguments were passed in.
if (argc != 2)
return JS_FALSE;
// Convert the two arguments from jsvals to longs.
if (JS_ValueToInteger(cx, argv[0], &a) == JS_FALSE ||
JS_ValueToInteger(cx, argv[1], &b) == JS_FALSE)
return JS_FALSE;
/* Perform the actual work. */
sum = a + b;
/* Package the return value as a jsval. */
*rval = JS_IntegerToValue(sum);
/* Indicate success. */
return JS_TRUE;
}
Summary of Contents for FLASH 8-EXTENDING FLASH
Page 1: ...Extending Flash...
Page 38: ...38 Top Level Functions and Methods...
Page 532: ...532 Objects...
Page 554: ...554 C Level Extensibility...