From fa7e97e80def8d0f305f6211f6d1b7d7274b0f59 Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Sun, 2 Jul 2006 13:03:09 +0200 Subject: [PATCH] oleview: Added type displaying in TypeLib Viewer. --- programs/oleview/En.rc | 8 ++- programs/oleview/resource.h | 2 + programs/oleview/typelib.c | 121 ++++++++++++++++++++++++++++++++---- 3 files changed, 116 insertions(+), 15 deletions(-) diff --git a/programs/oleview/En.rc b/programs/oleview/En.rc index b792716308f..f5b3a28c239 100644 --- a/programs/oleview/En.rc +++ b/programs/oleview/En.rc @@ -137,9 +137,11 @@ STRINGTABLE IDS_CGCOFAIL, "CoGetClassObject failed." IDS_ERROR_UNKN, "Unknown error" - IDS_TRUE "True" - IDS_FALSE "False" - IDS_BYTES "bytes" + IDS_TRUE, "True" + IDS_FALSE, "False" + IDS_BYTES, "bytes" + + IDS_ERROR_LOADTYPELIB, "LoadTypeLib( %s ) failed ($%x)" } DLG_CREATEINSTON DIALOG DISCARDABLE 0, 0, 250, 41 diff --git a/programs/oleview/resource.h b/programs/oleview/resource.h index 123427eb690..5d7818b403c 100644 --- a/programs/oleview/resource.h +++ b/programs/oleview/resource.h @@ -73,6 +73,8 @@ #define IDS_FALSE 311 #define IDS_BYTES 312 +#define IDS_ERROR_LOADTYPELIB 400 + #define DLG_CREATEINSTON 1000 #define IDC_MACHINE 1001 diff --git a/programs/oleview/typelib.c b/programs/oleview/typelib.c index f6b3e2398f0..09275f44c9c 100644 --- a/programs/oleview/typelib.c +++ b/programs/oleview/typelib.c @@ -23,43 +23,140 @@ TYPELIB typelib; static const WCHAR wszTypeLib[] = { 'T','Y','P','E','L','I','B','\0' }; -void PopulateTree(void) +void AddToStrW(WCHAR *wszDest, const WCHAR *wszSource) +{ + lstrcpyW(&wszDest[lstrlenW(wszDest)], wszSource); +} + +int PopulateTree(void) { TVITEM tvi; TVINSERTSTRUCT tvis; ITypeLib *pTypeLib; + ITypeInfo *pTypeInfo, *pRefTypeInfo; + TYPEATTR *pTypeAttr; INT count, i; BSTR bstrName; + BSTR bstrData; + WCHAR wszText[MAX_LOAD_STRING]; + HRESULT hRes; + + const WCHAR wszFormat[] = { '%','s',' ','(','%','s',')','\0' }; + const WCHAR wszSpace[] = { ' ','\0' }; + + const WCHAR wszTKIND_ENUM[] = { 't','y','p','e','d','e','f',' ','e','n','u','m',' ','\0' }; + const WCHAR wszTKIND_RECORD[] + = { 't','y','p','e','d','e','f',' ','s','t','r','u','c','t',' ','\0' }; + const WCHAR wszTKIND_MODULE[] = { 'm','o','d','u','l','e',' ','\0' }; + const WCHAR wszTKIND_INTERFACE[] = { 'i','n','t','e','r','f','a','c','e',' ','\0' }; + const WCHAR wszTKIND_DISPATCH[] + = { 'd','i','s','p','i','n','t','e','r','f','a','c','e',' ','\0' }; + const WCHAR wszTKIND_COCLASS[] = { 'c','o','c','l','a','s','s',' ','\0' }; + const WCHAR wszTKIND_ALIAS[] = { 't','y','p','e','d','e','f',' ','\0' }; + const WCHAR wszTKIND_UNION[] + = { 't','y','p','e','d','e','f',' ','u','n','i','o','n',' ','\0' }; + + const WCHAR wszVT_BOOL[] = { 'V','A','R','I','A','N','T','_','B','O','O','L',' ','\0' }; + const WCHAR wszVT_UI4[] = { 'u','n','s','i','g','n','e','d',' ','l','o','n','g',' ','\0' }; + const WCHAR wszVT_I4[] = { 'l','o','n','g',' ','\0' }; + const WCHAR wszVT_R4[] = { 's','i','n','g','l','e',' ','\0' }; + const WCHAR wszVT_INT[] = { 'i','n','t',' ','\0' }; + const WCHAR wszVT_BSTR[] = { 'B','S','T','R',' ','\0' }; + const WCHAR wszVT_CY[] = { 'C','U','R','R','E','N','C','Y',' ','\0' }; memset(&tvi, 0, sizeof(TVITEM)); tvi.hItem = TreeView_GetSelection(globals.hTree); U(tvis).item.mask = TVIF_TEXT|TVIF_CHILDREN; + U(tvis).item.cchTextMax = MAX_LOAD_STRING; + U(tvis).item.pszText = wszText; U(tvis).item.cChildren = 1; tvis.hInsertAfter = (HTREEITEM)TVI_LAST; tvis.hParent = TVI_ROOT; SendMessage(globals.hTree, TVM_GETITEM, 0, (LPARAM)&tvi); - if(FAILED(LoadTypeLib(((ITEM_INFO*)tvi.lParam)->path, &pTypeLib))) return; + if(FAILED((hRes = LoadTypeLib(((ITEM_INFO*)tvi.lParam)->path, &pTypeLib)))) + { + WCHAR wszMessage[MAX_LOAD_STRING]; + WCHAR wszError[MAX_LOAD_STRING]; + + LoadString(globals.hMainInst, IDS_ERROR_LOADTYPELIB, + wszError, sizeof(WCHAR[MAX_LOAD_STRING])); + wsprintfW(wszMessage, wszError, ((ITEM_INFO*)tvi.lParam)->path, hRes); + MessageBox(globals.hMainWnd, wszMessage, NULL, MB_OK|MB_ICONEXCLAMATION); + return 1; + } count = ITypeLib_GetTypeInfoCount(pTypeLib); - for(i=-1; itypekind) + { +#define TKINDADDTOSTR(x) case x:\ + AddToStrW(wszText, wsz##x);\ + AddToStrW(wszText, bstrName);\ + break + TKINDADDTOSTR(TKIND_ENUM); + TKINDADDTOSTR(TKIND_RECORD); + TKINDADDTOSTR(TKIND_MODULE); + TKINDADDTOSTR(TKIND_INTERFACE); + TKINDADDTOSTR(TKIND_DISPATCH); + TKINDADDTOSTR(TKIND_COCLASS); + TKINDADDTOSTR(TKIND_UNION); + case TKIND_ALIAS: + AddToStrW(wszText, wszTKIND_ALIAS); + + switch(pTypeAttr->tdescAlias.vt&VT_TYPEMASK) + { +#define VTADDTOSTR(x) case x:\ + AddToStrW(wszText, wsz##x);\ + break + VTADDTOSTR(VT_BOOL); + VTADDTOSTR(VT_UI4); + VTADDTOSTR(VT_I4); + VTADDTOSTR(VT_R4); + VTADDTOSTR(VT_INT); + VTADDTOSTR(VT_BSTR); + VTADDTOSTR(VT_CY); + case VT_USERDEFINED: + ITypeInfo_GetRefTypeInfo(pTypeInfo, U(pTypeAttr->tdescAlias).hreftype, &pRefTypeInfo); + ITypeInfo_GetDocumentation(pRefTypeInfo, MEMBERID_NIL, &bstrData, NULL, NULL, NULL); + AddToStrW(wszText, bstrData); + AddToStrW(wszText, wszSpace); + SysFreeString(bstrData); + ITypeInfo_Release(pRefTypeInfo); + break; + } + + AddToStrW(wszText, bstrName); + break; + default: + lstrcpyW(wszText, bstrName); + } + SendMessage(typelib.hTree, TVM_INSERTITEM, 0, (LPARAM)&tvis); + + ITypeInfo_ReleaseTypeAttr(pTypeInfo, pTypeAttr); + ITypeInfo_Release(pTypeInfo); SysFreeString(bstrName); } SendMessage(typelib.hTree, TVM_EXPAND, TVE_EXPAND, (LPARAM)tvis.hParent); ITypeLib_Release(pTypeLib); + return 0; } void TypeLibResizeChild(void) @@ -124,8 +221,8 @@ LRESULT CALLBACK TypeLibProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SetLeft(typelib.hPaneWnd, typelib.hTree); SetRight(typelib.hPaneWnd, typelib.hEdit); - PopulateTree(); - SetFocus(typelib.hTree); + if(PopulateTree()) DestroyWindow(hWnd); + else SetFocus(typelib.hTree); break; } case WM_COMMAND: