Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C

COM in plain C, Part 7

Rate me:
Please Sign up or sign in to vote.
5.00/5 (15 votes)
8 Aug 2006CPOL13 min read 93.3K   2K   83  
An ActiveX Script Host with custom COM objects. This allows a script to call C functions in your app.
<HTML><HEAD><TITLE>COM in C</TITLE></HEAD><BODY BGCOLOR=WHITE TEXT=BLACK LINK=BLUE VLINK=BLUE ALINK=RED><FONT SIZE=3>
<PRE><FONT COLOR=GREEN><B>Chapter 1
A component for C/C++ clients</B></FONT>
<A HREF="ComInC1.html#INTRO" TARGET=Frame2>Introduction</A>
<A HREF="ComInC1.html#VTABLE" TARGET=Frame2>A COM object and its VTable</A>
<A HREF="ComInC1.html#GUID" TARGET=Frame2>A GUID</A>
<A HREF="ComInC1.html#FUNCS" TARGET=Frame2>QueryInterface(), AddRef(), and Release()</A>
<A HREF="ComInC1.html#CLASS" TARGET=Frame2>An IClassFactory object</A>
<A HREF="ComInC1.html#DLL" TARGET=Frame2>Packaging into a DLL</A>
<A HREF="ComInC1.html#H" TARGET=Frame2>Our C++/C include file</A>
<A HREF="ComInC1.html#DEF" TARGET=Frame2>The Definition (DEF) file</A>
<A HREF="ComInC1.html#REG" TARGET=Frame2>Install the DLL, and register the object</A>
<A HREF="ComInC1.html#C" TARGET=Frame2>An example C program</A>
<A HREF="ComInC1.html#CPLUS" TARGET=Frame2>An example C++ program</A>
<A HREF="ComInC1.html#MOD" TARGET=Frame2>Modifying the code</A>

<PRE><FONT COLOR=GREEN><B>Chapter 2
A component for scripting clients</B></FONT>
<P><A HREF="ComInC2.html#WHY" TARGET=Frame2>Why script languages can't use our DLL as is</A>
<BR><A HREF="ComInC2.html#TYPE" TARGET=Frame2>Automation datatypes (ie, BSTR, VARIANT)</A>
<BR><A HREF="ComInC2.html#DISPATCH" TARGET=Frame2>The IDispatch functions</A>
<BR><A HREF="ComInC2.html#LIB" TARGET=Frame2>The type library</A>
<BR><A HREF="ComInC2.html#REG" TARGET=Frame2>Registering the type library</A>
<BR><A HREF="ComInC2.html#VB" TARGET=Frame2>A VBscript example</A>
<BR><A HREF="ComInC2.html#PROP" TARGET=Frame2>A Property</A>
<BR><A HREF="ComInC2.html#C" TARGET=Frame2>An updated example C application</A>
<BR><A HREF="ComInC2.html#EXE" TARGET=Frame2>Packaging the component into an EXE</A>

<PRE><FONT COLOR=GREEN><B>Chapter 3
Collections</B></FONT>
<P><A HREF="ComInC3.html" TARGET=Frame2>A list</A>
<A HREF="ComInC3.html#DEFINE" TARGET=Frame2>Defining a collection object</A>
<BR><A HREF="ComInC3.html#BOOK" TARGET=Frame2>Some helper functions</A>
<BR><A HREF="ComInC3.html#COLLECT" TARGET=Frame2>Our collection object's functions</A>
<BR><A HREF="ComInC3.html#HOW" TARGET=Frame2>How an application obtains our collection object</A>
<BR><A HREF="ComInC3.html#VB1" TARGET=Frame2>A VBscript example</A>
<BR><A HREF="ComInC3.html#C1" TARGET=Frame2>A C example</A>
<BR><A HREF="ComInC3.html#ENUM" TARGET=Frame2>An IEnumVARIANT object</A>
<BR><A HREF="ComInC3.html#VB2" TARGET=Frame2>Another VBscript example</A>
<BR><A HREF="ComInC3.html#C2" TARGET=Frame2>Another C example</A>
<BR><A HREF="ComInC3.html#GENERIC" TARGET=Frame2>A more generic approach</A>
<BR><A HREF="ComInC3.html#ADD" TARGET=Frame2>Add/Remove items</A>

