|
Implement COM objects in script
Among the variety of powerful things that Groove's ScriptFreeThreaded component can do, one of the more interesting ones is the ability to implement CoCreate'able objects in script. The Groove Platform GDK contains a sample called YourApp10 that shows how to do this, so I will just summarize the main points. Note that if you don't know much about COM or writing IDL, go get this book and read it.
Write IDL for the COM object To be a good citizen to early and late binding clients, you should define dual interfaces for non-event interfaces. You should also have 2 flavors of event interfaces, 1 for early bound clients that derives from IUnknown and 1 for late bound clients that is a dispinterface. You should also define a CoClass to publish the interfaces implemented by the COM object. Note that [in, out] and [out] parameters are not supported for methods.
Define OSD so that the COM object can be CoCreate'd <SOFTPKG NAME="com.yourcompany.xxx.YourCOMObject_GSL" VERSION="1,0,0,0"> <IMPLEMENTATION> <CODEBASE HREF="http://components.yourcompany.com/xxx/YourCOMObject.gsl"/> <g:Install Type="Import To XSS" DatabaseURI="$TEMPLATESURI$" DocumentName="YourCOMObject.gsl" SchemaURI="$DEFAULTSCHEMA$"/> <g:Factory Name="Open" Type="XML Document" DatabaseURI="$TEMPLATESURI$" DocumentName="YourCOMObject.gsl"/> <g:Registry Command="Add" Hive="HKCR" Key="clsid\{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}" Value="" Data="Your COM Object" Type="String"/> <g:Registry Command="Add" Hive="HKCR" Key="clsid\{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}\InprocServer32" Value="" Data="$GROOVEBIN$\GrooveCommonComponents.dll" Type="String"/> <g:Registry Command="Add" Hive="HKCR" Key="clsid\{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}\InprocServer32" Value="ThreadingModel" Data="Both" Type="String"/> <g:Registry Command="Add" Hive="HKCR" Key="clsid\{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}\URL" Value="" Data="http://components.yourcompany.com/xxx/YourCOMObject.osd?Package=com.yourcompany.xxx.YourCOMObject_GSL&amp;Version=1,0&Factory=Open" Type="String"/> <g:Registry Command="Add" Hive="HKCR" Key="YourCOMObjects.YourCOMObjectProgID\CLSID" Value="" Data="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}" Type="String"/> </IMPLEMENTATION> </SOFTPKG>
Create a .gsl file for the COM object This script file should import the type library for your COM object, as well as any other dependent type libraries. You import type libraries by having the following statement:
<TYPELIB LIBID="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFE}" NAME="YourCOMObjectTypeLibrary" MAJORVER="1" MINORVER="0"/> Your script file should implement the interfaces as described by the coclass (at least). You implement interfaces by having the following statement:
<IMPLEMENTS Default="1" IID="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}" LIBID="{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFE}"> Note that the Default attribute should only be used for one of the implemented interfaces, and omitted from all other implemented interface. Also note that to return HRESULT values, you should use the SetCurrentError method.
Global & instance data storage You should not define/use global variables because of performance reasons and the fact that they are not thread safe/accessible. Instead you should use GrooveRunTimeData and/or ScriptSharedObjectTables.
7:59:21 AM
|
|