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.

150 lines
4.1 KiB

  1. #include "pch.cxx"
  2. #include <stdio.h>
  3. #include <ole2.h>
  4. #include <pstgserv.hxx>
  5. HWND CPropertyStorageServerApp::m_hwnd;
  6. DWORD CPropertyStorageServerApp::m_dwReg;
  7. CClassFactory *CPropertyStorageServerApp::m_pClassFactory;
  8. CHAR CPropertyStorageServerApp::m_szAppName[80];
  9. HINSTANCE CPropertyStorageServerApp::m_hInstance;
  10. int CPropertyStorageServerApp::m_nCmdShow;
  11. BOOL CPropertyStorageServerApp::m_fCloseOnFinalRelease;
  12. EXTERN_C const IID IID_IPropertyStorageServerApp= {0xaf4ae0d1,0xa37f,0x11cf,{0x8d,0x73,0x00,0xaa,0x00,0x4c,0xd0,0x1a}};
  13. __declspec(dllexport)
  14. LONG_PTR FAR PASCAL
  15. CPropertyStorageServerApp::WndProc (HWND hwnd, UINT message,
  16. WPARAM wParam, LPARAM lParam)
  17. {
  18. switch (message)
  19. {
  20. case WM_USER :
  21. if( m_fCloseOnFinalRelease )
  22. PostMessage( hwnd, WM_CLOSE, 0, 0 );
  23. break;
  24. case WM_CLOSE :
  25. DestroyWindow( hwnd );
  26. break;
  27. case WM_DESTROY :
  28. CoUninitialize();
  29. CoRevokeClassObject( m_dwReg );
  30. delete m_pClassFactory;
  31. PostQuitMessage (0) ;
  32. return 0 ;
  33. }
  34. return (long) DefWindowProc (hwnd, message, wParam, lParam) ;
  35. }
  36. BOOL
  37. CPropertyStorageServerApp::Init( HANDLE hInstance, HANDLE hPrevInstance,
  38. LPSTR lpszCmdLine, int nCmdShow )
  39. {
  40. WNDCLASSA wndclass;
  41. if( strcmp( lpszCmdLine, "/Embedding" )
  42. &&
  43. strcmp( lpszCmdLine, "-Embedding" ))
  44. {
  45. m_fCloseOnFinalRelease = FALSE;
  46. }
  47. sprintf( m_szAppName, "IPropertyStorage Server" );
  48. m_hInstance = (HINSTANCE) hInstance;
  49. m_nCmdShow = nCmdShow;
  50. if( !hPrevInstance )
  51. {
  52. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  53. wndclass.lpfnWndProc = CPropertyStorageServerApp::WndProc;
  54. wndclass.cbClsExtra = 0;
  55. wndclass.cbWndExtra = 0;
  56. wndclass.hInstance = m_hInstance;
  57. wndclass.hIcon = LoadIconA( m_hInstance, m_szAppName );
  58. wndclass.hCursor = LoadCursorA( NULL, MAKEINTRESOURCEA(32512) ); // IDC_ARROW
  59. wndclass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
  60. wndclass.lpszMenuName = NULL;
  61. wndclass.lpszClassName = m_szAppName;
  62. RegisterClassA( &wndclass );
  63. }
  64. return( TRUE ); // Successful
  65. }
  66. #ifdef CreateWindowA
  67. #undef CreateWindow
  68. #endif
  69. WORD
  70. CPropertyStorageServerApp::Run( void )
  71. {
  72. MSG msg;
  73. HRESULT hr;
  74. CHAR szErrorMessage[80];
  75. msg.wParam = 0;
  76. m_hwnd = CreateWindowA( m_szAppName,
  77. "IPropertyStorage Server",
  78. WS_OVERLAPPEDWINDOW,
  79. CW_USEDEFAULT, CW_USEDEFAULT,
  80. CW_USEDEFAULT, CW_USEDEFAULT,
  81. NULL, NULL, m_hInstance, NULL );
  82. if( NULL == m_hwnd )
  83. {
  84. sprintf( szErrorMessage, "Failed CreateWindowA (%lu)", GetLastError() );
  85. goto Exit;
  86. }
  87. ShowWindow( m_hwnd, SW_MINIMIZE );
  88. UpdateWindow( m_hwnd );
  89. if( FAILED( hr = CoInitialize( NULL )))
  90. {
  91. sprintf( szErrorMessage, "Failed CoInitialize (%08x)", hr );
  92. goto Exit;
  93. }
  94. m_pClassFactory = (CClassFactory*) new CClassFactory( m_hwnd );
  95. if( m_pClassFactory == NULL )
  96. {
  97. hr = E_OUTOFMEMORY;
  98. sprintf( szErrorMessage, "Couldn't create CClassFactory" );
  99. goto Exit;
  100. }
  101. if( FAILED( hr = CoRegisterClassObject( IID_IPropertyStorageServerApp,
  102. m_pClassFactory,
  103. CLSCTX_LOCAL_SERVER,
  104. REGCLS_MULTIPLEUSE,
  105. &m_dwReg )))
  106. {
  107. sprintf( szErrorMessage, "Couldn't register class object" );
  108. goto Exit;
  109. }
  110. while( GetMessage( &msg, NULL, 0, 0 ))
  111. {
  112. TranslateMessage(&msg);
  113. DispatchMessage(&msg);
  114. }
  115. Exit:
  116. return( (WORD) msg.wParam );
  117. }