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.

107 lines
2.9 KiB

  1. //+-------------------------------------------------------------------
  2. //
  3. // File: srvmain.cxx
  4. //
  5. // Contents: This file contins the EXE entry points
  6. //
  7. // History: 28-Feb-96 Rickhi Created
  8. //
  9. //---------------------------------------------------------------------
  10. #include <common.h>
  11. #include <mixedcf.hxx>
  12. extern "C" const GUID CLSID_QI;
  13. extern "C" const GUID CLSID_QIHANDLER;
  14. TCHAR *pszWindow[] = { TEXT("QI Server") };
  15. STHREADINFO *gpThrdInfo = NULL;
  16. ULONG gcThrds = 0;
  17. //+-------------------------------------------------------------------
  18. //
  19. // Function: MakeClassInfo
  20. //
  21. // Synopsis: fills in a SCLASSINFO structure
  22. //
  23. // History: 28-Feb-96 Rickhi Created
  24. //
  25. //--------------------------------------------------------------------
  26. HRESULT MakeClassInfo(REFCLSID rclsid, SCLASSINFO *pClsInfo)
  27. {
  28. pClsInfo->clsid = rclsid;
  29. pClsInfo->pCF = (IClassFactory *) new CMixedClassFactory(rclsid);
  30. pClsInfo->dwCtx = CLSCTX_LOCAL_SERVER;
  31. pClsInfo->dwClsReg = REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED;
  32. pClsInfo->dwReg = 0;
  33. return (pClsInfo->pCF != NULL) ? S_OK : E_OUTOFMEMORY;
  34. }
  35. //+-------------------------------------------------------------------
  36. //
  37. // Function: RegisterSameThread
  38. //
  39. // Synopsis: Entry point. Creates the classinfo and enters the main
  40. // server loop.
  41. //
  42. // History: 28-Feb-96 Rickhi Created
  43. //
  44. //--------------------------------------------------------------------
  45. int WINAPI RegisterSameThread(
  46. HINSTANCE hInstance,
  47. HINSTANCE hPrevInstance,
  48. LPSTR lpCmdLine,
  49. int nCmdShow,
  50. DWORD dwThreadModel)
  51. {
  52. SCLASSINFO ClsInfo[2];
  53. STHREADINFO ThrdInfo;
  54. HRESULT hr[2];
  55. hr[0] = MakeClassInfo(CLSID_QI, &ClsInfo[0]);
  56. hr[1] = MakeClassInfo(CLSID_QIHANDLER, &ClsInfo[1]);
  57. ThrdInfo.hEventRun = CreateEvent(NULL, FALSE, FALSE, NULL);
  58. ThrdInfo.hEventDone = CreateEvent(NULL, FALSE, FALSE, NULL);
  59. ThrdInfo.hInstance = hInstance;
  60. ThrdInfo.pszWindow = pszWindow[0];
  61. ThrdInfo.dwFlags = dwThreadModel;
  62. ThrdInfo.cClasses = 2;
  63. ThrdInfo.pClsInfo = &ClsInfo[0];
  64. // this thread is the one that should call resume.
  65. ThrdInfo.dwFlags |= SRVF_REGISTER_RESUME;
  66. ThrdInfo.dwTid = GetCurrentThreadId();
  67. // stuff the thrd pointers and count into globals so we can
  68. // wake the threads up whenever 1 single thread exits.
  69. gpThrdInfo = &ThrdInfo;
  70. gcThrds = 1;
  71. hr[0] = SrvMain2(&ThrdInfo);
  72. return hr[0];
  73. }
  74. //+-------------------------------------------------------------------
  75. //
  76. // Function: WinMain
  77. //
  78. // Synopsis: Entry point. Creates the classinfo and enters the main
  79. // server loop.
  80. //
  81. // History: 28-Feb-96 Rickhi Created
  82. //
  83. //--------------------------------------------------------------------
  84. int WINAPI WinMain(
  85. HINSTANCE hInstance,
  86. HINSTANCE hPrevInstance,
  87. LPSTR lpCmdLine,
  88. int nCmdShow)
  89. {
  90. return RegisterSameThread(hInstance, hPrevInstance, lpCmdLine, nCmdShow,
  91. SRVF_THREADMODEL_APARTMENT);
  92. }