OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
ocreg.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectComponents
3// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4/// \file
5/// OLE Registration definitions
6//----------------------------------------------------------------------------
7
8#if !defined(OCF_OCREG_H)
9#define OCF_OCREG_H
10
11#include <owl/private/defs.h>
12#if defined(BI_HAS_PRAGMA_ONCE)
13# pragma once
14#endif
15
16#include <owl/pointer.h>
17
18#include <owl/registry.h>
19
20#include <ocf/autodefs.h>
21#include <ocf/appdesc.h> // private for inline implementation only
22
23namespace ocf { class TRegistrar; }
24extern owl::TPointer<ocf::TRegistrar> Registrar; ///< Global registrar object defined by the client application.
25
26namespace ocf {
27
28//
29// Global registration functions for OLE. Most are wrappers for winsys's
30// TRegistry functions
31//
32
33long // returns numeric value of <docflags>
34OcRegisterClass(owl::TRegList& regInfo, // obj holding array of reg parameters
35 owl::TModule* module, // 0 defaults to current task
36 owl::tostream& out, // open ostream to stream reg entries
37 owl::TLangId lang, // language for registration
38 LPCTSTR filter = 0, // internal use to restrict entries
39 owl::TRegItem* defaults = 0,// optional registration default list
40 owl::TRegItem* overrides= 0);// optional registration override list
41
42int // returns error count, 0 if success
43OcUnregisterClass(owl::TRegList& regInfo, // registration table used for register
44 owl::TRegItem* overrides=0); // optional additional regitration item
45
49
53
54int // return: 0=no debug reg, -1=user clsid, 1=default used
55OcSetupDebugReg(owl::TRegList& regInfo, // original registration list
56 owl::TRegItem* regDebug, // temp override list[DebugReplaceCount]
57 owl::TLangId lang, // language for registration
58 LPTSTR clsid); // default temp debug clsid string buf
59
60// !CQ make these local to ocreg ???
61//
62const int DebugRegCount = 4+1; // replacements + room for terminator
63
64extern _TCHAR AppDebugFilter[]; // templates needed for debug app reg
65extern _TCHAR DocDebugFilter[]; // templates needed for debug doc reg
66extern owl::TRegItem OcRegNoDebug[]; // override list to shut off "debugger"
67extern owl::TRegItem OcRegNotDll[]; // override to shut off EXE-only items
68
69//----------------------------------------------------------------------------
70// TRegistrar class
71//
72
73//
74/// Application running mode and registration flags
75/// these are initialized when processing command line or registration requests
76/// the application's copy of the initial option flags is dynamically updated
77//
79 amRegServer = 0x0001, ///< complete registration database update requested
80 amUnregServer = 0x0002, ///< registration database unregistration requested
81 amAutomation = 0x0004, ///< set from cmdline when EXE lauched for automation
82 amEmbedding = 0x0008, ///< cmdline, overridden per Instance if embedded DLL
83 amLangId = 0x0010, ///< user registration requested a particular LangId
84 amTypeLib = 0x0020, ///< requested typelib to be generated and registered
85 amDebug = 0x0040, ///< user requested launching for debugging
86 amNoRegValidate= 0x0080, ///< user request to suppress registry validation
87 amExeModule = 0x0100, ///< set for EXE components, 0 if DLL inproc server
88 amExeMode = 0x0200, ///< may be overridden per instance if running DLL
89 amServedApp = 0x0400, ///< per instance flag, app refcnt held by container
90 amSingleUse = 0x0800, ///< set from app reg, may be forced on per instance
91 amQuietReg = 0x1000, ///< suppress error UI during registration processing
92 amRun = 0x2000, ///< set in factory call to run application msg loop
93 amShutdown = 0x4000, ///< set in factory call to shutdown/delete app
95};
96
97// Factory routine which creates OLE object
98//
99typedef IUnknown* (*TComponentFactory)(IUnknown* outer, owl::uint32 options, owl::uint32 id);
100
101
103
104//
105/// \class TRegistrar
106// ~~~~~ ~~~~~~~~~~
107/// Application registration manager interface class
108//
110 public:
111 TRegistrar(owl::TRegList& regInfo, TComponentFactory callback,
112 owl::tstring& cmdLine,
113 owl::TModule* module = & owl::GetGlobalModule());
114 virtual ~TRegistrar();
115
116 // Create/Expose/Destroy automation object proxies
117 //
118 TUnknown* CreateAutoApp(TObjectDescriptor app, owl::uint32 options,
119 IUnknown* outer=0);
120 void ReleaseAutoApp(TObjectDescriptor app);
121 TUnknown* CreateAutoObject(TObjectDescriptor doc, TServedObject& app,
122 IUnknown* outer=0);
123 TUnknown* CreateAutoObject(const void* obj, const std::type_info& objInfo,
124 const void* app, const std::type_info& appInfo,
125 IUnknown* outer=0);
126
127 virtual void* GetFactory(const GUID& clsid, const GUID& iid);
128 virtual bool CanUnload();
129
130 // Run (run app instance if EXE) and Shutdown
131 //
132 virtual int Run();
133 virtual void Shutdown(IUnknown* releasedObj, owl::uint32 options);
134
135 // Walk linked list of registrars
136 //
137 static TRegistrar* GetNext(TRegistrar* reg);
138
139 // Registration management functions
140 //
141 void RegisterAppClass();
142 void UnregisterAppClass();
143
144 // Command line options accessors
145 //
146 bool IsOptionSet(owl::uint32 option) const;
147 owl::uint32 GetOptions() const;
148 void SetOption(owl::uint32 bit, bool state);
149 void ProcessCmdLine(owl::tstring& cmdLine);
150
151 // Accessor to AppDescriptor object (real workhorse object!)
152 //
153 TAppDescriptor& GetAppDescriptor() {return AppDesc;}
154
155 protected:
156 TRegistrar(TAppDescriptor& appDesc);
158
159 private:
160
161 // Members to maintain linked list of registrar objects
162 //
163 static TRegistrar* RegistrarList;
164 TRegistrar* Next;
165};
166
167//----------------------------------------------------------------------------
168// Factory for automated OLE components, no linking/embedding support
169//
170
171//
172/// Simple factor for COM Servers
173//
174template <class T> class TOcComFactory {
175 public:
176 operator TComponentFactory() {return Create;}
177
178 // Main Create callback function called to create app and/or object
179 //
180 static IUnknown* Create(IUnknown* outer, owl::uint32 options, owl::uint32 id);
181};
182
183/// Main Create callback function called to create COM object
184//
185template <class T> IUnknown*
186TOcComFactory<T>::Create(IUnknown* outer, owl::uint32 /*options*/, owl::uint32 /*id*/)
187{
188 // Create instance of our object
189 //
190 T *objPtr = new T;
191
192 // Set the controlling IUnknown
193 //
194 objPtr->SetOuter(outer);
195
196 // Return IUnknown [operator automatically calls AddRef()]
197 //
198 return objPtr->operator IUnknown*();
199}
200
201//
202/// Simple factory for Automation Server
203//
204template <class T> class TOcAutoFactory {
205 public:
206 operator TComponentFactory() {return Create;}
207
208 // Callouts to allow replacement of individual creation steps
209 //
210 static T* CreateApp(HINSTANCE hInst, owl::uint32 options);
211 static int RunApp(T* app);
212 static void DestroyApp(T* app);
213
214 // Main Create callback function called to create app and/or object
215 //
216 static IUnknown* Create(IUnknown* outer, owl::uint32 options, owl::uint32 id);
217};
218
219//
220/// Called when the app is not found and needs to be created
221//
222template <class T> T*
224{
225 T* app = new T(hInst, options);
226 return app;
227}
228
229//
230/// Called to run the application message loop if an EXE, or DLL in amExeMode
231//
232template <class T> int
234{
235 MSG msg;
236 while(GetMessage(&msg, 0, 0, 0)) {
237 TranslateMessage(&msg);
238 DispatchMessage(&msg);
239 }
240 return 0;
241}
242
243//
244/// Called to destroy the application previously created
245//
246template <class T> void
248{
249 delete app;
250}
251
252//
253/// Main Create callback function called to create app
254//
255template <class T> IUnknown*
256TOcAutoFactory<T>::Create(IUnknown* outer, owl::uint32 options, owl::uint32 /*id*/)
257{
258 static T* exeApp; // used to hold EXE object until OLE factory call
259 T* app;
260 IUnknown* ifc = 0;
261 if (options & amShutdown)
262 return (options & amServedApp) ? 0 : outer;
263 if ((options & amAutomation) && (options & amServedApp)) {
264 app = exeApp; // if EXE, retrieve app created on initial call from main
265 } else {
266 app = CreateApp(owl::GetGlobalModule(), options);
267 }
268 if ((options & amAutomation) && !(options & amServedApp)) {
269 exeApp = app; // if EXE, hold app until factory call when outer known
270 } else {
271 using ::Registrar;
273 ifc = *Registrar->CreateAutoApp(TAutoObjectDelete<T>(app),options,outer);
274 }
275 if (options & amRun) {
276 RunApp(app);
277 DestroyApp(app);
278 } // else DLL server, ifc will be released by controller, which deletes app
279 return ifc;
280}
281
282//----------------------------------------------------------------------------
283
284#if !defined(OCF_APPDESC_H)
285# include <ocf/appdesc.h> // private for inline implementation only
286#endif
287
288//
289//
290//
291inline TUnknown*
293 return AppDesc.CreateAutoApp(app, opts, outer);
294}
295
296//
297//
298//
299inline void
303
304//
305//
306//
307inline TUnknown*
309 IUnknown* outer) {
310 return AppDesc.CreateAutoObject(doc, app, outer);
311}
312
313//
314//
315//
316inline TUnknown*
317TRegistrar::CreateAutoObject(const void* obj, const std::type_info& objInfo,
318 const void* app, const std::type_info& appInfo,
319 IUnknown* outer) {
320 return AppDesc.CreateAutoObject(obj, objInfo, app, appInfo, outer);
321}
322
323//
324//
325//
326inline void
330
331//
332//
333//
334inline void
338
339//
340//
341//
342inline bool
344 return AppDesc.IsOptionSet(option);
345}
346
347//
348//
349//
351 return AppDesc.GetOptions();
352}
353
354//
355//
356//
357inline void TRegistrar::SetOption(owl::uint32 bit, bool state) {
358 AppDesc.SetOption(bit,state);
359}
360
361//
362//
363//
364inline void
368
369} // OCF namespace
370
371#endif // OCF_OCREG_H
TAppDescriptor - OLE application descriptor definitions.
OLE Automation Class Definitions.
#define CHECK(condition)
Definition checks.h:239
void ProcessCmdLine(owl::tstring &cmdLine)
Processes known options on the command line.
Definition appdesc.cpp:977
void SetOption(owl::uint32 bit, bool state)
Definition appdesc.h:75
bool IsOptionSet(owl::uint32 option) const
Definition appdesc.h:73
void RegisterClass()
Register an EXE class object with OLE so that other applications can connect to it.
Definition appdesc.cpp:399
TUnknown * CreateAutoApp(TObjectDescriptor app, owl::uint32 options, IUnknown *outer=0)
Creates a TServedObject helper object which implements an IDispatch implementation on behalf of the '...
Definition appdesc.cpp:162
TUnknown * CreateAutoObject(TObjectDescriptor obj, TServedObject &app, IUnknown *outer=0)
Creates a TServedObject helper which implements IDispatch on behalf of the class described via the 'o...
Definition appdesc.cpp:205
void UnregisterClass()
Invalidates application class registered earlier with 'RegisterClass'.
Definition appdesc.cpp:415
owl::uint32 GetOptions() const
Definition appdesc.h:74
void ReleaseAutoApp(TObjectDescriptor app)
Releases the helper object (TServedObject) implementing IDispatch on behalf of the 'Application' obje...
Definition appdesc.cpp:193
Simple factory for Automation Server.
Definition ocreg.h:204
static IUnknown * Create(IUnknown *outer, owl::uint32 options, owl::uint32 id)
Main Create callback function called to create app.
Definition ocreg.h:256
static T * CreateApp(HINSTANCE hInst, owl::uint32 options)
Called when the app is not found and needs to be created.
Definition ocreg.h:223
static int RunApp(T *app)
Called to run the application message loop if an EXE, or DLL in amExeMode.
Definition ocreg.h:233
static void DestroyApp(T *app)
Called to destroy the application previously created.
Definition ocreg.h:247
Simple factor for COM Servers.
Definition ocreg.h:174
static IUnknown * Create(IUnknown *outer, owl::uint32 options, owl::uint32 id)
Main Create callback function called to create COM object.
Definition ocreg.h:186
Application registration manager interface class.
Definition ocreg.h:109
TUnknown * CreateAutoApp(TObjectDescriptor app, owl::uint32 options, IUnknown *outer=0)
Definition ocreg.h:292
bool IsOptionSet(owl::uint32 option) const
Definition ocreg.h:343
TAppDescriptor & GetAppDescriptor()
Definition ocreg.h:153
void SetOption(owl::uint32 bit, bool state)
Definition ocreg.h:357
void UnregisterAppClass()
Definition ocreg.h:335
void ProcessCmdLine(owl::tstring &cmdLine)
Definition ocreg.h:365
TUnknown * CreateAutoObject(TObjectDescriptor doc, TServedObject &app, IUnknown *outer=0)
Definition ocreg.h:308
owl::uint32 GetOptions() const
Definition ocreg.h:350
void RegisterAppClass()
Definition ocreg.h:327
TAppDescriptor & AppDesc
Definition ocreg.h:157
void ReleaseAutoApp(TObjectDescriptor app)
Definition ocreg.h:300
OLE object exposed for automated access of internal object.
Definition autodefs.h:972
Standard implementation of a controlling IUnknown for an object, to be inherited with other COM inter...
Definition oleutil.h:264
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Smart pointer to a single object. Provides member access operator ->
Definition pointer.h:73
static auto GetClassesRoot() -> TRegKey &
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT).
Definition registry.cpp:32
A registration parameter table, composed of a list of TRegItems.
Definition registry.h:531
static void Update(TRegKey &baseKey, tistream &in)
Writes lines to registry.
static int Validate(TRegKey &baseKey, tistream &in)
Returns number of mismatched entries.
Object Component Framework (COM encapsulation)
Definition appdesc.h:22
int OcRegistryValidate(owl::tistream &in)
Definition ocreg.h:46
const int DebugRegCount
Definition ocreg.h:62
IUnknown *(* TComponentFactory)(IUnknown *outer, owl::uint32 options, owl::uint32 id)
Definition appdesc.h:35
TCHAR DocDebugFilter[]
Definition ocreg.cpp:311
int OcSetupDebugReg(owl::TRegList &regInfo, owl::TRegItem *regDebug, owl::TLangId lang, TCHAR *clsid)
Walk thru a reginfo list using debug entries to create a parallel non-debug set for alternate,...
Definition ocreg.cpp:332
void OcRegistryUpdate(owl::tistream &in)
Definition ocreg.h:50
TCHAR AppDebugFilter[]
Definition ocreg.cpp:310
owl::TRegItem OcRegNotDll[]
Definition ocreg.cpp:305
const GUID & iid
Definition appdesc.h:328
owl::TRegItem OcRegNoDebug[]
Definition ocreg.cpp:304
long OcRegisterClass(owl::TRegList &regInfo, owl::TModule *module, owl::tostream &out, owl::TLangId lang, LPCTSTR filter=0, owl::TRegItem *defaults=0, owl::TRegItem *overrides=0)
Generate OLE registration file image to an output stream.
Definition ocreg.cpp:187
TOcAppMode
Application running mode and registration flags these are initialized when processing command line or...
Definition ocreg.h:78
@ amAutomation
set from cmdline when EXE lauched for automation
Definition ocreg.h:81
@ amAnyRegOption
Definition ocreg.h:94
@ amQuietReg
suppress error UI during registration processing
Definition ocreg.h:91
@ amTypeLib
requested typelib to be generated and registered
Definition ocreg.h:84
@ amRegServer
complete registration database update requested
Definition ocreg.h:79
@ amUnregServer
registration database unregistration requested
Definition ocreg.h:80
@ amShutdown
set in factory call to shutdown/delete app
Definition ocreg.h:93
@ amSingleUse
set from app reg, may be forced on per instance
Definition ocreg.h:90
@ amServedApp
per instance flag, app refcnt held by container
Definition ocreg.h:89
@ amLangId
user registration requested a particular LangId
Definition ocreg.h:83
@ amExeMode
may be overridden per instance if running DLL
Definition ocreg.h:88
@ amExeModule
set for EXE components, 0 if DLL inproc server
Definition ocreg.h:87
@ amDebug
user requested launching for debugging
Definition ocreg.h:85
@ amNoRegValidate
user request to suppress registry validation
Definition ocreg.h:86
@ amEmbedding
cmdline, overridden per Instance if embedded DLL
Definition ocreg.h:82
@ amRun
set in factory call to run application msg loop
Definition ocreg.h:92
class _ICLASS TAppDescriptor
Definition autodefs.h:47
int OcUnregisterClass(owl::TRegList &regInfo, owl::TRegItem *overrides=0)
Unregister application or class from registration database.
Definition ocreg.cpp:282
unsigned long uint32
Definition number.h:34
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition lclstrng.h:26
std::istream tistream
Definition strmdefs.h:39
std::string tstring
Definition defs.h:79
TModule & GetGlobalModule()
Definition global.cpp:48
std::ostream tostream
Definition strmdefs.h:40
owl::TPointer< ocf::TRegistrar > Registrar
Global registrar object defined by the client application.
#define _ICLASS
Definition oleutil.h:25
Various types of smart pointer templatized classes.
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...
A single registration list entry.
Definition registry.h:508