India seo web development website designer freelance
Calling a C function from JavaScript
After you understand how C-level extensibility works in and its dependency on certain data types and functions, it's useful to know how to build a library and call a function.
This example requires four files, which are included in the Extending/c_files folder inside the application folder:
- mm_jsapi.h is a header file that includes definitions for the data types and functions that are described in C-level extensibility and the JavaScript interpreter .
- mm_jsapi_environment.h, which defines the MM_Environment.h structure.
- Sample.c is an example file that defines the computeSum() function.
- Sample.mak is a makefile that you can use to build Sample.c into a DLL with Microsoft Visual C++; Sample.proj is the equivalent file for building a CFM Library with Metrowerks CodeWarrior. If you use another tool, you can create the makefile.
To build the DLL in Windows:
- In Microsoft Visual C++, choose File > Open Workspace and select Sample.mak.
- Choose Build > Rebuild All.
When the build operation finishes, a file called Sample.dll appears in the folder that contains Sample.mak (or one of its subfolders).
To build the shared library on the Macintosh:
- Open Sample.proj in Metrowerks CodeWarrior.
- Build the project to generate a CFM Library.
When the build operation finishes, a file called Sample appears in the folder that contains Sample.proj (or in one of its subfolders).
To call the computeSum() function from the Insert Horizontal Rule object:
- Create a folder called JSExtensions in the Configuration folder within the application folder.
- Copy Sample.dll (Windows) or Sample (Macintosh) to the JSExtensions folder.
- In a text editor, open the file called horizontal_rule.htm in the Configuration/Objects/Common folder.
- Add the line alert(Sample.computeSum(2,2)); to the objectTag() function so that it appears as shown in the following example:
function objectTag() { // Return the html tag that should be inserted alert(Sample.computeSum(2,2)); return "<HR>"; }
- Save the file and restart .
To execute the computeSum() function:
Choose Insert > Horizontal Rule.
A dialog box that contains the number 4 (the result of computing the sum of 2 plus 2) appears.
1 2
3 4 5
6 7 8
9 10 11
12 13 14
15 16 17
18 19 20
21 22 23
24 25 26
27 28 29
30 31 32
33 34 35
36 37 38
39 40 41
42 43 44
45 46 47
48 49 50
51 52 53
54 55 56
57 58 59
60 61 62
63 64 65
66 67 68
69 70 71
72 73 74
75 76 77
78 79 80
81 82 83
84 85 86
87 88 89
90 91 92
93 94 95
96 97 98
99 100 101
102 103 104
105 106 107
108 109 110
111 112 113
114 115 116
117