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.

194 lines
4.5 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLBASE_H__
  11. #error atlimpl.cpp requires atlbase.h to be included first
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Minimize CRT
  15. // Specify DllMain as EntryPoint
  16. // Turn off exception handling
  17. // Define _ATL_MIN_CRT
  18. #ifdef _ATL_MIN_CRT
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Startup Code
  21. #if defined(_WINDLL) || defined(_USRDLL)
  22. // Declare DllMain
  23. extern "C" BOOL WINAPI DllMain(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved);
  24. extern "C" BOOL WINAPI _DllMainCRTStartup(HANDLE hDllHandle, DWORD dwReason, LPVOID lpReserved)
  25. {
  26. return DllMain(hDllHandle, dwReason, lpReserved);
  27. }
  28. #else
  29. // wWinMain is not defined in winbase.h.
  30. extern "C" int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd);
  31. #define SPACECHAR _T(' ')
  32. #define DQUOTECHAR _T('\"')
  33. #ifdef _UNICODE
  34. extern "C" void wWinMainCRTStartup()
  35. #else // _UNICODE
  36. extern "C" void WinMainCRTStartup()
  37. #endif // _UNICODE
  38. {
  39. LPTSTR lpszCommandLine = ::GetCommandLine();
  40. if(lpszCommandLine == NULL)
  41. ::ExitProcess((UINT)-1);
  42. // Skip past program name (first token in command line).
  43. // Check for and handle quoted program name.
  44. if(*lpszCommandLine == DQUOTECHAR)
  45. {
  46. // Scan, and skip over, subsequent characters until
  47. // another double-quote or a null is encountered.
  48. do
  49. {
  50. lpszCommandLine = ::CharNext(lpszCommandLine);
  51. }
  52. while((*lpszCommandLine != DQUOTECHAR) && (*lpszCommandLine != _T('\0')));
  53. // If we stopped on a double-quote (usual case), skip over it.
  54. if(*lpszCommandLine == DQUOTECHAR)
  55. lpszCommandLine = ::CharNext(lpszCommandLine);
  56. }
  57. else
  58. {
  59. while(*lpszCommandLine > SPACECHAR)
  60. lpszCommandLine = ::CharNext(lpszCommandLine);
  61. }
  62. // Skip past any white space preceeding the second token.
  63. while(*lpszCommandLine && (*lpszCommandLine <= SPACECHAR))
  64. lpszCommandLine = ::CharNext(lpszCommandLine);
  65. STARTUPINFO StartupInfo;
  66. StartupInfo.dwFlags = 0;
  67. ::GetStartupInfo(&StartupInfo);
  68. int nRet = _tWinMain(::GetModuleHandle(NULL), NULL, lpszCommandLine,
  69. (StartupInfo.dwFlags & STARTF_USESHOWWINDOW) ?
  70. StartupInfo.wShowWindow : SW_SHOWDEFAULT);
  71. ::ExitProcess((UINT)nRet);
  72. }
  73. #endif // defined(_WINDLL) | defined(_USRDLL)
  74. /////////////////////////////////////////////////////////////////////////////
  75. // Heap Allocation
  76. #ifndef _DEBUG
  77. #ifndef _MERGE_PROXYSTUB
  78. //rpcproxy.h does the same thing as this
  79. int __cdecl _purecall()
  80. {
  81. DebugBreak();
  82. return 0;
  83. }
  84. #endif
  85. #if !defined(_M_ALPHA) && !defined(_M_PPC)
  86. //RISC always initializes floating point and always defines _fltused
  87. extern "C" const int _fltused = 0;
  88. #endif
  89. static const int nExtraAlloc = 8;
  90. static const int nOffsetBlock = nExtraAlloc/sizeof(HANDLE);
  91. void* __cdecl malloc(size_t n)
  92. {
  93. void* pv = NULL;
  94. #ifndef _ATL_NO_MP_HEAP
  95. if (_Module.m_phHeaps == NULL)
  96. #endif
  97. {
  98. pv = (HANDLE*) HeapAlloc(_Module.m_hHeap, 0, n);
  99. }
  100. #ifndef _ATL_NO_MP_HEAP
  101. else
  102. {
  103. // overallocate to remember the heap handle
  104. int nHeap = _Module.m_nHeap++;
  105. HANDLE hHeap = _Module.m_phHeaps[nHeap & _Module.m_dwHeaps];
  106. HANDLE* pBlock = (HANDLE*) HeapAlloc(hHeap, 0, n + nExtraAlloc);
  107. if (pBlock != NULL)
  108. {
  109. *pBlock = hHeap;
  110. pv = (void*)(pBlock + nOffsetBlock);
  111. }
  112. else
  113. pv = NULL;
  114. }
  115. #endif
  116. return pv;
  117. }
  118. void* __cdecl calloc(size_t n, size_t s)
  119. {
  120. return malloc(n*s);
  121. }
  122. void* __cdecl realloc(void* p, size_t n)
  123. {
  124. if (p == NULL)
  125. return malloc(n);
  126. #ifndef _ATL_NO_MP_HEAP
  127. if (_Module.m_phHeaps == NULL)
  128. #endif
  129. return HeapReAlloc(_Module.m_hHeap, 0, p, n);
  130. #ifndef _ATL_NO_MP_HEAP
  131. else
  132. {
  133. HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
  134. pHeap = (HANDLE*) HeapReAlloc(*pHeap, 0, pHeap, n + nExtraAlloc);
  135. return (pHeap != NULL) ? pHeap + nOffsetBlock : NULL;
  136. }
  137. #endif
  138. }
  139. void __cdecl free(void* p)
  140. {
  141. if (p == NULL)
  142. return;
  143. #ifndef _ATL_NO_MP_HEAP
  144. if (_Module.m_phHeaps == NULL)
  145. #endif
  146. HeapFree(_Module.m_hHeap, 0, p);
  147. #ifndef _ATL_NO_MP_HEAP
  148. else
  149. {
  150. HANDLE* pHeap = ((HANDLE*)p)-nOffsetBlock;
  151. HeapFree(*pHeap, 0, pHeap);
  152. }
  153. #endif
  154. }
  155. void* __cdecl operator new(size_t n)
  156. {
  157. return malloc(n);
  158. }
  159. void __cdecl operator delete(void* p)
  160. {
  161. free(p);
  162. }
  163. #endif //_DEBUG
  164. #endif //_ATL_MIN_CRT