Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
6.4 KiB

  1. /*
  2. generate comctl tool
  3. based on gennt32t
  4. */
  5. #pragma warning( disable : 4786) //disable identifier is too long for debugging error
  6. #pragma warning( disable : 4503) //disable decorated name is too long
  7. #include <nt.h>
  8. #include <ntrtl.h>
  9. #include <nturtl.h>
  10. #include <windows.h>
  11. #include <imagehlp.h>
  12. #include <ctype.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <iostream>
  18. #include <fstream>
  19. #include <iomanip>
  20. #include <string>
  21. #include <sstream>
  22. #include <set>
  23. #include <map>
  24. extern "C" {
  25. #include "gen.h"
  26. #if !defined(NUMBER_OF)
  27. #define NUMBER_OF(x) (sizeof(x)/sizeof((x)[0]))
  28. #endif
  29. // string to put in front of all error messages so that BUILD can find them.
  30. const char *ErrMsgPrefix = "NMAKE : U8603: 'GENCOMCTLT' ";
  31. void
  32. HandlePreprocessorDirective(
  33. char *p
  34. )
  35. {
  36. ExitErrMsg(FALSE, "Preprocessor directives not allowed by gencomctlt.\n");
  37. }
  38. }
  39. using namespace std;
  40. typedef string String;
  41. PRBTREE pFunctions = NULL;
  42. PRBTREE pStructures = NULL;
  43. PRBTREE pTypedefs = NULL;
  44. void ExtractCVMHeader(PCVMHEAPHEADER pHeader) {
  45. pFunctions = &pHeader->FuncsList;
  46. pTypedefs = &pHeader->TypeDefsList;
  47. pStructures =&pHeader->StructsList;
  48. }
  49. // globals so debugging works
  50. PKNOWNTYPES pFunction;
  51. PFUNCINFO pfuncinfo;
  52. #if 0
  53. #define NOTHING /* */
  54. #define IGNORED /* */
  55. #define NOPREFIX /* */
  56. #define NOSUFFIX /* */
  57. //HANDLE __stdcall MyCreateActCtx(void)
  58. //{
  59. // static HANDLE Handle = INVALID_HANDLE_VALUE;
  60. // if (Handle == INVALID_HANDLE_VALUE)
  61. // {
  62. // WCHAR PathToManifest[MAX_PATH];
  63. // ACTCTXW ActCtx = {sizeof(ActCtx)};
  64. // SearchPathW(NULL, L"shell32.dll", NULL, NUMBER_OF(PathToManifest), PathToManifest, NULL);
  65. // ActCtx.lpSource = PathToManifest;
  66. // Handle = CreateActCtxW(&ActCtx);
  67. // if (Handle == INVALID_HANDLE_VALUE)
  68. // goto Exit;
  69. // }
  70. //Exit:
  71. // return Handle;
  72. //}
  73. //BOOL MyLoadLibraryOrGetModuleHandle(PCWSTR name, HMODULE* Module)
  74. //{
  75. // static HMODULE StaticModule = NULL;
  76. // HANDLE ActivationContext;
  77. // BOOL Success = FALSE;
  78. // ULONG Cookie = 0;
  79. // DWORD Error = NO_ERROR;
  80. // *Module = NULL;
  81. // if (StaticModule != NULL)
  82. // {
  83. // *Module = StaticModule;
  84. // Success = TRUE;
  85. // goto Exit;
  86. // }
  87. // ActivationContext = MyCreateActCtx();
  88. // if (ActivationContext == INVALID_HANDLE_VALUE)
  89. // goto Exit;
  90. // ActivateActCtx(ActivationContext, &Cookie);
  91. // *Module = LoadLibraryW(L"comctl32.dll");
  92. // if (*Module == NULL)
  93. // goto Exit;
  94. // Success = TRUE;
  95. //Exit:
  96. // if (!Success && Error == NO_ERROR)
  97. // Error = GetLastError();
  98. // if (Cookie != 0)
  99. // {
  100. // if (!DeactivateActCtx(Cookie))
  101. // { // ?
  102. // if (Success)
  103. // {
  104. // Success = FALSE;
  105. // Error = GetLastError();
  106. // }
  107. // }
  108. // }
  109. // if (!Success)
  110. // SetLastError(Error);
  111. // return Success;
  112. //}
  113. //BOOL Patch(PCSTR ProcName, FARPROC* ProcAddress)
  114. //{
  115. // HMODULE Module = NULL;
  116. // BOOL Success = FALSE;
  117. // *ProcAddress = NULL;
  118. // Success = MyLoadLibraryOrGetModuleHandle(L"comctl32.dll", &Module);
  119. // if (!Success)
  120. // goto Exit;
  121. // *ProcAddress = GetProcAddress(Module, ProcName);
  122. // if (*ProcAddress == NULL)
  123. // goto Exit;
  124. // Success = TRUE;
  125. //Exit:
  126. // return Success;
  127. //}
  128. //#define DECLARE(ret, call, name, argNamesTypes, argNames, importType, importExtra, onError) \
  129. // ret (call* name) argNamesTypes ;
  130. //#define DEFINE(ret, call, name, argNamesTypes, argNames, importType, importExtra, onError) \
  131. //static ret call FIRST(name) argNamesTypes \
  132. //{ \
  133. // static DWORD Error = NO_ERROR; \
  134. // if (Error != NO_ERROR) \
  135. // { \
  136. // onError(Error); \
  137. // } \
  138. // if (!Patch(importType(importExtra), (FARPROC*)&name)) \
  139. // { \
  140. // Error = GetLastError(); \
  141. // onError(Error); \
  142. // } \
  143. // return name argNames; \
  144. //} \
  145. //ret (call* name) argNamesTypes = FIRST(name);
  146. //#define IMPORT_BY_NAME(name, extra) (#name)
  147. //#define IMPORT_BY_ORDINAL(name, extra) ((const char*)(ULONG_PTR)extra)
  148. //#define COMCTL_FUNCTIONS \
  149. //COMCTL_FUNCTION(HRESULT, __stdcall, UninitializeFlatSB, (HWND _noname0), (_noname0), IMPORT_BY_NAME, IGNORED) \
  150. //COMCTL_FUNCTION(BOOL, __stdcall, InitializeFlatSB, (HWND _noname0), (_noname0), IMPORT_BY_ORDINAL, 1)
  151. //#define COMCTL_FUNCTION(ret, call, name, argNamesTypes, argNames, importType, importExtra, onError) \
  152. // DECLARE(ret, call, name, argNamesTypes, argNames, importType, importExtra, onError)
  153. //COMCTL_FUNCTIONS
  154. // HWND _noname0,
  155. //)
  156. DumpLib(PCWSTR filename)
  157. {
  158. CreateFileW(filename, GENERIC_READ, FILE_SHARE_READ, NULL
  159. }
  160. #endif
  161. void DumpFunctionDeclarationsHeader(void)
  162. {
  163. //PKNOWNTYPES pFunction;
  164. //PFUNCINFO pfuncinfo;
  165. cout << "///////////////////////////////////////////\n";
  166. cout << "// This file is autogenerated by gencomctlt. \n";
  167. cout << "// Do not edit \n";
  168. cout << "///////////////////////////////////////////\n";
  169. cout << '\n' << '\n';
  170. cout << "#include \"windows.h\"\n";
  171. cout << "#include \"commctrl.h\"\n\n";
  172. cout << "///////////////////////////////////////////\n";
  173. cout << "// Functions //\n";
  174. cout << "///////////////////////////////////////////\n";
  175. for (
  176. pFunction = pFunctions->pLastNodeInserted;
  177. pFunction != NULL
  178. && pFunction->TypeName != NULL
  179. && strcmp(pFunction->TypeName, "MarkerFunction_8afccfaa_27e7_45d5_8ff7_7ac0b970789d") != 0 ;
  180. pFunction = pFunction->Next)
  181. {
  182. /*
  183. for now, just like print out commctrl as a demo/test of understanding the tool
  184. tomorrow, print out what we actually need
  185. */
  186. #if 1
  187. cout << pFunction->FuncRet << ' ';
  188. cout << pFunction->FuncMod << ' '; // __stdcall
  189. cout << pFunction->TypeName << "(\n"; // function name
  190. pfuncinfo = pFunction->pfuncinfo;
  191. if (pfuncinfo == NULL || pfuncinfo->sType == NULL || pfuncinfo->sName == NULL)
  192. {
  193. cout << "void";
  194. }
  195. else
  196. {
  197. for ( ; pfuncinfo != NULL ; pfuncinfo = pfuncinfo->pfuncinfoNext )
  198. {
  199. cout << ' ' << pfuncinfo->sType << ' ' << pfuncinfo->sName << ",\n";
  200. }
  201. }
  202. cout << ")\n";
  203. #endif
  204. }
  205. cout << '\n' << '\n';
  206. }
  207. int __cdecl main(int argc, char*argv[])
  208. {
  209. ExtractCVMHeader(MapPpmFile(argv[1], TRUE));
  210. DumpFunctionDeclarationsHeader();
  211. return 0;
  212. }