OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
typelib.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectComponents
3// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4/// \file
5/// TServedObject implementation and OLE Type library generation
6//----------------------------------------------------------------------------
7#include <ocf/pch.h>
8#include <ocf/appdesc.h>
9#include <ocf/occtrl.h>
10#include <owl/filename.h>
11
12#define OLE_TYPELIB_FILE L"stdole32.tlb"
13
14namespace ocf {
15
16using namespace owl;
17
18//____________________________________________________________________________
19//
20// TypeLibrary generation
21//____________________________________________________________________________
22
23/// local class to hold ICreateTypeLib interface pointers for each class
24
25struct TOleCreateInfo {
26 int FuncCount;
27 int VarCount;
28 int ImplCount;
29 TYPEKIND TypeKind;
30 ITypeInfo* OurTypeInfo; // our type info implementation
31 ITypeInfo* OleTypeInfo; // type info obtained from ICreatTypeInfo
32 ICreateTypeInfo* CreateInfo; // interface obtained from ICreateTypeLib
33 TOleCreateInfo() : OurTypeInfo(0), OleTypeInfo(0), CreateInfo(0) {}
34 ~TOleCreateInfo();
35};
36
37TOleCreateInfo::~TOleCreateInfo()
38{
39 if (OurTypeInfo)
40 OurTypeInfo->Release();
41 if (OleTypeInfo)
42 OleTypeInfo->Release();
43 if (CreateInfo)
44 CreateInfo->Release();
45}
46
47struct TOleCreateList {
48 int Count;
49 ITypeLib* TypeLib;
50 LPCTSTR FileName;
51 TOleCreateInfo* List;
52 ITypeLib* OleLib;
53 ITypeComp* OleComp;
54 ITypeInfo* OleInfo;
55 ICreateTypeLib* CreateLib;
56 TLIBATTR * LibAttr;
57 TYPEATTR * TypeAttr;
58 ITypeInfo* AttrTypeInfo; // valid only when TypeAttr!=0, not refcnt'd
59 TBSTR* FuncNames; // temporary transfer of BSTR name arrays
60
61 TOleCreateList(ITypeLib* typeLib, LPCTSTR fileName);
62 void FixupTypeDescRef(int typeIndex, TYPEDESC & typeDesc);
63 void Close(LPCTSTR helpDir);
64 void Clear();
65 ~TOleCreateList() {Clear();}
66};
67
68TOleCreateList::TOleCreateList(ITypeLib* typeLib, LPCTSTR fileName)
69:
70 TypeLib(typeLib),
71 FileName(fileName),
72 OleLib(0), OleComp(0), OleInfo(0),
73 CreateLib(0), TypeAttr(0), LibAttr(0), List(0), FuncNames(0)
74{
75 TBSTR libName;
76 TBSTR libDoc;
77 TBSTR helpFile;
78 ulong helpId;
79 TypeLib->AddRef();
80 OLECALL(::LoadTypeLib(OLE_TYPELIB_FILE, &OleLib), _T("Load stdole.tlb"));
81 OLECALL(OleLib->GetTypeComp(&OleComp), _T("GetTypeComp"));
82 ITypeComp* tempComp; // required as reference arg, but always set to 0
83 OLECALL(
84 OleComp->BindType(
85 const_cast<LPOLESTR>(OleText("IDispatch")),
86 ::LHashValOfName(0, OleText("IDispatch")),
87 &OleInfo,
88 &tempComp
89 ),
90 _T("BindType"));
91 OLECALL(TypeLib->GetLibAttr(&LibAttr), _T("GetLibAttr"));
92 OLECALL(TypeLib->GetDocumentation(-1, libName, libDoc, &helpId, helpFile),
93 _T("GetDocumentation for library"));
94 OLECALL(::CreateTypeLib(LibAttr->syskind, OleStr((LPTSTR)FileName), &CreateLib), _T("CreateTypeLib"));
95 OLECALL(CreateLib->SetGuid(LibAttr->guid), _T("Set TypeLib GUID"));
96 OLECALL(CreateLib->SetLcid(LibAttr->lcid), _T("Set TypeLib language"));
97 OLECALL(CreateLib->SetLibFlags(LibAttr->wLibFlags), _T("Set TypeLib flags"));
98 if (!!libName)
99 OLECALL(CreateLib->SetName(libName), _T("Set TypeLib name"));
100 if (!!libDoc)
101 OLECALL(CreateLib->SetDocString(libDoc), _T("Set TypeLib doc"));
102 if (!!helpFile)
103 {
104 OLECALL(CreateLib->SetHelpFileName(helpFile), _T("SetHelpFileName"));
105 OLECALL(CreateLib->SetHelpContext(helpId), _T("HelpContext"));
106 }
107 OLECALL(CreateLib->SetVersion(LibAttr->wMajorVerNum,
108 LibAttr->wMinorVerNum), _T("Set TypeLib version"));
109 // allocate all ITypeInfo's upfront to force consistent references
110 Count = TypeLib->GetTypeInfoCount();
111 List = new TOleCreateInfo[Count];
112 for (int nInfo = 0; nInfo < Count; nInfo++) {
113 TOleCreateInfo& info = List[nInfo];
114 ICreateTypeInfo* newInfo;
115 OLECALL(TypeLib->GetTypeInfo(nInfo, &AttrTypeInfo), _T("GetTypeInfo"));
116 info.OurTypeInfo = AttrTypeInfo;
117 OLECALL(info.OurTypeInfo->GetTypeAttr(&TypeAttr), _T("GetTypeAttr"));
118 OLECALL(TypeLib->GetDocumentation(nInfo,libName,libDoc,&helpId,helpFile),
119 _T("GetDocumentation for TypeInfo"));
120 OLECALL(CreateLib->CreateTypeInfo(libName, TypeAttr->typekind, &newInfo),
121 _T("Create CreateTypeInfo"));
122 info.CreateInfo = newInfo;
123 OLECALL(newInfo->QueryInterface(IID_ITypeInfo,
124 (void **)&info.OleTypeInfo), _T("QueryInterface for ITypeInfo"));
125 if (!!libDoc)
126 OLECALL(newInfo->SetDocString(libDoc), _T("Set TypeInfo doc"));
127 OLECALL(newInfo->SetHelpContext(helpId), _T("SetHelpContext"));
128 OLECALL(newInfo->SetVersion(TypeAttr->wMajorVerNum,
129 TypeAttr->wMinorVerNum),_T("Set TypeInfo version"));
130 OLECALL(newInfo->SetGuid(TypeAttr->guid), _T("SetTypeInfo GUID"));
131 OLECALL(newInfo->SetTypeFlags(TypeAttr->wTypeFlags), _T("SetTypeFlags"));
132 if (TypeAttr->typekind == TKIND_DISPATCH) {
133 HREFTYPE hreftype;
134 OLECALL(newInfo->AddRefTypeInfo(OleInfo, &hreftype), _T("AddRefTypeInfo"));
135 OLECALL(newInfo->AddImplType(0, hreftype), _T("AddImplType"));
136 }
137 info.TypeKind = TypeAttr->typekind;
138 info.FuncCount = TypeAttr->cFuncs;
139 info.VarCount = TypeAttr->cVars;
140 info.ImplCount = TypeAttr->cImplTypes;
141 info.OurTypeInfo->ReleaseTypeAttr(TypeAttr), TypeAttr = 0;
142 }
143}
144
145void TOleCreateList::Close(LPCTSTR helpDir)
146{
147 OLECALL(CreateLib->SaveAllChanges(), _T("Write and close TypeLib file"));
148 CreateLib->Release();
149 CreateLib = 0;
150 OLECALL(::RegisterTypeLib(TypeLib,
151 OleStr((LPTSTR)FileName),
152 OleStr((LPTSTR)helpDir)),
153 _T("Register type library"));
154}
155
156void TOleCreateList::Clear()
157{
158 delete[] List; // releases all interface pointers
159 delete[] FuncNames; // in case exception thrown while in use
160 if (LibAttr)
161 TypeLib->ReleaseTLibAttr(LibAttr);
162 if (TypeAttr)
163 AttrTypeInfo->ReleaseTypeAttr(TypeAttr);
164 if (OleInfo)
165 OleInfo->Release();
166 if (OleComp)
167 OleComp->Release();
168 if (OleLib)
169 OleLib->Release();
170 if (CreateLib)
171 CreateLib->Release();
172 TypeLib->Release(); // finally release typelib called at constructor
173}
174
175void
176TOleCreateList::FixupTypeDescRef(int typeIndex, TYPEDESC & typeDesc)
177{
178 if (typeDesc.vt == VT_USERDEFINED) {
179 ITypeInfo* refInfo;
180 OLECALL(List[typeIndex].OurTypeInfo->GetRefTypeInfo(typeDesc.hreftype,
181 &refInfo), _T("GetRefTypeInfo"));
182 refInfo->Release(); // ok to release here, we're only using its pointer
183 for (int nInfo = 0; nInfo < Count; nInfo++) {
184 if (List[nInfo].OurTypeInfo == refInfo) {
185 OLECALL(List[typeIndex].CreateInfo->AddRefTypeInfo(List[nInfo].OleTypeInfo,
186 &typeDesc.hreftype), _T("AddRefTypeInfo"));
187 return;
188 }
189 }
190 OLECALL(HR_TYPE_ELEMENTNOTFOUND, _T("Unknown reference type"));
191 }
192}
193
194void
196{
197 TServedObject* servedObject;
198 TBSTR libName;
199 TBSTR libDoc;
200 ulong helpId;
201 FUNCDESC * funcDesc = 0;
202 VARDESC * varDesc = 0;
203 TOleCreateList typeList(new TTypeLibrary(*this, lang), file);
204 for (int nInfo = 0; nInfo < typeList.Count; nInfo++) {
205 TOleCreateInfo& curInfo = typeList.List[nInfo];
206 ITypeInfo* typeInfo = curInfo.OurTypeInfo;
207 ICreateTypeInfo* newInfo = curInfo.CreateInfo;
208 int index;
209 for (index = 0; index < curInfo.FuncCount; index++) {
210 OLECALL(typeInfo->GetFuncDesc(index, &funcDesc), _T("GetFuncDesc"));
211 // Using the GetDocumentation call fails when creating a typelib, so attempt to
212 // use the function GetFuncDocFromIndex to get around this problem
213 servedObject = dynamic_cast<TServedObject*>(typeInfo);
214 if (servedObject)
215 OLECALL(servedObject->GetFuncDocFromIndex(index, libName, libDoc,
216 &helpId, 0), _T("Get method name and doc"));
217 else
218 OLECALL(typeInfo->GetDocumentation(funcDesc->memid, libName, libDoc,
219 &helpId, 0), _T("Get method name and doc"));
220 for (int nArg = funcDesc->cParams; nArg-- >=0; ) {
221 ELEMDESC * elem = nArg < 0 ? &funcDesc->elemdescFunc
222 : &funcDesc->lprgelemdescParam[nArg];
223 typeList.FixupTypeDescRef(nInfo, elem->tdesc);
224 }
225 OLECALL(newInfo->AddFuncDesc(index, funcDesc), _T("AddFuncDesc"));
226 unsigned nNames = funcDesc->cParams + 1;
227 typeList.FuncNames = new TBSTR[nNames];
228 OLECALL(typeInfo->GetNames(funcDesc->memid, (BSTR*)typeList.FuncNames,
229 nNames, &nNames), _T("Get method parameter names"));
230 OLECALL(newInfo->SetFuncAndParamNames(index, (BSTR*)typeList.FuncNames,
231 nNames), _T("Set method parameter names"));
232 delete[] typeList.FuncNames;
233 typeList.FuncNames = 0;
234 if (!!libDoc)
235 OLECALL(newInfo->SetFuncDocString(index, libDoc),_T("Set method doc"));
236 OLECALL(newInfo->SetFuncHelpContext(index, helpId), _T("HelpContext"));
237 typeInfo->ReleaseFuncDesc(funcDesc), funcDesc = 0;
238 }
239 for (index = 0; index < curInfo.VarCount; index++) {
240 OLECALL(typeInfo->GetVarDesc(index, &varDesc), _T("GetVarDesc"));
241 // Using the GetDocumentation call fails when creating a typelib, so attempt to
242 // use the function GetVarDocFromIndex to get around this problem
243 servedObject = dynamic_cast<TServedObject*>(typeInfo);
244 if (servedObject)
245 OLECALL(servedObject->GetVarDocFromIndex(index, libName, libDoc,
246 &helpId, 0), _T("Get propery name and doc"));
247 else
248 OLECALL(typeInfo->GetDocumentation(varDesc->memid, libName, libDoc,
249 &helpId, 0), _T("Get propery name and doc"));
250 typeList.FixupTypeDescRef(nInfo, varDesc->elemdescVar.tdesc);
251 OLECALL(newInfo->AddVarDesc(index, varDesc), _T("AddVarDesc"));
252 OLECALL(newInfo->SetVarName(index, libName),_T("Set property name"));
253 if (!!libDoc)
254 OLECALL(newInfo->SetVarDocString(index, libDoc),_T("Set property doc"));
255 OLECALL(newInfo->SetVarHelpContext(index, helpId), _T("HelpContext"));
256 typeInfo->ReleaseVarDesc(varDesc), varDesc = 0;
257 }
258 if (curInfo.TypeKind == TKIND_COCLASS) {
259 for (index = 0; index < curInfo.ImplCount; index++) {
260 HREFTYPE hreftype;
261 ITypeInfo* refInfo;
262 OLECALL(typeInfo->GetRefTypeOfImplType(index, &hreftype),_T("GetCoClassRef"));
263 OLECALL(typeInfo->GetRefTypeInfo(hreftype, &refInfo), _T("GetCoClassTypeInfo"));
264 refInfo->Release(); // ok to release here, only using its pointer
265 for (int iInfo = 0; iInfo < typeList.Count; iInfo++) {
266 if (typeList.List[iInfo].OurTypeInfo == refInfo) {
267 OLECALL(newInfo->AddRefTypeInfo(typeList.List[iInfo].OleTypeInfo, &hreftype), _T("AddRefTypeInfo"));
268 OLECALL(newInfo->AddImplType(index, hreftype), _T("AddImplType"));
269 int implflags;
270 OLECALL(typeInfo->GetImplTypeFlags(index, &implflags), _T("GetImplTypeFlags"));
271 OLECALL(newInfo->SetImplTypeFlags(index, implflags), _T("SetImplTypeFlags"));
272 }
273 }
274 }
275 }
276 OLECALL(newInfo->LayOut(), _T("Layout typeinfo"));
277 }
278 const auto regHelpDir = RegInfo.Lookup("helpdir"); // may be null
279 tstring helpDir = regHelpDir ? regHelpDir : _T("");
280 if (helpDir.empty()){
281 _TCHAR path [_MAX_PATH];
282 Module->GetModuleFileName(path, sizeof(path));
284 }
285 typeList.Close(helpDir.c_str());
286
287 int iGuid = 0; // first pass for app, second for debug app if present
288 do {
289 _TCHAR buf[80];
290 _tcscpy(buf, _T("CLSID\\"));
291 _tcscat(buf, AppClassId[iGuid]);
292 _tcscat(buf, _T("\\TypeLib"));
293 TRegKey::GetClassesRoot().SetValue(buf,REG_SZ, (uint8*)(LPCTSTR)AppClassId[LibGuidOffset], 0);
294 iGuid ^= DebugGuidOffset; // remains 0 if no debug guid assigned
295 } while (iGuid);
296}
297
298//____________________________________________________________________________
299//
300// TTypeLibrary implementation
301//____________________________________________________________________________
302
304 : AppDesc(appDesc), Lang(lang), RefCnt(0)
305{
306 CoClassFlags = 0;
307 CoClassImplCount = 0;
308 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
309 for (int index = 0; index < AppDesc.ClassCount; index++, ref++) {
310 TAutoClass* cls = ref->Class;
311 int implFlags = cls->GetImplTypeFlags();
312 uint16 typeFlags = cls->GetCoClassFlags();
313 if (implFlags != 0 || typeFlags != 0) {
314 CoClassImplCount++;
315 CoClassFlags |= typeFlags;
316 }
317 }
318}
319
321{
322 if (AppDesc.TypeLib == this)
323 AppDesc.TypeLib = 0; // remove pointer to this
324 if (RefCnt > 0)
325 ::CoDisconnectObject(this,0); // should not normally happen
326}
327
330{
331 ITypeInfo* ifc = new TCoClassInfo(AppDesc, CoClassFlags, CoClassImplCount);
332 ifc->AddRef();
333 return ifc;
334}
335
336HRESULT _IFUNC
337TTypeLibrary::QueryInterface(const IID & riid, void * * retIface)
338{
339 if (riid == IID_IUnknown || riid == IID_ITypeLib) {
340 AddRef();
341 *retIface = (IUnknown*)this;
342 return HR_NOERROR;
343 }
344 *retIface = 0;
345 return HR_NOINTERFACE;
346}
347
348unsigned long _IFUNC
349
350TTypeLibrary::AddRef()
351{
352 return ++RefCnt;
353}
354
355unsigned long _IFUNC
356TTypeLibrary::Release()
357{
358 if (--RefCnt != 0)
359 return RefCnt;
360 delete this;
361 return 0;
362}
363
364unsigned int _IFUNC
365TTypeLibrary::GetTypeInfoCount()
366{
367 return AppDesc.GetClassCount() + (CoClassImplCount > 0); // +1 for CoClass
368}
369
370HRESULT _IFUNC
371TTypeLibrary::GetTypeInfo(unsigned index, ITypeInfo* * retInfo)
372{
373 if (CoClassImplCount > 0 && index == (uint)AppDesc.GetClassCount()) {
374 *retInfo = CreateCoClassInfo();
375 }
376 else {
377 TAutoClass* cls = AppDesc.GetAutoClass(index);
378 if (!cls)
380 *retInfo = AppDesc.CreateITypeInfo(*cls);
381 }
382 return HR_NOERROR;
383}
384
385HRESULT _IFUNC
386TTypeLibrary::GetTypeInfoType(unsigned index, TYPEKIND * retKind)
387{
388 unsigned int count = AppDesc.GetClassCount();
389 if (index > count)
391 *retKind = (index == count ? TKIND_COCLASS : TKIND_DISPATCH);
392 return HR_NOERROR;
393}
394
395HRESULT _IFUNC
396TTypeLibrary::GetTypeInfoOfGuid(const GUID & guid, ITypeInfo* * retInfo)
397{
398 if (AppDesc.AppClassId.GetOffset(guid) == 0) {
399 *retInfo = CreateCoClassInfo();
400 } else {
401 TAutoClass* cls = AppDesc.GetAutoClass(guid);
402 if (!cls)
404 *retInfo = AppDesc.CreateITypeInfo(*cls);
405 }
406 return HR_NOERROR;
407}
408
409HRESULT _IFUNC
410TTypeLibrary::GetLibAttr(TLIBATTR * * retAttr)
411{
412 TLIBATTR* libAttr = new TLIBATTR;
413 memset(libAttr, 0, sizeof(TLIBATTR));
414 libAttr->syskind = SYS_WIN32;
415 libAttr->lcid = Lang;
416 AppDesc.GetClassId(0, libAttr->guid);
417 libAttr->wMajorVerNum = AppDesc.GetVersionField(0);
418 libAttr->wMinorVerNum = AppDesc.GetVersionField(1);
419 *retAttr = libAttr;
420 return HR_NOERROR;
421}
422
423void _IFUNC
424TTypeLibrary::ReleaseTLibAttr(TLIBATTR * attr)
425{
426 delete attr;
427}
428
429HRESULT _IFUNC
430TTypeLibrary::GetTypeComp(ITypeComp* * /*retComp*/)
431{
432 return HR_TYPE_UNSUPFORMAT;
433}
434
435HRESULT _IFUNC
436TTypeLibrary::GetDocumentation(int index, BSTR * retName,
437 BSTR * retDoc,
438 ulong * retHelpContext,
439 BSTR * retHelpFile)
440{
441 if (retHelpFile)
442 *retHelpFile = owl::SysAllocString(AppDesc.GetHelpFile(Lang));
443 if (retHelpContext)
444 *retHelpContext = 0;
445 if (index == -1 || index == AppDesc.GetClassCount()) { // library itself
446 if (retName)
447 *retName = owl::SysAllocString(AppDesc.GetAppName(Lang));
448 if (retDoc)
449 *retDoc = owl::SysAllocString(AppDesc.GetAppDoc(Lang));
450 if (retHelpContext)
451 *retHelpContext = 0;
452 } else {
453 TAutoClass* cls = AppDesc.GetAutoClass(index);
454 if (!cls)
456 if (retName)
457 *retName = owl::SysAllocString(cls->GetName(Lang));
458 if (retDoc)
459 *retDoc = owl::SysAllocString(cls->GetDoc(Lang));
460 if (retHelpContext)
461 *retHelpContext = cls->GetHelpId();
462 }
463 return HR_NOERROR;
464}
465
466HRESULT _IFUNC
467TTypeLibrary::IsName(OLECHAR * nameBuf, ulong /*hashVal*/, int * retFound)
468{
469 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
470 for (int index = 0; index < AppDesc.ClassCount; index++, ref++) {
471 TAutoClass* cls = ref->Class;
472 // not clear from doc if we should check names of classes as well as members
473 long id;
474 TAutoSymbol* sym = cls->Lookup(OleStr(nameBuf), Lang, asOleType, id);
475 if (sym) {
476 lstrcpyW(nameBuf, OleStr(sym->Name));
477 *retFound = 1;
478 return HR_NOERROR;
479 }
480 }
481 return ResultFromScode(TYPE_E_ELEMENTNOTFOUND);
482}
483
484HRESULT _IFUNC
485TTypeLibrary::FindName(OLECHAR * nameBuf, ulong /*lHashVal*/,
486 ITypeInfo* * retInfo, MEMBERID * retId,
487 unsigned short * inoutCount)
488{
489 unsigned short found = 0;
490 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
491 for (int index = 0; index < AppDesc.ClassCount && found < *inoutCount;
492 index++, ref++) {
493 TAutoClass* cls = ref->Class;
494 long id;
495 TAutoSymbol* sym = cls->Lookup(OleStr(nameBuf), Lang, asOleType, id);
496 if (sym) {
497 retId[found] = id;
498 retInfo[found] = AppDesc.CreateITypeInfo(*cls);
499 found++;
500 }
501 }
502 *inoutCount = found;
503 return found ? HR_NOERROR : HR_TYPE_ELEMENTNOTFOUND;
504}
505
506//____________________________________________________________________________
507//
508// TCoClassInfo implementation
509//____________________________________________________________________________
510
511TCoClassInfo::TCoClassInfo(TAppDescriptor& appDesc, uint16 typeFlags, int implCount)
512: AppDesc(appDesc), RefCnt(0), TypeFlags(typeFlags), ImplCount(implCount)
513{
514 ImplList = new unsigned[implCount];
515 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
516 int iapp = -1;
517 int ievent = -1;
518 Default = -1;
519 DefaultEvent = -1;
520 int iclass = 0;
521 for (int index = 0; iclass < implCount; index++, ref++) {
522 TAutoClass* cls = ref->Class;
523 int implFlags = cls->GetImplTypeFlags();
524 uint16 typeFlags = cls->GetCoClassFlags();
525 if (implFlags || typeFlags) {
526 if (implFlags & IMPLTYPEFLAG_FSOURCE) {
527 ievent = iclass;
528 if (implFlags & IMPLTYPEFLAG_FDEFAULT)
529 DefaultEvent = iclass;
530 } else {
531 if (typeFlags & TYPEFLAG_FAPPOBJECT)
532 iapp = iclass;
533 if (implFlags & IMPLTYPEFLAG_FDEFAULT)
534 Default = iclass;
535 }
536 ImplList[iclass++] = index;
537 }
538 }
539 if (Default == -1)
540 Default = iapp;
541 if (DefaultEvent == -1)
542 DefaultEvent = ievent;
543}
544
546{
547 delete ImplList;
548}
549
550HRESULT _IFUNC
551TCoClassInfo::QueryInterface(const IID & riid, void * * retIface)
552{
553 if (riid == IID_IUnknown || riid == IID_ITypeInfo) {
554 AddRef();
555 *retIface = (IUnknown*)this;
556 return HR_NOERROR;
557 }
558 *retIface = 0;
559 return HR_NOINTERFACE;
560}
561
562unsigned long _IFUNC
563
564TCoClassInfo::AddRef()
565{
566 return ++RefCnt;
567}
568
569unsigned long _IFUNC
570TCoClassInfo::Release()
571{
572 if (--RefCnt != 0)
573 return RefCnt;
574 delete this;
575 return 0;
576}
577
578HRESULT _IFUNC
579TCoClassInfo::GetTypeAttr(TYPEATTR * * retTypeAttr)
580{
581 TYPEATTR* ta = (TYPEATTR*)new uint8[sizeof(TYPEATTR)];
582 memset(ta, 0, sizeof(TYPEATTR));
583 ta->guid = AppDesc.AppClassId;
584 ta->lcid = AppDesc.GetAppLang();
585 ta->typekind = TKIND_COCLASS;
586 ta->cImplTypes = (unsigned short)ImplCount;
587 ta->wMajorVerNum = AppDesc.GetVersionField(0);
588 ta->wMinorVerNum = AppDesc.GetVersionField(1);
589 ta->wTypeFlags = TypeFlags;
590 *retTypeAttr = ta;
591 return HR_NOERROR;
592}
593
594void _IFUNC
595TCoClassInfo::ReleaseTypeAttr(TYPEATTR * ptypeattr)
596{
597 delete [] (uint8*)ptypeattr;
598}
599
600HRESULT _IFUNC
601TCoClassInfo::GetDocumentation(MEMBERID memid,
602 BSTR * retName, BSTR * retDoc,
603 ulong * retHelpContext,
604 BSTR * retHelpFile)
605{
606 if (retHelpFile)
607 *retHelpFile = owl::SysAllocString(AppDesc.GetHelpFile(AppDesc.GetAppLang()));
608 if (memid == -1) { // request info on type library itself
609 if (retName)
610 *retName = owl::SysAllocString(AppDesc.GetAppName(AppDesc.GetAppLang()));
611 if (retDoc)
612 *retDoc = owl::SysAllocString(AppDesc.GetAppDoc(AppDesc.GetAppLang()));
613 if (retHelpContext)
614 *retHelpContext = 0;
615 } else {
617 }
618 return HR_NOERROR;
619}
620
621HRESULT _IFUNC
622TCoClassInfo::CreateInstance(IUnknown* /*punkOuter*/, const IID & /*riid*/,
623 void * * /*ppvObj*/)
624{
626}
627
628HRESULT _IFUNC
629TCoClassInfo::GetContainingTypeLib(ITypeLib* * retLib,
630 unsigned int * retIndex)
631{
632 *retLib = AppDesc.GetTypeLibrary();
633 if (retIndex)
634 *retIndex = AppDesc.GetClassCount();
635 return HR_NOERROR;
636}
637
638HRESULT _IFUNC
639TCoClassInfo::GetRefTypeInfo(HREFTYPE hreftype, ITypeInfo* * retInfo)
640{
641 TAutoClass* cls = (TAutoClass*)hreftype;
642 if (AppDesc.GetClassIndex(cls) == -1) // validate pointer to avoid crash
644 *retInfo = AppDesc.CreateITypeInfo(*cls);
645 return HR_NOERROR;
646}
647
648HRESULT _IFUNC
649TCoClassInfo::GetImplTypeFlags(unsigned int index, int * retflags)
650{
651 TAutoClass* cls = index < (uint)ImplCount ?
652 AppDesc.GetAutoClass(ImplList[index]) : 0;
653 if (!cls)
655 int implFlags = cls->GetImplTypeFlags();
656 if (implFlags & IMPLTYPEFLAG_FSOURCE) {
657 if (index == (uint)DefaultEvent)
658 implFlags |= IMPLTYPEFLAG_FDEFAULT;
659 }
660 else {
661 if (index == (uint)Default)
662 implFlags |= IMPLTYPEFLAG_FDEFAULT;
663 }
664 *retflags = implFlags;
665 return HR_NOERROR;
666}
667
668HRESULT _IFUNC
669TCoClassInfo::GetRefTypeOfImplType(unsigned int index,
670 HREFTYPE * retreftype)
671{
672 TAutoClass* cls = index < (uint)ImplCount ?
673 AppDesc.GetAutoClass(ImplList[index]):0;
674 *retreftype = (HREFTYPE)cls;
675 return cls ? HR_NOERROR : HR_TYPE_ELEMENTNOTFOUND;
676}
677
678// The following methods of ITypeInfo are not relevant for a COCLASS typeinfo
679
680HRESULT _IFUNC
681TCoClassInfo::GetFuncDesc(unsigned int, FUNCDESC * *)
682{
684}
685
686void _IFUNC
687TCoClassInfo::ReleaseFuncDesc(FUNCDESC *)
688{
689}
690
691HRESULT _IFUNC
692TCoClassInfo::GetVarDesc(unsigned int, VARDESC * *)
693{
695}
696
697void _IFUNC
698TCoClassInfo::ReleaseVarDesc(VARDESC *)
699{
700}
701
702HRESULT _IFUNC
703TCoClassInfo::GetNames(MEMBERID, BSTR *, unsigned int, unsigned int *)
704{
706}
707
708HRESULT _IFUNC
709TCoClassInfo::GetIDsOfNames(OLECHAR * *, uint, MEMBERID *)
710{
712}
713
714HRESULT _IFUNC
715TCoClassInfo::Invoke(void *, MEMBERID, unsigned short, DISPPARAMS *,
716 VARIANT *, EXCEPINFO *, unsigned int *)
717{
719}
720
721HRESULT _IFUNC
722TCoClassInfo::GetTypeComp(ITypeComp* *)
723{
725}
726
727HRESULT _IFUNC
728TCoClassInfo::GetMops(MEMBERID, BSTR *)
729{
731}
732
733HRESULT _IFUNC
734TCoClassInfo::GetDllEntry(MEMBERID, INVOKEKIND, BSTR *, BSTR *,
735 unsigned short *)
736{
738}
739
740HRESULT _IFUNC
741TCoClassInfo::AddressOfMember(MEMBERID, INVOKEKIND, void * *)
742{
744}
745
746} // OCF namespace
747
748//==============================================================================
749
TAppDescriptor - OLE application descriptor definitions.
void WriteTypeLibrary(owl::TLangId lang, LPCTSTR file)
Definition typelib.cpp:195
TBaseClassId AppClassId
Definition appdesc.h:136
unsigned short GetCoClassFlags() const
Definition autodefs.h:1487
int GetImplTypeFlags() const
Definition autodefs.h:1484
TCoClassInfo(TAppDescriptor &appDesc, owl::uint16 typeFlags, int implCount)
Definition typelib.cpp:511
OLE object exposed for automated access of internal object.
Definition autodefs.h:972
TTypeLibrary(TAppDescriptor &appDesc, owl::TLangId lang)
Definition typelib.cpp:303
ITypeInfo * CreateCoClassInfo()
Definition typelib.cpp:329
TFileName()
Constructs an empty filename.
Definition filename.cpp:225
@ Device
Logical device or sharename.
Definition filename.h:127
@ Path
Directory path to the file.
Definition filename.h:128
@ Server
Server name.
Definition filename.h:126
static auto GetClassesRoot() -> TRegKey &
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT).
Definition registry.cpp:32
#define _tcscat
Definition cygwin.h:83
#define _tcscpy
Definition cygwin.h:79
#define _MAX_PATH
Definition cygwin.h:97
#define _T(x)
Definition cygwin.h:51
Include for OC, gets common headers when precompiled headers are enabled.
Object Component Framework (COM encapsulation).
Definition appdesc.h:22
@ asOleType
method or property exposed for OLE
Definition autodefs.h:299
_T("!ForeColor")
owl::TSysStr TBSTR
BASIC global string encapsulation.
Definition oleutil.h:40
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
unsigned long ulong
Definition number.h:26
unsigned char uint8
Definition number.h:32
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
Definition lclstrng.h:26
unsigned short uint16
Definition number.h:33
BSTR SysAllocString(const char *str)
Definition string.h:130
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
ulong TStaticSync< T >::Count
Definition thread.h:1354
Definition of TOcControl class - Proxy object representing a control in.
interface _ICLASS ITypeInfo
Definition occtrl.h:27
#define HR_NOINTERFACE
Definition defs.h:79
#define HR_TYPE_WRONGTYPEKIND
Definition defs.h:101
#define HR_TYPE_ELEMENTNOTFOUND
Definition defs.h:103
#define HR_TYPE_LIBNOTREGISTERED
Definition defs.h:102
#define HR_TYPE_UNSUPFORMAT
Definition defs.h:104
#define HR_NOERROR
Definition defs.h:73
#define OLECALL(func, msg)
Definition except.h:78
#define _IFUNC
Definition oleutil.h:28
#define OleText(s)
Definition string.h:129
#define OleStr(s)
Definition string.h:128
#define OLE_TYPELIB_FILE
Definition typelib.cpp:12