Sample DLL implementation
A sample DLL implementation is located in ZIP and SIT files in the ExtendingFlash/
dllSampleComputeSum folder (see
process works without actually building the DLL, you can do the following:
Store the Sample.jsfl file in the Commands directory (see
Store the Sample.dll file in the External Libraries directory (see
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;
}
540
C-Level Extensibility
"Sample implementations" on page
19). To see how the
"Saving JSFL files" on page
"Integrating C functions"
7).
Need help?
Do you have a question about the FLASH 8-EXTENDING FLASH and is the answer not in the manual?
Questions and answers