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.

103 lines
2.3 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: srvmain.cxx
  4. //
  5. // Contents: This file contins the EXE entry points
  6. // WinMain
  7. //
  8. // Classes:
  9. //
  10. // History: 30-Nov-92 Rickhi Created
  11. //
  12. //---------------------------------------------------------------------
  13. #include <common.h>
  14. #include <rpccf.hxx>
  15. #include <stream.hxx>
  16. #include <rpctst.h> // IID_IRpcTest
  17. extern IUnknown *gpPunk;
  18. //+-------------------------------------------------------------------
  19. //
  20. // Function: WinMain
  21. //
  22. // Synopsis: Entry point to EXE
  23. //
  24. // Arguments:
  25. //
  26. // Returns: TRUE
  27. //
  28. // History: 21-Nov-92 Rickhi Created
  29. //
  30. //--------------------------------------------------------------------
  31. int WINAPI WinMain(
  32. HINSTANCE hInstance,
  33. HINSTANCE hPrevInstance,
  34. LPSTR lpCmdLine,
  35. int nCmdShow)
  36. {
  37. CRpcTestClassFactory *pCF = new CRpcTestClassFactory();
  38. // create an instance, then marshal that instance TABLE_STRONG
  39. // and LONG_FORM into a stream.
  40. IRpcTest *pUnk = NULL;
  41. HRESULT hr = pCF->CreateInstance(NULL, IID_IRpcTest, (void **)&pUnk);
  42. if (FAILED(hr))
  43. {
  44. return hr;
  45. }
  46. hr = E_OUTOFMEMORY;
  47. IStream *pStm = (IStream *) new CStreamOnFile(TEXT("c:\\rickrpc.stm"),
  48. hr, FALSE);
  49. if (FAILED(hr))
  50. {
  51. return hr;
  52. }
  53. DWORD dwThreadMode;
  54. TCHAR buffer[80];
  55. int len;
  56. len = GetProfileString( TEXT("OleSrv"),
  57. TEXT("ThreadMode"),
  58. TEXT("MultiThreaded"),
  59. buffer,
  60. sizeof(buffer) );
  61. #ifdef THREADING_SUPPORT
  62. if (lstrcmp(buffer, TEXT("ApartmentThreaded")) == 0)
  63. dwThreadMode = COINIT_APARTMENTTHREADED;
  64. else
  65. dwThreadMode = COINIT_MULTITHREADED;
  66. hr = OleInitializeEx(NULL, dwThreadMode);
  67. #else
  68. hr = OleInitialize(NULL);
  69. #endif
  70. hr = CoMarshalInterface(pStm, IID_IRpcTest, pUnk, 0, NULL,
  71. MSHLFLAGS_TABLESTRONG);
  72. if (FAILED(hr))
  73. {
  74. return hr;
  75. }
  76. // close the stream
  77. pStm->Release();
  78. hr = pCF->CreateInstance(NULL, IID_IUnknown, (void **)&gpPunk);
  79. if (FAILED(hr))
  80. {
  81. return hr;
  82. }
  83. int sc = SrvMain(hInstance, CLSID_RpcTest, REGCLS_SINGLEUSE,
  84. TEXT("IRpcTest Server"), pCF);
  85. OleUninitialize();
  86. return sc;
  87. }