<PRE><FONT COLOR=GREEN><B>Chapter 4
Multiple interfaces, and delegation</B></FONT>
<P><A HREF="ComInC4.html" TARGET=Frame2>Multiple interfaces</A>
<BR><A HREF="ComInC4.html#EMBED" TARGET=Frame2>Embedding sub-objects in our object</A>
<BR><A HREF="ComInC4.html#BASE" TARGET=Frame2>How an app obtains the base object</A>
<BR><A HREF="ComInC4.html#SUB" TARGET=Frame2>How an app obtains a sub object from the base object</A>
<BR><A HREF="ComInC4.html#SUB2" TARGET=Frame2>How an app obtains an object from another sub-object</A>
<BR><A HREF="ComInC4.html#DELE" TARGET=Frame2>Delegation</A>
<BR><A HREF="ComInC4.html#UNK1" TARGET=Frame2>QueryInterface, AddRef, and Release of our base object</A>
<BR><A HREF="ComInC4.html#UNK2" TARGET=Frame2>QueryInterface, AddRef, and Release of our sub-objects</A>
<BR><A HREF="ComInC4.html#ADD" TARGET=Frame2>Another way to add a sub-object to our object</A>
<BR><A HREF="ComInC4.html#DLL" TARGET=Frame2>An example object with multiple interfaces</A>
<BR><A HREF="ComInC4.html#EXAM" TARGET=Frame2>An example C app that uses our object</A>
<BR><A HREF="ComInC4.html#LIMIT" TARGET=Frame2>Scripting limitations</A>

<PRE><FONT COLOR=GREEN><B>Chapter 5
Event source/sink (Connectable objects)</B></FONT>
<P><A HREF="ComInC5.html" TARGET=Frame2>Callback functions</A>
<BR><A HREF="ComInC5.html#WRAP" TARGET=Frame2>Wrapping a callback function in a COM object</A>
<BR><A HREF="ComInC5.html#CONNECT" TARGET=Frame2>IConnectionPointContainer and IConnectionPoint objects</A>
<BR><A HREF="ComInC5.html#C1" TARGET=Frame2>An example C app</A>
<BR><A HREF="ComInC5.html#SCRIPT" TARGET=Frame2>Adding support for script languages</A>
<BR><A HREF="ComInC5.html#C2" TARGET=Frame2>Another example C app</A>
<BR><A HREF="ComInC5.html#VB" TARGET=Frame2>A VBscript example</A>
<BR><A HREF="ComInC5.html#MULT" TARGET=Frame2>Multiple types of callback objects</A>
<BR><A HREF="ComInC5.html#MULT2" TARGET=Frame2>Multiple callback objects</A>

<PRE><FONT COLOR=GREEN><B>Chapter 6
An ActiveX Script Host</B></FONT>
<P><A HREF="ComInC6.html#INTRO" TARGET=Frame2>Introduction</A>
<BR><A HREF="ComInC6.html#GUID" TARGET=Frame2>Choosing/opening an engine</A>
<BR><A HREF="ComInC6.html#HOST" TARGET=Frame2>Our IActiveScriptSite object</A>
<BR><A HREF="ComInC6.html#SCRIPT" TARGET=Frame2>An example VBscript</A>
<BR><A HREF="ComInC6.html#INIT" TARGET=Frame2>Initializing the engine</A>
<BR><A HREF="ComInC6.html#ADD" TARGET=Frame2>Adding a script to the engine</A>
<BR><A HREF="ComInC6.html#RUN" TARGET=Frame2>Running scripts</A>
<BR><A HREF="ComInC6.html#CLOSE" TARGET=Frame2>Closing an engine</A>
<BR><A HREF="ComInC6.html#LOAD" TARGET=Frame2>Loading a script</A>
<BR><A HREF="ComInC6.html#ENUM" TARGET=Frame2>Enumerating installed engines</A>
<BR><A HREF="ComInC6.html#THREAD" TARGET=Frame2>Running a script in another thread</A>

<PRE><FONT COLOR=GREEN><B>Chapter 7
A Script Host's custom objects</B></FONT>
<P><A HREF="ComInC7.html#DECLARE" TARGET=Frame2>Declaring our custom COM object</A>
<BR><A HREF="ComInC7.html#IDL" TARGET=Frame2>Our IDL file and type library</A>
<BR><A HREF="ComInC7.html#REG" TARGET=Frame2>Register our COM object with the engine</A>
<BR><A HREF="ComInC7.html#HOW" TARGET=Frame2>How a script calls our COM object functions</A>
<BR><A HREF="ComInC7.html#MULTI" TARGET=Frame2>Our IProvideMultipleClassInfo object</A>
<BR><A HREF="ComInC7.html#APP" TARGET=Frame2>Application and document objects</A>
<BR><A HREF="ComInC7.html#C" TARGET=Frame2>A C++ example host</A>
</PRE></FONT></BODY></HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions