summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Jezabek <jezabek@poczta.onet.pl>2008-08-16 15:38:22 +0000
committerJan Jezabek <jezabek@poczta.onet.pl>2008-08-16 15:38:22 +0000
commit89f04f678347db150272e4fcb52b400063e0a55c (patch)
tree757a3445eb418171fb81300ee8b58da04d4d7332
parent4bdd67e89fbd19941cd6b60bdafd67a23917d5c3 (diff)
downloadswig-89f04f678347db150272e4fcb52b400063e0a55c.tar.gz
Added 'simple' example.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-jezabek@10769 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--Examples/Makefile.in4
-rw-r--r--Examples/com/check.list1
-rw-r--r--Examples/com/simple/Makefile17
-rw-r--r--Examples/com/simple/example.c18
-rw-r--r--Examples/com/simple/example.i7
-rw-r--r--Examples/com/simple/index.html126
-rw-r--r--Examples/com/simple/runme.vbs23
7 files changed, 194 insertions, 2 deletions
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index 4cd3f3d0d..be4a4152c 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1123,13 +1123,13 @@ com: $(SRCS)
$(COMPILETOOL) $(COM_RC) $(COM_RC_OUT_SWITCHES)$(COM_RES_FILE) $(COM_RC_IN_SWITCHES) $(COM_RC_FILE)
$(COMPILETOOL) $(COM_CC) $(COM_CC_SHARED_SWITCHES) $(COM_CC_OUT_SWITCHES)$(TARGET).dll$(COM_EXEC_SUFFIX) $(SRCS) $(ISRCS) $(COM_RES_FILE) $(COM_DEF_FILE) $(COM_LIBS) $(INCLUDES)
-com_cpp: $(SRCS)
+com_cpp: $(SRCS) $(CXXSRCS)
$(SWIG) -com -c++ $(SWIGOPT) $(INTERFACE)
$(COMPILETOOL) $(COM_IDL) $(COM_IDL_COMMON_SWITCHES) $(COM_IDL_TLB_SWITCHES) $(COM_TLB_FILE) $(COM_IDL_FILE)
$(COMPILETOOL) $(COM_RC) $(COM_RC_OUT_SWITCHES)$(COM_RES_FILE) $(COM_RC_IN_SWITCHES) $(COM_RC_FILE)
$(COMPILETOOL) $(COM_CXX) $(COM_CXX_SHARED_SWITCHES) $(COM_CXX_OUT_SWITCHES)$(TARGET).dll$(COM_EXEC_SUFFIX) $(SRCS) $(CXXSRCS) $(ICXXSRCS) $(COM_RES_FILE) $(COM_DEF_FILE) $(COM_LIBS) $(INCLUDES)
-com_compile: $(SRCS)
+com_compile: $(COMSRCS)
$(COMPILETOOL) $(COM_CC) $(COM_CC_SWITCHES) $(COM_CC_OUT_SWITCHES)$(TARGET)$(COM_EXEC_SUFFIX) $(COMSRCS) $(COM_LIBS)
com_clean:
diff --git a/Examples/com/check.list b/Examples/com/check.list
index f9b363696..69d56a4f6 100644
--- a/Examples/com/check.list
+++ b/Examples/com/check.list
@@ -1,2 +1,3 @@
# see top-level Makefile.in
class
+simple
diff --git a/Examples/com/simple/Makefile b/Examples/com/simple/Makefile
new file mode 100644
index 000000000..b934e315e
--- /dev/null
+++ b/Examples/com/simple/Makefile
@@ -0,0 +1,17 @@
+TOP = ../..
+SWIG = $(TOP)/../preinst-swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+SWIGOPT =
+
+all:: com
+
+com::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' com
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile com_clean
+
+check: all
diff --git a/Examples/com/simple/example.c b/Examples/com/simple/example.c
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/com/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/com/simple/example.i b/Examples/com/simple/example.i
new file mode 100644
index 000000000..24093b9bf
--- /dev/null
+++ b/Examples/com/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%}
diff --git a/Examples/com/simple/index.html b/Examples/com/simple/index.html
new file mode 100644
index 000000000..8e4bbde9c
--- /dev/null
+++ b/Examples/com/simple/index.html
@@ -0,0 +1,126 @@
+<html>
+<head>
+<title>SWIG:Examples:com:simple</title>
+</head>
+
+<body bgcolor="#ffffff">
+
+
+<tt>SWIG/Examples/com/simple/</tt>
+<hr>
+
+<H2>Simple COM Example</H2>
+
+<p>
+This example illustrates how you can hook a COM client to a very simple C program containing
+a function and a global variable.
+
+<h2>The C Code</h2>
+
+Suppose you have the following C code:
+
+<blockquote>
+<pre>
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x &gt; 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+</pre>
+</blockquote>
+
+<h2>The SWIG interface</h2>
+
+Here is a simple SWIG interface file:
+
+<blockquote>
+<pre>
+/* File: example.i */
+%module example
+
+extern int gcd(int x, int y);
+extern double Foo;
+</pre>
+</blockquote>
+
+<h2>Compilation</h2>
+
+<ol>
+<li><tt>swig -com <a href="example.i">example.i</a></tt>
+<p>
+<li>To create the COM DLL you will need to compile the <tt>example.idl</tt>
+file using an IDL compiler, then compile the resource file
+<tt>example_rc.rc</tt> and finally create a DLL from
+<tt>example_wrap.c</tt>, <tt><a href="example.c">example.c</a></tt>,
+<tt>example.def</tt> and <tt>example_rc.res</tt>. In Visual C++ this
+is accomplished by executing the following commands:
+
+<blockquote>
+<pre>
+midl example.idl
+rc example_rc.rc
+cl /LD example.c example_wrap.c example.def example_rc.res ole32.lib uuid.lib advapi32.lib oleaut32.lib
+</pre>
+</blockquote>
+
+Before using the COM DLL you will also need to register it using
+<tt>regsvr32</tt>
+
+<blockquote>
+<pre>
+regsvr32 example.dll
+</pre>
+</blockquote>
+
+Please consult the SWIG documentation for further details.
+</ol>
+
+<h2>Using the extension</h2>
+
+Click <a href="runme.vbs">here</a> to see a program that calls our C functions from VBScript using COM.
+
+<h2>Key points</h2>
+
+<ul>
+<li>To access global variables and functions you need to create an object
+of the module class. In VBScript this is done in the following way:
+
+<blockquote>
+<pre>
+Dim example
+Set example = CreateObject("example.example")
+</pre>
+</blockquote>
+
+<li>C functions are mapped to member functions of the module class. For example:
+<blockquote>
+<pre>
+Dim g
+g = example.gcd(42,105)
+</pre>
+</blockquote>
+
+<li>C global variables are accessed as properties of the module class. For example:
+<blockquote>
+<pre>
+Dim a
+a = example.foo
+example.foo = 20.0
+</pre>
+</blockquote>
+</ul>
+
+<hr>
+</body>
+</html>
diff --git a/Examples/com/simple/runme.vbs b/Examples/com/simple/runme.vbs
new file mode 100644
index 000000000..996e8012e
--- /dev/null
+++ b/Examples/com/simple/runme.vbs
@@ -0,0 +1,23 @@
+Dim example, x, y, g
+
+Rem Get an instance of the module class
+Set example = CreateObject("example.example")
+
+Rem Call our gcd() function
+x = 42
+y = 105
+g = example.gcd(x,y)
+
+WScript.Echo "The gcd of " & x & " and " & y & " is " & g
+
+Rem Manipulate the Foo global variable
+
+Rem Output its current value
+WScript.Echo "Foo = " & example.foo
+
+Rem Change its value
+example.foo = 3.1415926
+
+Rem See if the change took effect
+WScript.Echo "Foo = " & example.foo
+