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.

166 lines
4.3 KiB

  1. // Inline functions
  2. #if !defined (_INLINES_H__INCLUDED_)
  3. #define _INLINES_H__INCLUDED_
  4. #include "debug.h"
  5. #include "imemisc.h"
  6. #ifndef DEBUG
  7. /////////////////////////////////////////////////////////////////////////////
  8. // New and Delete operator overloading
  9. /*---------------------------------------------------------------------------
  10. operator new
  11. Unicode String compare
  12. ---------------------------------------------------------------------------*/
  13. __inline void* __cdecl operator new(size_t size)
  14. {
  15. return (void*)GlobalAllocPtr(GMEM_FIXED, size);
  16. }
  17. /*---------------------------------------------------------------------------
  18. operator new
  19. Unicode String compare
  20. ---------------------------------------------------------------------------*/
  21. __inline void __cdecl operator delete(void* pv)
  22. {
  23. if (pv)
  24. GlobalFreePtr(pv);
  25. }
  26. #endif
  27. // DATA.CPP
  28. __inline BOOL DoEnterCriticalSection(HANDLE hMutex)
  29. {
  30. if(WAIT_FAILED==WaitForSingleObject(hMutex, 3000)) // Wait 3 seconds
  31. return(fFalse);
  32. return(fTrue);
  33. }
  34. __inline
  35. LRESULT OurSendMessage( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  36. {
  37. DWORD_PTR dwptResult;
  38. LRESULT lResult;
  39. DbgAssert( hWnd != (HWND)0 );
  40. Dbg( DBGID_SendMsg, TEXT("SendMsg - hW=%x uiMsg=%x wP=%x lP=%x"), hWnd, uiMsg, wParam, lParam );
  41. lResult = SendMessageTimeout( hWnd, uiMsg, wParam, lParam, SMTO_NORMAL, 8000, &dwptResult );
  42. if( lResult == 0 ) // application didn't respond
  43. {
  44. AST( lResult != 0 );
  45. Dbg( DBGID_SendMsg, TEXT("SendMsg - *TIMEOUT*"));
  46. PostMessage( hWnd, uiMsg, wParam, lParam ); // post anyway
  47. }
  48. Dbg( DBGID_SendMsg, TEXT("SendMsg - Exit = %x hW=%x uiMsg=%x wP=%x lP=%x"), dwptResult, hWnd, uiMsg, wParam, lParam );
  49. return (LRESULT)dwptResult;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Wide String Functions
  53. // Win95 does not support lstrcmpW, lstrcpyW, lstrcatW
  54. /*---------------------------------------------------------------------------
  55. StrCmpW
  56. Unicode String compare
  57. ---------------------------------------------------------------------------*/
  58. __inline INT StrCmpW(WCHAR* pwSz1, WCHAR* pwSz2)
  59. {
  60. INT cch1 = lstrlenW( pwSz1 );
  61. INT cch2 = lstrlenW( pwSz2 );
  62. if( cch1 != cch2 ) {
  63. return cch2 - cch1;
  64. }
  65. INT i;
  66. for( i=0; i<cch1; i++ ) {
  67. if( pwSz1[i] != pwSz2[i] ) {
  68. return i+1;
  69. }
  70. }
  71. return 0;
  72. }
  73. /*---------------------------------------------------------------------------
  74. StrCopyW
  75. Unicode String copy
  76. ---------------------------------------------------------------------------*/
  77. __inline INT StrCopyW(LPWSTR pwSz1, LPCWSTR pwSz2)
  78. {
  79. INT cch = 0;
  80. while( *pwSz2 ) {
  81. *pwSz1 = *pwSz2;
  82. pwSz1 ++;
  83. pwSz2 ++;
  84. cch++;
  85. }
  86. *pwSz1 = L'\0';
  87. return cch;
  88. }
  89. /*---------------------------------------------------------------------------
  90. StrnCopyW
  91. Unicode String copy
  92. ---------------------------------------------------------------------------*/
  93. __inline LPWSTR StrnCopyW(LPWSTR pwDest, LPCWSTR pwSrc, UINT uiCount)
  94. {
  95. LPWSTR pwStart = pwDest;
  96. while (uiCount && (*pwDest++ = *pwSrc++)) // copy string
  97. uiCount--;
  98. if (uiCount) // pad out with zeroes
  99. while (--uiCount)
  100. *pwDest++ = 0;
  101. return (pwStart);
  102. }
  103. __inline
  104. LRESULT OurSendMessageNoPost( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  105. {
  106. DWORD_PTR dwptResult;
  107. LRESULT lResult;
  108. Dbg( DBGID_SendMsg, TEXT("SendMsgNoPost - hW=%x uiMsg=%x wP=%x lP=%x"), hWnd, uiMsg, wParam, lParam );
  109. lResult = SendMessageTimeout( hWnd, uiMsg, wParam, lParam, SMTO_NORMAL, 100, &dwptResult );
  110. Dbg( DBGID_SendMsg, TEXT("SendMsgNoPost - Exit = %x hW=%x uiMsg=%x wP=%x lP=%x"), dwptResult, hWnd, uiMsg, wParam, lParam );
  111. return (LRESULT)dwptResult;
  112. }
  113. __inline
  114. BOOL IsWin( HWND hWnd )
  115. {
  116. return (hWnd && IsWindow(hWnd));
  117. }
  118. __inline
  119. LRESULT OurPostMessage( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam )
  120. {
  121. LRESULT lResult;
  122. Dbg( DBGID_SendMsg, TEXT("PostMsg - hW=%x uiMsg=%x wP=%x lP=%x"), hWnd, uiMsg, wParam, lParam );
  123. lResult = PostMessage( hWnd, uiMsg, wParam, lParam);
  124. return (LRESULT)lResult;
  125. }
  126. __inline
  127. BOOL IsShiftKeyPushed( LPBYTE lpbKeyState )
  128. {
  129. return lpbKeyState[VK_SHIFT] & 0x80;
  130. }
  131. __inline
  132. BOOL IsControlKeyPushed( LPBYTE lpbKeyState )
  133. {
  134. return lpbKeyState[VK_CONTROL] & 0x80;
  135. }
  136. #endif // __INLINES_H__