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.

130 lines
2.8 KiB

  1. /***************************************************************************
  2. * VER.C
  3. *
  4. * Code specific to the DLL version of VER which contains the Windows
  5. * procedures necessary to make it work
  6. *
  7. ***************************************************************************/
  8. #include "verpriv.h"
  9. #include <diamondd.h>
  10. #include "mydiam.h"
  11. /* LibMain
  12. * Called by DLL startup code.
  13. * Initializes VER.DLL.
  14. */
  15. #ifdef LOG_DATA
  16. typedef struct {
  17. DWORD idThd;
  18. char szMsg[4];
  19. DWORD dwLine;
  20. DWORD dwData;
  21. } LOGLINE;
  22. typedef LOGLINE *PLOGLINE;
  23. #define CLOG_MAX 16384
  24. LOGLINE llLogBuff[CLOG_MAX];
  25. int illLogPtr = 0;
  26. CRITICAL_SECTION csLog;
  27. void LogThisData( DWORD id, char *szMsg, DWORD dwLine, DWORD dwData ) {
  28. PLOGLINE pll;
  29. EnterCriticalSection(&csLog);
  30. pll = &llLogBuff[illLogPtr++];
  31. if (illLogPtr >= CLOG_MAX)
  32. illLogPtr = 0;
  33. LeaveCriticalSection(&csLog);
  34. pll->idThd = id;
  35. pll->dwData = dwData;
  36. pll->dwLine = dwLine;
  37. CopyMemory( pll->szMsg, szMsg, sizeof(pll->szMsg) );
  38. }
  39. #endif
  40. HANDLE hInst;
  41. extern HINSTANCE hLz32;
  42. extern HINSTANCE hCabinet;
  43. DWORD itlsDiamondContext = ITLS_ERROR; // Init to Error Condition
  44. INT
  45. APIENTRY
  46. LibMain(
  47. HANDLE hInstance,
  48. DWORD dwReason,
  49. LPVOID lp
  50. )
  51. {
  52. PDIAMOND_CONTEXT pdcx;
  53. UNREFERENCED_PARAMETER(lp);
  54. hInst = hInstance;
  55. #ifdef LOG_DATA
  56. {
  57. TCHAR szBuffer[80];
  58. swprintf( szBuffer, TEXT("thd[0x%08ld]: Attached to version.dll for %ld\n"), GetCurrentThreadId(), dwReason );
  59. OutputDebugString(szBuffer);
  60. }
  61. #endif
  62. switch (dwReason) {
  63. case DLL_PROCESS_ATTACH:
  64. #ifdef LOG_DATA
  65. InitializeCriticalSection(&csLog);
  66. #endif
  67. #ifdef LOG_DATA
  68. {
  69. TCHAR szBuffer[MAX_PATH];
  70. OutputDebugString(TEXT(">>>version.c: compiled ") TEXT(__DATE__) TEXT(" ") TEXT(__TIME__) TEXT("\n"));
  71. OutputDebugString(TEXT("\tProcess "));
  72. GetModuleFileName(NULL, szBuffer, sizeof(szBuffer) / sizeof(TCHAR));
  73. OutputDebugString(szBuffer);
  74. OutputDebugString(TEXT(" attached\n"));
  75. }
  76. #endif
  77. itlsDiamondContext = TlsAlloc();
  78. // Fall through to Thread Attach, since for some reason
  79. // the DLL_PROCESS_ATTACH thread does not call DLL_THREAD_ATTACH
  80. case DLL_THREAD_ATTACH:
  81. if (GotDmdTlsSlot())
  82. TlsSetValue(itlsDiamondContext, NULL);
  83. break;
  84. case DLL_PROCESS_DETACH:
  85. if (GotDmdTlsSlot()) {
  86. TlsFree(itlsDiamondContext);
  87. }
  88. if (hLz32) {
  89. FreeLibrary(hLz32);
  90. }
  91. if (hCabinet) {
  92. FreeLibrary(hCabinet);
  93. }
  94. break;
  95. }
  96. /* Return success */
  97. return 1;
  98. }