12#define OLE_TYPELIB_FILE L"stdole32.tlb"
25struct TOleCreateInfo {
32 ICreateTypeInfo* CreateInfo;
33 TOleCreateInfo() : OurTypeInfo(0), OleTypeInfo(0), CreateInfo(0) {}
37TOleCreateInfo::~TOleCreateInfo()
40 OurTypeInfo->Release();
42 OleTypeInfo->Release();
44 CreateInfo->Release();
47struct TOleCreateList {
55 ICreateTypeLib* CreateLib;
61 TOleCreateList(ITypeLib* typeLib, LPCTSTR fileName);
62 void FixupTypeDescRef(
int typeIndex, TYPEDESC & typeDesc);
63 void Close(LPCTSTR helpDir);
65 ~TOleCreateList() {Clear();}
68TOleCreateList::TOleCreateList(ITypeLib* typeLib, LPCTSTR fileName)
72 OleLib(0), OleComp(0), OleInfo(0),
73 CreateLib(0), TypeAttr(0), LibAttr(0), List(0), FuncNames(0)
81 OLECALL(OleLib->GetTypeComp(&OleComp),
_T(
"GetTypeComp"));
85 const_cast<LPOLESTR
>(
OleText(
"IDispatch")),
86 ::LHashValOfName(0,
OleText(
"IDispatch")),
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"));
99 OLECALL(CreateLib->SetName(libName),
_T(
"Set TypeLib name"));
101 OLECALL(CreateLib->SetDocString(libDoc),
_T(
"Set TypeLib doc"));
104 OLECALL(CreateLib->SetHelpFileName(helpFile),
_T(
"SetHelpFileName"));
105 OLECALL(CreateLib->SetHelpContext(helpId),
_T(
"HelpContext"));
107 OLECALL(CreateLib->SetVersion(LibAttr->wMajorVerNum,
108 LibAttr->wMinorVerNum),
_T(
"Set TypeLib version"));
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"));
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) {
134 OLECALL(newInfo->AddRefTypeInfo(OleInfo, &hreftype),
_T(
"AddRefTypeInfo"));
135 OLECALL(newInfo->AddImplType(0, hreftype),
_T(
"AddImplType"));
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;
145void TOleCreateList::Close(LPCTSTR helpDir)
147 OLECALL(CreateLib->SaveAllChanges(),
_T(
"Write and close TypeLib file"));
148 CreateLib->Release();
150 OLECALL(::RegisterTypeLib(TypeLib,
153 _T(
"Register type library"));
156void TOleCreateList::Clear()
161 TypeLib->ReleaseTLibAttr(LibAttr);
163 AttrTypeInfo->ReleaseTypeAttr(TypeAttr);
171 CreateLib->Release();
176TOleCreateList::FixupTypeDescRef(
int typeIndex, TYPEDESC & typeDesc)
178 if (typeDesc.vt == VT_USERDEFINED) {
180 OLECALL(List[typeIndex].OurTypeInfo->GetRefTypeInfo(typeDesc.hreftype,
181 &refInfo),
_T(
"GetRefTypeInfo"));
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"));
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;
209 for (index = 0; index < curInfo.FuncCount; index++) {
210 OLECALL(typeInfo->GetFuncDesc(index, &funcDesc),
_T(
"GetFuncDesc"));
215 OLECALL(servedObject->GetFuncDocFromIndex(index, libName, libDoc,
216 &helpId, 0),
_T(
"Get method name and doc"));
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);
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;
235 OLECALL(newInfo->SetFuncDocString(index, libDoc),
_T(
"Set method doc"));
236 OLECALL(newInfo->SetFuncHelpContext(index, helpId),
_T(
"HelpContext"));
237 typeInfo->ReleaseFuncDesc(funcDesc), funcDesc = 0;
239 for (index = 0; index < curInfo.VarCount; index++) {
240 OLECALL(typeInfo->GetVarDesc(index, &varDesc),
_T(
"GetVarDesc"));
245 OLECALL(servedObject->GetVarDocFromIndex(index, libName, libDoc,
246 &helpId, 0),
_T(
"Get propery name and doc"));
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"));
254 OLECALL(newInfo->SetVarDocString(index, libDoc),
_T(
"Set property doc"));
255 OLECALL(newInfo->SetVarHelpContext(index, helpId),
_T(
"HelpContext"));
256 typeInfo->ReleaseVarDesc(varDesc), varDesc = 0;
258 if (curInfo.TypeKind == TKIND_COCLASS) {
259 for (index = 0; index < curInfo.ImplCount; index++) {
262 OLECALL(typeInfo->GetRefTypeOfImplType(index, &hreftype),
_T(
"GetCoClassRef"));
263 OLECALL(typeInfo->GetRefTypeInfo(hreftype, &refInfo),
_T(
"GetCoClassTypeInfo"));
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"));
270 OLECALL(typeInfo->GetImplTypeFlags(index, &implflags),
_T(
"GetImplTypeFlags"));
271 OLECALL(newInfo->SetImplTypeFlags(index, implflags),
_T(
"SetImplTypeFlags"));
276 OLECALL(newInfo->LayOut(),
_T(
"Layout typeinfo"));
278 const auto regHelpDir = RegInfo.Lookup(
"helpdir");
279 tstring helpDir = regHelpDir ? regHelpDir :
_T(
"");
280 if (helpDir.empty()){
282 Module->GetModuleFileName(path,
sizeof(path));
285 typeList.Close(helpDir.c_str());
294 iGuid ^= DebugGuidOffset;
304 : AppDesc(appDesc), Lang(lang), RefCnt(0)
307 CoClassImplCount = 0;
308 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
309 for (
int index = 0; index < AppDesc.ClassCount; index++, ref++) {
313 if (implFlags != 0 || typeFlags != 0) {
315 CoClassFlags |= typeFlags;
322 if (AppDesc.TypeLib ==
this)
325 ::CoDisconnectObject(
this,0);
337TTypeLibrary::QueryInterface(
const IID & riid,
void * * retIface)
339 if (riid == IID_IUnknown || riid == IID_ITypeLib) {
341 *retIface = (IUnknown*)
this;
350TTypeLibrary::AddRef()
356TTypeLibrary::Release()
365TTypeLibrary::GetTypeInfoCount()
367 return AppDesc.GetClassCount() + (CoClassImplCount > 0);
371TTypeLibrary::GetTypeInfo(
unsigned index,
ITypeInfo* * retInfo)
373 if (CoClassImplCount > 0 && index == (
uint)AppDesc.GetClassCount()) {
377 TAutoClass* cls = AppDesc.GetAutoClass(index);
380 *retInfo = AppDesc.CreateITypeInfo(*cls);
386TTypeLibrary::GetTypeInfoType(
unsigned index, TYPEKIND * retKind)
388 unsigned int count = AppDesc.GetClassCount();
391 *retKind = (index == count ? TKIND_COCLASS : TKIND_DISPATCH);
396TTypeLibrary::GetTypeInfoOfGuid(
const GUID & guid,
ITypeInfo* * retInfo)
398 if (AppDesc.AppClassId.GetOffset(guid) == 0) {
401 TAutoClass* cls = AppDesc.GetAutoClass(guid);
404 *retInfo = AppDesc.CreateITypeInfo(*cls);
410TTypeLibrary::GetLibAttr(TLIBATTR * * retAttr)
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);
424TTypeLibrary::ReleaseTLibAttr(TLIBATTR * attr)
430TTypeLibrary::GetTypeComp(ITypeComp* * )
436TTypeLibrary::GetDocumentation(
int index, BSTR * retName,
438 ulong * retHelpContext,
445 if (index == -1 || index == AppDesc.GetClassCount()) {
453 TAutoClass* cls = AppDesc.GetAutoClass(index);
461 *retHelpContext = cls->GetHelpId();
467TTypeLibrary::IsName(OLECHAR * nameBuf,
ulong ,
int * retFound)
469 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
470 for (
int index = 0; index < AppDesc.ClassCount; index++, ref++) {
471 TAutoClass* cls = ref->Class;
476 lstrcpyW(nameBuf,
OleStr(sym->Name));
481 return ResultFromScode(TYPE_E_ELEMENTNOTFOUND);
485TTypeLibrary::FindName(OLECHAR * nameBuf,
ulong ,
487 unsigned short * inoutCount)
489 unsigned short found = 0;
490 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
491 for (
int index = 0; index < AppDesc.ClassCount && found < *inoutCount;
493 TAutoClass* cls = ref->Class;
498 retInfo[found] = AppDesc.CreateITypeInfo(*cls);
512: AppDesc(appDesc), RefCnt(0), TypeFlags(typeFlags), ImplCount(implCount)
514 ImplList =
new unsigned[implCount];
515 TAutoClass::TAutoClassRef* ref = AppDesc.ClassList;
521 for (
int index = 0; iclass < implCount; index++, ref++) {
525 if (implFlags || typeFlags) {
526 if (implFlags & IMPLTYPEFLAG_FSOURCE) {
528 if (implFlags & IMPLTYPEFLAG_FDEFAULT)
529 DefaultEvent = iclass;
531 if (typeFlags & TYPEFLAG_FAPPOBJECT)
533 if (implFlags & IMPLTYPEFLAG_FDEFAULT)
536 ImplList[iclass++] = index;
541 if (DefaultEvent == -1)
542 DefaultEvent = ievent;
551TCoClassInfo::QueryInterface(
const IID & riid,
void * * retIface)
553 if (riid == IID_IUnknown || riid == IID_ITypeInfo) {
555 *retIface = (IUnknown*)
this;
564TCoClassInfo::AddRef()
570TCoClassInfo::Release()
579TCoClassInfo::GetTypeAttr(TYPEATTR * * retTypeAttr)
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;
595TCoClassInfo::ReleaseTypeAttr(TYPEATTR * ptypeattr)
597 delete [] (
uint8*)ptypeattr;
601TCoClassInfo::GetDocumentation(MEMBERID memid,
602 BSTR * retName, BSTR * retDoc,
603 ulong * retHelpContext,
622TCoClassInfo::CreateInstance(IUnknown* ,
const IID & ,
629TCoClassInfo::GetContainingTypeLib(ITypeLib* * retLib,
630 unsigned int * retIndex)
632 *retLib = AppDesc.GetTypeLibrary();
634 *retIndex = AppDesc.GetClassCount();
639TCoClassInfo::GetRefTypeInfo(HREFTYPE hreftype,
ITypeInfo* * retInfo)
641 TAutoClass* cls = (TAutoClass*)hreftype;
642 if (AppDesc.GetClassIndex(cls) == -1)
644 *retInfo = AppDesc.CreateITypeInfo(*cls);
649TCoClassInfo::GetImplTypeFlags(
unsigned int index,
int * retflags)
651 TAutoClass* cls = index < (
uint)ImplCount ?
652 AppDesc.GetAutoClass(ImplList[index]) : 0;
655 int implFlags = cls->GetImplTypeFlags();
656 if (implFlags & IMPLTYPEFLAG_FSOURCE) {
657 if (index == (
uint)DefaultEvent)
658 implFlags |= IMPLTYPEFLAG_FDEFAULT;
661 if (index == (
uint)Default)
662 implFlags |= IMPLTYPEFLAG_FDEFAULT;
664 *retflags = implFlags;
669TCoClassInfo::GetRefTypeOfImplType(
unsigned int index,
670 HREFTYPE * retreftype)
672 TAutoClass* cls = index < (
uint)ImplCount ?
673 AppDesc.GetAutoClass(ImplList[index]):0;
674 *retreftype = (HREFTYPE)cls;
681TCoClassInfo::GetFuncDesc(
unsigned int, FUNCDESC * *)
687TCoClassInfo::ReleaseFuncDesc(FUNCDESC *)
692TCoClassInfo::GetVarDesc(
unsigned int, VARDESC * *)
698TCoClassInfo::ReleaseVarDesc(VARDESC *)
703TCoClassInfo::GetNames(MEMBERID, BSTR *,
unsigned int,
unsigned int *)
709TCoClassInfo::GetIDsOfNames(OLECHAR * *,
uint, MEMBERID *)
715TCoClassInfo::Invoke(
void *, MEMBERID,
unsigned short, DISPPARAMS *,
716 VARIANT *, EXCEPINFO *,
unsigned int *)
722TCoClassInfo::GetTypeComp(ITypeComp* *)
728TCoClassInfo::GetMops(MEMBERID, BSTR *)
734TCoClassInfo::GetDllEntry(MEMBERID, INVOKEKIND, BSTR *, BSTR *,
741TCoClassInfo::AddressOfMember(MEMBERID, INVOKEKIND,
void * *)
TAppDescriptor - OLE application descriptor definitions.
void WriteTypeLibrary(owl::TLangId lang, LPCTSTR file)
unsigned short GetCoClassFlags() const
int GetImplTypeFlags() const
TCoClassInfo(TAppDescriptor &appDesc, owl::uint16 typeFlags, int implCount)
OLE object exposed for automated access of internal object.
TTypeLibrary(TAppDescriptor &appDesc, owl::TLangId lang)
ITypeInfo * CreateCoClassInfo()
TFileName()
Constructs an empty filename.
@ Device
Logical device or sharename.
@ Path
Directory path to the file.
static auto GetClassesRoot() -> TRegKey &
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT).
Include for OC, gets common headers when precompiled headers are enabled.
Object Component Framework (COM encapsulation).
@ asOleType
method or property exposed for OLE
owl::TSysStr TBSTR
BASIC global string encapsulation.
Object Windows Library (OWLNext Core).
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
BSTR SysAllocString(const char *str)
ulong TStaticSync< T >::Count
Definition of TOcControl class - Proxy object representing a control in.
interface _ICLASS ITypeInfo
#define HR_TYPE_WRONGTYPEKIND
#define HR_TYPE_ELEMENTNOTFOUND
#define HR_TYPE_LIBNOTREGISTERED
#define HR_TYPE_UNSUPFORMAT
#define OLECALL(func, msg)