interface.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * OleView (interface.c)
  3. *
  4. * Copyright 2006 Piotr Caban
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "main.h"
  21. typedef struct
  22. {
  23. WCHAR *wszLabel;
  24. WCHAR *wszIdentifier;
  25. }DIALOG_INFO;
  26. BOOL IsInterface(HTREEITEM item)
  27. {
  28. TVITEMW tvi;
  29. memset(&tvi, 0, sizeof(TVITEMW));
  30. tvi.hItem = item;
  31. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  32. if(!tvi.lParam) return FALSE;
  33. if(((ITEM_INFO*)tvi.lParam)->cFlag & INTERFACE) return TRUE;
  34. return FALSE;
  35. }
  36. static IUnknown *GetInterface(void)
  37. {
  38. HTREEITEM hSelect;
  39. TVITEMW tvi;
  40. CLSID clsid;
  41. IUnknown *unk;
  42. hSelect = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
  43. TVGN_CARET, 0);
  44. memset(&tvi, 0, sizeof(TVITEMW));
  45. tvi.hItem = hSelect;
  46. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  47. CLSIDFromString(((ITEM_INFO *)tvi.lParam)->clsid, &clsid);
  48. memset(&tvi, 0, sizeof(TVITEMW));
  49. tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
  50. TVGN_PARENT, (LPARAM)hSelect);
  51. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  52. IUnknown_QueryInterface(((ITEM_INFO *)tvi.lParam)->pU, &clsid, (void *)&unk);
  53. return unk;
  54. }
  55. static INT_PTR CALLBACK InterfaceViewerProc(HWND hDlgWnd, UINT uMsg,
  56. WPARAM wParam, LPARAM lParam)
  57. {
  58. DIALOG_INFO *di;
  59. HWND hObject;
  60. IUnknown *unk;
  61. HRESULT hRes;
  62. ULARGE_INTEGER size;
  63. WCHAR wszSize[MAX_LOAD_STRING];
  64. WCHAR wszBuf[MAX_LOAD_STRING];
  65. WCHAR wszFormat[] = { '%','d',' ','%','s','\0' };
  66. switch(uMsg)
  67. {
  68. case WM_INITDIALOG:
  69. di = (DIALOG_INFO *)lParam;
  70. hObject = GetDlgItem(hDlgWnd, IDC_LABEL);
  71. SetWindowTextW(hObject, di->wszLabel);
  72. hObject = GetDlgItem(hDlgWnd, IDC_IDENTIFIER);
  73. SetWindowTextW(hObject, di->wszIdentifier);
  74. return TRUE;
  75. case WM_COMMAND:
  76. switch(LOWORD(wParam)) {
  77. case IDCANCEL:
  78. EndDialog(hDlgWnd, IDCANCEL);
  79. return TRUE;
  80. case IDC_ISDIRTY_BUTTON:
  81. unk = GetInterface();
  82. hRes = IPersistStream_IsDirty((IPersistStream *)unk);
  83. IUnknown_Release(unk);
  84. if(hRes == S_OK)
  85. LoadStringW(globals.hMainInst, IDS_FALSE, wszBuf, ARRAY_SIZE(wszBuf));
  86. else
  87. LoadStringW(globals.hMainInst, IDS_TRUE, wszBuf, ARRAY_SIZE(wszBuf));
  88. hObject = GetDlgItem(hDlgWnd, IDC_ISDIRTY);
  89. SetWindowTextW(hObject, wszBuf);
  90. return TRUE;
  91. case IDC_GETSIZEMAX_BUTTON:
  92. unk = GetInterface();
  93. IPersistStream_GetSizeMax((IPersistStream *)unk, &size);
  94. IUnknown_Release(unk);
  95. LoadStringW(globals.hMainInst, IDS_BYTES, wszBuf, ARRAY_SIZE(wszBuf));
  96. wsprintfW(wszSize, wszFormat, U(size).LowPart, wszBuf);
  97. hObject = GetDlgItem(hDlgWnd, IDC_GETSIZEMAX);
  98. SetWindowTextW(hObject, wszSize);
  99. return TRUE;
  100. }
  101. }
  102. return FALSE;
  103. }
  104. static void IPersistStreamInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
  105. {
  106. DIALOG_INFO di;
  107. WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
  108. if(wszName[0] == '{')
  109. di.wszLabel = wszClassMoniker;
  110. else di.wszLabel = wszName;
  111. di.wszIdentifier = clsid;
  112. DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSISTSTREAM_IV),
  113. globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
  114. }
  115. static void IPersistInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
  116. {
  117. DIALOG_INFO di;
  118. WCHAR wszClassMoniker[] = { 'C','l','a','s','s','M','o','n','i','k','e','r','\0' };
  119. if(wszName[0] == '{')
  120. di.wszLabel = wszClassMoniker;
  121. else di.wszLabel = wszName;
  122. di.wszIdentifier = clsid;
  123. DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_IPERSIST_IV),
  124. globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
  125. }
  126. static void DefaultInterfaceViewer(WCHAR *clsid, WCHAR *wszName)
  127. {
  128. DIALOG_INFO di;
  129. di.wszLabel = wszName;
  130. di.wszIdentifier = clsid;
  131. DialogBoxParamW(0, MAKEINTRESOURCEW(DLG_DEFAULT_IV),
  132. globals.hMainWnd, InterfaceViewerProc, (LPARAM)&di);
  133. }
  134. void InterfaceViewer(HTREEITEM item)
  135. {
  136. TVITEMW tvi;
  137. WCHAR *clsid;
  138. WCHAR wszName[MAX_LOAD_STRING];
  139. WCHAR wszParent[MAX_LOAD_STRING];
  140. WCHAR wszIPersistStream[] = { '{','0','0','0','0','0','1','0','9','-',
  141. '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
  142. '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };
  143. WCHAR wszIPersist[] = { '{','0','0','0','0','0','1','0','C','-',
  144. '0','0','0','0','-','0','0','0','0','-','C','0','0','0','-',
  145. '0','0','0','0','0','0','0','0','0','0','4','6','}','\0' };
  146. memset(&tvi, 0, sizeof(TVITEMW));
  147. tvi.mask = TVIF_TEXT;
  148. tvi.hItem = item;
  149. tvi.cchTextMax = MAX_LOAD_STRING;
  150. tvi.pszText = wszName;
  151. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  152. clsid = ((ITEM_INFO*)tvi.lParam)->clsid;
  153. memset(&tvi, 0, sizeof(TVITEMW));
  154. tvi.mask = TVIF_TEXT;
  155. tvi.hItem = (HTREEITEM)SendMessageW(globals.hTree, TVM_GETNEXTITEM,
  156. TVGN_PARENT, (LPARAM)item);
  157. tvi.cchTextMax = MAX_LOAD_STRING;
  158. tvi.pszText = wszParent;
  159. SendMessageW(globals.hTree, TVM_GETITEMW, 0, (LPARAM)&tvi);
  160. if(!memcmp(clsid, wszIPersistStream, sizeof(wszIPersistStream)))
  161. IPersistStreamInterfaceViewer(clsid, wszParent);
  162. else if(!memcmp(clsid, wszIPersist, sizeof(wszIPersist)))
  163. IPersistInterfaceViewer(clsid, wszParent);
  164. else DefaultInterfaceViewer(clsid, wszName);
  165. }