Leaked source code of windows server 2003
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.

953 lines
18 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: certutil.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <pch.cpp>
  11. #pragma hdrstop
  12. #include <locale.h>
  13. #include <io.h>
  14. #include <fcntl.h>
  15. #include "clibres.h"
  16. #include "setupids.h"
  17. #include "res.h"
  18. #include "csresstr.h"
  19. #define __dwFILE__ __dwFILE_CERTLOG_CERTLOG_CPP__
  20. #define WM_DOCERTLOGMAIN WM_USER+0
  21. WCHAR const wszAppName[] = L"CertLogApp";
  22. WCHAR const *g_pwszProg = L"CertLog";
  23. HINSTANCE g_hInstance;
  24. #define _SYMENTRY(def) { #def, def }
  25. typedef struct _SYMENTRY
  26. {
  27. char const *pszSymbol;
  28. DWORD symno;
  29. } SYMENTRY;
  30. SYMENTRY g_fnmap[] = {
  31. #include "csfile2.h"
  32. };
  33. SYMENTRY g_resmap[] = {
  34. #include "csres2.h"
  35. };
  36. char s_szFilePrefix[] = "__dwFILE_";
  37. DWORD
  38. GetNumber(
  39. IN WCHAR wcTerm,
  40. IN OUT WCHAR **ppwsz)
  41. {
  42. WCHAR *pwsz = *ppwsz;
  43. DWORD dw = _wtoi(pwsz);
  44. DWORD dwRet = MAXDWORD;
  45. if (iswdigit(*pwsz))
  46. {
  47. while (iswdigit(*pwsz))
  48. {
  49. pwsz++;
  50. }
  51. if (wcTerm == *pwsz)
  52. {
  53. dwRet = dw;
  54. *ppwsz = &pwsz[1];
  55. }
  56. }
  57. return(dwRet);
  58. }
  59. // Turn "__dwFILE_CERTLOG_CERTLOG_CPP__" into "certlog\certlog.cpp"
  60. char *
  61. FormatFileName(
  62. IN char const *pszFileIn)
  63. {
  64. HRESULT hr;
  65. char *pszFileOut = NULL;
  66. char *pch;
  67. if (0 == _strnicmp(pszFileIn, s_szFilePrefix, SZARRAYSIZE(s_szFilePrefix)))
  68. {
  69. pszFileIn += SZARRAYSIZE(s_szFilePrefix);
  70. }
  71. hr = myDupStringA(pszFileIn, &pszFileOut);
  72. _JumpIfError(hr, error, "myDupStringA");
  73. pch = &pszFileOut[strlen(pszFileOut)];
  74. while (--pch >= pszFileOut && *pch == '_')
  75. {
  76. *pch = '\0';
  77. }
  78. pch = strrchr(pszFileOut, '_');
  79. *pch = '.';
  80. while (TRUE)
  81. {
  82. pch = strchr(pszFileOut, '_');
  83. if (NULL == pch)
  84. {
  85. break;
  86. }
  87. *pch = '\\';
  88. }
  89. _strlwr(pszFileOut);
  90. error:
  91. return(pszFileOut);
  92. }
  93. SYMENTRY const *
  94. FindSymbol(
  95. IN DWORD symno,
  96. IN SYMENTRY const *psym,
  97. IN DWORD csym)
  98. {
  99. SYMENTRY const *psymEnd = &psym[csym];
  100. for ( ; psym < psymEnd; psym++)
  101. {
  102. if (psym->symno == symno)
  103. {
  104. return(psym);
  105. }
  106. }
  107. return(NULL);
  108. }
  109. VOID
  110. ProcessLine(
  111. IN char const *pszLine)
  112. {
  113. HRESULT hr;
  114. WCHAR *pwszLine = NULL;
  115. char *pszFile = NULL;
  116. DWORD fileno;
  117. DWORD lineno;
  118. DWORD resno;
  119. SYMENTRY const *psym;
  120. WCHAR *pwsz;
  121. if (!myConvertSzToWsz(&pwszLine, pszLine, -1))
  122. {
  123. hr = E_OUTOFMEMORY;
  124. _JumpError(hr, error, "myConvertSzToWsz");
  125. }
  126. pwsz = pwszLine;
  127. fileno = GetNumber(L'.', &pwsz);
  128. lineno = GetNumber(L'.', &pwsz);
  129. resno = GetNumber(L':', &pwsz);
  130. if (MAXDWORD != fileno && MAXDWORD != lineno && MAXDWORD != resno)
  131. {
  132. while (L' ' == *pwsz)
  133. {
  134. pwsz++;
  135. }
  136. if (0 == fileno)
  137. {
  138. // "0.resno.resno: "
  139. psym = FindSymbol(lineno, g_resmap, ARRAYSIZE(g_resmap));
  140. if (NULL != psym)
  141. {
  142. wprintf(L"%hs: ", psym->pszSymbol);
  143. }
  144. else
  145. {
  146. pwsz = pwszLine; // give up
  147. }
  148. }
  149. else
  150. {
  151. // "fileno.lineno.resno: "
  152. psym = FindSymbol(fileno, g_fnmap, ARRAYSIZE(g_fnmap));
  153. if (NULL != psym)
  154. {
  155. pszFile = FormatFileName(psym->pszSymbol);
  156. wprintf(
  157. L"%hs(%u): ",
  158. NULL != pszFile?
  159. pszFile : &psym->pszSymbol[SZARRAYSIZE(s_szFilePrefix)],
  160. lineno);
  161. }
  162. else
  163. {
  164. pwsz = pwszLine; // give up
  165. }
  166. }
  167. }
  168. else
  169. {
  170. pwsz = pwszLine;
  171. }
  172. if (pwsz > pwszLine && 0 != resno)
  173. {
  174. psym = FindSymbol(resno, g_resmap, ARRAYSIZE(g_resmap));
  175. psym = FindSymbol(resno, g_resmap, ARRAYSIZE(g_resmap));
  176. if (NULL != psym)
  177. {
  178. wprintf(L"%hs: ", psym->pszSymbol);
  179. }
  180. else
  181. {
  182. wprintf(L"%u: ", resno);
  183. }
  184. }
  185. wprintf(L"%ws\n", pwsz);
  186. error:
  187. if (NULL != pszFile)
  188. {
  189. LocalFree(pszFile);
  190. }
  191. if (NULL != pwszLine)
  192. {
  193. LocalFree(pwszLine);
  194. }
  195. }
  196. #define ISNEWLINECHAR(ch) ('\r' == (ch) || '\n' == (ch))
  197. char *
  198. myfgets(
  199. OUT char *buf,
  200. IN DWORD cch,
  201. IN FILE *pf)
  202. {
  203. char *psz = fgets(buf, cch, pf);
  204. if (NULL != psz)
  205. {
  206. char *pch = &psz[strlen(psz)];
  207. while (--pch >= psz && ISNEWLINECHAR(*pch))
  208. {
  209. *pch = '\0';
  210. }
  211. }
  212. return(psz);
  213. }
  214. char *g_apszColumn[150];
  215. char *g_apszColumnDisplay[150];
  216. DWORD g_cColumn = 0;
  217. HRESULT
  218. SaveColumnNames(
  219. IN char const *psz)
  220. {
  221. HRESULT hr;
  222. char const *pszStart;
  223. char const *pszEnd;
  224. char *pszAlloc;
  225. DWORD cch;
  226. while (' ' == *psz)
  227. {
  228. psz++;
  229. }
  230. pszStart = psz;
  231. while ('\0' != *psz && ' ' != *psz)
  232. {
  233. psz++;
  234. }
  235. cch = SAFE_SUBTRACT_POINTERS(psz, pszStart);
  236. pszAlloc = (char *) LocalAlloc(LMEM_FIXED, cch + 1);
  237. if (NULL == pszAlloc)
  238. {
  239. hr = E_OUTOFMEMORY;
  240. _JumpError(hr, error, "LocalAlloc");
  241. }
  242. g_apszColumn[g_cColumn] = pszAlloc;
  243. CopyMemory(pszAlloc, pszStart, cch);
  244. pszAlloc[cch] = '\0';
  245. while (' ' == *psz)
  246. {
  247. psz++;
  248. }
  249. pszEnd = strstr(psz, " ");
  250. if (NULL == pszEnd)
  251. {
  252. hr = E_INVALIDARG;
  253. _JumpError(hr, error, "strstr");
  254. }
  255. while (psz < pszEnd && ' ' == *pszEnd)
  256. {
  257. pszEnd--;
  258. }
  259. cch = SAFE_SUBTRACT_POINTERS(pszEnd, psz) + 1;
  260. pszAlloc = (char *) LocalAlloc(LMEM_FIXED, cch + 1);
  261. if (NULL == pszAlloc)
  262. {
  263. hr = E_OUTOFMEMORY;
  264. _JumpError(hr, error, "LocalAlloc");
  265. }
  266. g_apszColumnDisplay[g_cColumn] = pszAlloc;
  267. CopyMemory(pszAlloc, psz, cch);
  268. pszAlloc[cch] = '\0';
  269. //wprintf(L"Col[%u] = %hs '%hs'\n", g_cColumn, g_apszColumn[g_cColumn], g_apszColumnDisplay[g_cColumn]);
  270. g_cColumn++;
  271. hr = S_OK;
  272. error:
  273. return(hr);
  274. }
  275. BOOL
  276. ConvertHexToDecimal(
  277. IN char const *psz,
  278. OUT char *pch,
  279. OUT DWORD cch)
  280. {
  281. HRESULT hr;
  282. BOOL fValid = FALSE;
  283. WCHAR *pwsz = NULL;
  284. WCHAR *pwszDecimal;
  285. int i;
  286. int j;
  287. if ('0' == psz[0] && 'x' == psz[1])
  288. {
  289. if (!myConvertSzToWsz(&pwsz, psz, -1))
  290. {
  291. hr = E_OUTOFMEMORY;
  292. _JumpError(hr, error, "myConvertSzToWsz");
  293. }
  294. pwszDecimal = wcschr(pwsz, L' ');
  295. if (NULL != pwszDecimal)
  296. {
  297. *pwszDecimal++ = L'\0';
  298. }
  299. i = myWtoI(pwsz, &fValid);
  300. if (fValid)
  301. {
  302. if (-1 == _snprintf(pch, cch, "%u", i))
  303. {
  304. fValid = FALSE;
  305. }
  306. else if (NULL != pwszDecimal)
  307. {
  308. fValid = FALSE;
  309. if (wcLPAREN == *pwszDecimal)
  310. {
  311. WCHAR *pwc;
  312. pwszDecimal++;
  313. pwc = wcschr(pwszDecimal, wcRPAREN);
  314. if (NULL != pwc && L'\0' == pwc[1])
  315. {
  316. *pwc = L'\0';
  317. j = myWtoI(pwszDecimal, &fValid);
  318. if (i != j)
  319. {
  320. fValid = FALSE;
  321. }
  322. }
  323. }
  324. }
  325. }
  326. }
  327. error:
  328. if (NULL != pwsz)
  329. {
  330. LocalFree(pwsz);
  331. }
  332. return(fValid);
  333. }
  334. HRESULT
  335. ReformatView(
  336. IN WCHAR const *pwszfn)
  337. {
  338. HRESULT hr;
  339. char buf[1024];
  340. FILE *pf = NULL;
  341. DWORD i;
  342. char *pszRowPrefix = NULL;
  343. DWORD cchRowPrefix;
  344. BOOL fFirstLine;
  345. pf = _wfopen(pwszfn, L"r");
  346. if (NULL == pf)
  347. {
  348. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  349. _JumpError(hr, error, "fopen");
  350. }
  351. fFirstLine = TRUE;
  352. while (TRUE)
  353. {
  354. WCHAR *pwszSchema = NULL;
  355. if (NULL == myfgets(buf, sizeof(buf), pf))
  356. {
  357. hr = E_INVALIDARG;
  358. _JumpError(hr, error, "myfgets(Schema:)");
  359. }
  360. if (!myConvertSzToWsz(&pwszSchema, buf, -1))
  361. {
  362. hr = E_OUTOFMEMORY;
  363. _JumpError(hr, error, "myConvertSzToWsz");
  364. }
  365. if (0 == LSTRCMPIS(pwszSchema, L"Schema:"))
  366. {
  367. LocalFree(pwszSchema);
  368. break;
  369. }
  370. LocalFree(pwszSchema);
  371. pwszSchema = NULL;
  372. if (fFirstLine)
  373. {
  374. char const *psz;
  375. psz = strchr(buf, ':');
  376. if (NULL != psz && '\0' == psz[1])
  377. {
  378. break;
  379. }
  380. }
  381. fFirstLine = FALSE;
  382. }
  383. if (NULL == myfgets(buf, sizeof(buf), pf) ||
  384. NULL == myfgets(buf, sizeof(buf), pf) ||
  385. NULL == strstr(buf, "-----------------"))
  386. {
  387. hr = E_INVALIDARG;
  388. _JumpError(hr, error, "myfgets(schema header)");
  389. }
  390. while (NULL != myfgets(buf, sizeof(buf), pf))
  391. {
  392. if (L'\0' == buf[0])
  393. {
  394. break;
  395. }
  396. hr = SaveColumnNames(buf);
  397. _JumpIfError(hr, error, "SaveColumnNames");
  398. }
  399. wprintf(L"Row");
  400. for (i = 0; i < g_cColumn; i++)
  401. {
  402. wprintf(L"\t%hs", g_apszColumn[i]);
  403. }
  404. wprintf(L"\n");
  405. while (TRUE)
  406. {
  407. BOOL fEOF = FALSE;
  408. static char s_BlankPrefix[] = " ";
  409. static char s_Begin[] = "-----BEGIN ";
  410. static char s_End[] = "-----END ";
  411. while (TRUE)
  412. {
  413. if (NULL == myfgets(buf, sizeof(buf), pf))
  414. {
  415. fEOF = TRUE;
  416. break;
  417. }
  418. if (NULL == pszRowPrefix)
  419. {
  420. char *psz;
  421. psz = strchr(buf, ' ');
  422. if (NULL == psz || psz == buf || !isdigit(psz[1]))
  423. {
  424. continue;
  425. }
  426. psz++;
  427. cchRowPrefix = SAFE_SUBTRACT_POINTERS(psz, buf);
  428. pszRowPrefix = (char *) LocalAlloc(LMEM_FIXED, cchRowPrefix + 1);
  429. if (NULL == pszRowPrefix)
  430. {
  431. hr = E_OUTOFMEMORY;
  432. _JumpError(hr, error, "LocalAlloc");
  433. }
  434. CopyMemory(pszRowPrefix, buf, cchRowPrefix);
  435. pszRowPrefix[cchRowPrefix] = '\0';
  436. }
  437. if (0 == _strnicmp(pszRowPrefix, buf, cchRowPrefix) &&
  438. isdigit(buf[cchRowPrefix]))
  439. {
  440. wprintf(L"%u", atoi(&buf[cchRowPrefix]));
  441. break;
  442. }
  443. }
  444. if (fEOF)
  445. {
  446. break;
  447. }
  448. for (i = 0; i < g_cColumn; i++)
  449. {
  450. DWORD cch;
  451. char const *psz;
  452. char ach[cwcDWORDSPRINTF];
  453. BOOL fSkipRead = 0 != i;
  454. cch = strlen(g_apszColumnDisplay[i]);
  455. while (TRUE)
  456. {
  457. if (!fSkipRead && NULL == myfgets(buf, sizeof(buf), pf))
  458. {
  459. fEOF = TRUE;
  460. break;
  461. }
  462. psz = &buf[SZARRAYSIZE(s_BlankPrefix)];
  463. if (0 == strncmp(
  464. s_BlankPrefix,
  465. buf,
  466. SZARRAYSIZE(s_BlankPrefix)) &&
  467. 0 == _strnicmp(g_apszColumnDisplay[i], psz, cch) &&
  468. ':' == psz[cch])
  469. {
  470. break;
  471. }
  472. fSkipRead = FALSE;
  473. }
  474. psz += cch + 1;
  475. while (' ' == *psz)
  476. {
  477. psz++;
  478. }
  479. if ('\0' == *psz)
  480. {
  481. psz = "???";
  482. }
  483. if (ConvertHexToDecimal(psz, ach, ARRAYSIZE(ach)))
  484. {
  485. psz = ach;
  486. }
  487. wprintf(L"\t%hs", psz);
  488. if ('"' == *psz && NULL == strchr(&psz[1], '"'))
  489. {
  490. while (TRUE)
  491. {
  492. if (NULL == myfgets(buf, sizeof(buf), pf))
  493. {
  494. break;
  495. }
  496. wprintf(L" %hs", buf);
  497. if (NULL != strchr(buf, '"'))
  498. {
  499. break;
  500. }
  501. }
  502. }
  503. else
  504. {
  505. BOOL fBase64 = FALSE;
  506. while (TRUE)
  507. {
  508. if (NULL == myfgets(buf, sizeof(buf), pf))
  509. {
  510. break;
  511. }
  512. if ('\0' == buf[0])
  513. {
  514. break;
  515. }
  516. if (i + 1 < g_cColumn)
  517. {
  518. psz = &buf[SZARRAYSIZE(s_BlankPrefix)];
  519. cch = strlen(g_apszColumnDisplay[i + 1]);
  520. if (0 == strncmp(
  521. s_BlankPrefix,
  522. buf,
  523. SZARRAYSIZE(s_BlankPrefix)) &&
  524. 0 == _strnicmp(
  525. g_apszColumnDisplay[i + 1],
  526. psz,
  527. cch) &&
  528. ':' == psz[cch])
  529. {
  530. break;
  531. }
  532. }
  533. if (!fBase64 &&
  534. 0 == _strnicmp(s_Begin, buf, SZARRAYSIZE(s_Begin)))
  535. {
  536. fBase64 = TRUE;
  537. }
  538. else if (fBase64 &&
  539. 0 == _strnicmp(s_End, buf, SZARRAYSIZE(s_End)))
  540. {
  541. fBase64 = FALSE;
  542. continue;
  543. }
  544. if (!fBase64)
  545. {
  546. psz = buf;
  547. while (' ' == *psz)
  548. {
  549. psz++;
  550. }
  551. wprintf(L" %hs", psz);
  552. }
  553. }
  554. }
  555. }
  556. wprintf(L"\n");
  557. }
  558. if (ferror(pf))
  559. {
  560. hr = STG_E_READFAULT;
  561. _JumpError(hr, error, "ferror");
  562. }
  563. hr = S_OK;
  564. error:
  565. if (NULL != pf)
  566. {
  567. fclose(pf);
  568. }
  569. for (i = 0; i < g_cColumn; i++)
  570. {
  571. if (NULL != g_apszColumn[i])
  572. {
  573. LocalFree(g_apszColumn[i]);
  574. }
  575. if (NULL != g_apszColumnDisplay[i])
  576. {
  577. LocalFree(g_apszColumnDisplay[i]);
  578. }
  579. }
  580. if (NULL != pszRowPrefix)
  581. {
  582. LocalFree(pszRowPrefix);
  583. }
  584. return(hr);
  585. }
  586. HRESULT
  587. ReformatLog(
  588. IN WCHAR const *pwszfn)
  589. {
  590. HRESULT hr;
  591. char buf[1024];
  592. FILE *pf = NULL;
  593. if (0 == lstrcmpi(pwszfn, L"-"))
  594. {
  595. pf = stdout;
  596. }
  597. else
  598. {
  599. pf = _wfopen(pwszfn, L"r");
  600. if (NULL == pf)
  601. {
  602. hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  603. _JumpError(hr, error, "fopen");
  604. }
  605. }
  606. while (NULL != myfgets(buf, sizeof(buf), pf))
  607. {
  608. ProcessLine(buf);
  609. }
  610. if (ferror(pf))
  611. {
  612. hr = STG_E_READFAULT;
  613. _JumpError(hr, error, "ferror");
  614. }
  615. hr = S_OK;
  616. error:
  617. if (NULL != pf && stdout != pf)
  618. {
  619. fclose(pf);
  620. }
  621. return(hr);
  622. }
  623. HRESULT
  624. ArgvMain(
  625. int argc,
  626. WCHAR *argv[],
  627. HWND hWndOwner)
  628. {
  629. HRESULT hr;
  630. BOOL fView = FALSE;
  631. if (1 < argc &&
  632. myIsSwitchChar(argv[1][0]) &&
  633. 0 == LSTRCMPIS(&argv[1][1], L"view"))
  634. {
  635. fView = TRUE;
  636. }
  637. if ((!fView && 2 != argc) || (fView && 3 != argc))
  638. {
  639. wprintf(L"Usage: CertLog [-view] <LogFile>\n");
  640. hr = E_INVALIDARG;
  641. _JumpError(hr, error, "Usage");
  642. }
  643. if (fView)
  644. {
  645. hr = ReformatView(argv[2]);
  646. _JumpIfError(hr, error, "ReformatView");
  647. }
  648. else
  649. {
  650. hr = ReformatLog(argv[1]);
  651. _JumpIfError(hr, error, "ReformatLog");
  652. }
  653. error:
  654. return(hr);
  655. }
  656. //**************************************************************************
  657. // FUNCTION: CertLogPreMain
  658. // NOTES: Based on MkRootMain function; takes an LPSTR command line and
  659. // chews it up into argc/argv form so that it can be passed on to
  660. // a traditional C style main.
  661. //**************************************************************************
  662. #define ISBLANK(wc) (L' ' == (wc) || L'\t' == (wc))
  663. HRESULT
  664. CertLogPreMain(
  665. WCHAR const *pwszCmdLine,
  666. HWND hWndOwner)
  667. {
  668. HRESULT hr;
  669. WCHAR *pbuf;
  670. WCHAR *apszArg[20];
  671. int cArg = 0;
  672. WCHAR *p;
  673. WCHAR const *pchQuote;
  674. WCHAR **prgpwszExeName = NULL;
  675. int carg;
  676. pbuf = (WCHAR *) LocalAlloc(
  677. LMEM_FIXED,
  678. (wcslen(pwszCmdLine) + 1) * sizeof(WCHAR));
  679. if (NULL == pbuf)
  680. {
  681. hr = E_OUTOFMEMORY;
  682. _JumpError(hr, error, "LocalAlloc");
  683. }
  684. p = pbuf;
  685. apszArg[cArg++] = TEXT("CertLog");
  686. while (*pwszCmdLine != TEXT('\0'))
  687. {
  688. while (ISBLANK(*pwszCmdLine))
  689. {
  690. pwszCmdLine++;
  691. }
  692. if (*pwszCmdLine != TEXT('\0'))
  693. {
  694. apszArg[cArg++] = p;
  695. if (sizeof(apszArg)/sizeof(apszArg[0]) <= cArg)
  696. {
  697. hr = E_INVALIDARG;
  698. _JumpError(hr, error, "Too many args");
  699. }
  700. pchQuote = NULL;
  701. while (*pwszCmdLine != L'\0')
  702. {
  703. if (NULL != pchQuote)
  704. {
  705. if (*pwszCmdLine == *pchQuote)
  706. {
  707. pwszCmdLine++;
  708. pchQuote = NULL;
  709. continue;
  710. }
  711. }
  712. else
  713. {
  714. if (ISBLANK(*pwszCmdLine))
  715. {
  716. break;
  717. }
  718. if (L'"' == *pwszCmdLine)
  719. {
  720. pchQuote = pwszCmdLine++;
  721. continue;
  722. }
  723. }
  724. *p++ = *pwszCmdLine++;
  725. }
  726. *p++ = TEXT('\0');
  727. if (*pwszCmdLine != TEXT('\0'))
  728. {
  729. pwszCmdLine++; // skip whitespace or quote character
  730. }
  731. }
  732. }
  733. apszArg[cArg] = NULL;
  734. hr = ArgvMain(cArg, apszArg, hWndOwner);
  735. _JumpIfError(hr, error, "ArgvMain");
  736. error:
  737. if (NULL != prgpwszExeName)
  738. {
  739. GlobalFree(prgpwszExeName);
  740. }
  741. if (NULL != pbuf)
  742. {
  743. LocalFree(pbuf);
  744. }
  745. return(hr);
  746. }
  747. //**************************************************************************
  748. // FUNCTION: MainWndProc(...)
  749. // ARGUMENTS:
  750. //**************************************************************************
  751. LRESULT APIENTRY
  752. MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  753. {
  754. int nWCharsRequired;
  755. WCHAR *pwszCmdLine = NULL;
  756. CHAR const *pszCmdLine;
  757. HRESULT hr;
  758. LRESULT lr = 0;
  759. switch (msg)
  760. {
  761. case WM_CREATE:
  762. case WM_SIZE:
  763. break;
  764. case WM_DESTROY:
  765. PostQuitMessage(0);
  766. break;
  767. case WM_DOCERTLOGMAIN:
  768. pwszCmdLine = (WCHAR*)lParam;
  769. hr = CertLogPreMain(pwszCmdLine, hWnd);
  770. PostQuitMessage(hr);
  771. break;
  772. default:
  773. lr = DefWindowProc(hWnd, msg, wParam, lParam);
  774. break;
  775. }
  776. return(lr);
  777. }
  778. //+------------------------------------------------------------------------
  779. //
  780. // Function: wWinMain()
  781. //
  782. // Synopsis: Entry Point
  783. //
  784. // Arguments: [hInstance] -- Instance handle
  785. // [hPrevInstance] -- Obsolete
  786. // [pwszCmdLine] -- App command line
  787. // [nCmdShow] -- Starting show state
  788. //
  789. // History: 12/07/96 JerryK Added this Comment
  790. //
  791. //-------------------------------------------------------------------------
  792. extern "C" int APIENTRY
  793. wWinMain(
  794. HINSTANCE hInstance,
  795. HINSTANCE hPrevInstance,
  796. LPWSTR pwszCmdLine,
  797. int nCmdShow)
  798. {
  799. MSG msg;
  800. WNDCLASS wcApp;
  801. HWND hWndMain;
  802. _setmode(_fileno(stdout), _O_TEXT);
  803. _wsetlocale(LC_ALL, L".OCP");
  804. mySetThreadUILanguage(0);
  805. // Save the current instance
  806. g_hInstance = hInstance;
  807. // Set up the application's window class
  808. wcApp.style = 0;
  809. wcApp.lpfnWndProc = MainWndProc;
  810. wcApp.cbClsExtra = 0;
  811. wcApp.cbWndExtra = 0;
  812. wcApp.hInstance = hInstance;
  813. wcApp.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  814. wcApp.hCursor = LoadCursor(NULL,IDC_ARROW);
  815. wcApp.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  816. wcApp.lpszMenuName = NULL;
  817. wcApp.lpszClassName = wszAppName;
  818. if (!RegisterClass(&wcApp))
  819. {
  820. return(FALSE);
  821. }
  822. // Create Main Window
  823. hWndMain = CreateWindow(
  824. wszAppName,
  825. L"CertLog Application",
  826. WS_OVERLAPPEDWINDOW,
  827. CW_USEDEFAULT, CW_USEDEFAULT,
  828. CW_USEDEFAULT, CW_USEDEFAULT,
  829. NULL,
  830. NULL,
  831. hInstance,
  832. NULL);
  833. if (NULL == hWndMain)
  834. {
  835. return(FALSE);
  836. }
  837. // Make window visible
  838. // ShowWindow(hWndMain, nCmdShow);
  839. // Update window client area
  840. UpdateWindow(hWndMain);
  841. // Send off the message to get things started
  842. PostMessage(hWndMain, WM_DOCERTLOGMAIN, 0, (LPARAM) pwszCmdLine);
  843. // Message Loop
  844. while (GetMessage(&msg, NULL, 0, 0))
  845. {
  846. TranslateMessage(&msg);
  847. DispatchMessage(&msg);
  848. }
  849. myRegisterMemDump();
  850. return((int) msg.wParam);
  851. }