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.

134 lines
4.2 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // IDBCreateSession interface implementation
  7. //
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "headers.h"
  10. /////////////////////////////////////////////////////////////////////////////////////////////////////
  11. //
  12. // Creates a new DB Session object from the DSO, and returns the requested interface on the newly
  13. // created object.
  14. //
  15. // HRESULT
  16. // S_OK The method succeeded.
  17. // E_INVALIDARG ppDBSession was NULL
  18. // DB_E_NOAGGREGATION pUnkOuter was not NULL (this object does not support being aggregated)
  19. // E_FAIL Provider-specific error. This provider can only create one DBSession
  20. // E_OUTOFMEMORY Out of memory
  21. // E_NOINTERFACE Could not obtain requested interface on DBSession object
  22. //
  23. /////////////////////////////////////////////////////////////////////////////////////////////////////
  24. STDMETHODIMP CImpIDBCreateSession::CreateSession(
  25. IUnknown* pUnkOuter, //IN Controlling IUnknown if being aggregated
  26. REFIID riid, //IN The ID of the interface
  27. IUnknown** ppDBSession //OUT A pointer to memory in which to return the interface pointer
  28. )
  29. {
  30. CDBSession* pDBSession = NULL;
  31. HRESULT hr = S_OK;
  32. CSetStructuredExceptionHandler seh;
  33. TRY_BLOCK;
  34. //================================
  35. // Serialize the object
  36. //================================
  37. CAutoBlock cab(DATASOURCE->GetCriticalSection());
  38. //=========================================================================
  39. // check in-params and NULL out-params in case of error
  40. //=========================================================================
  41. if (ppDBSession){
  42. *ppDBSession = NULL;
  43. }
  44. else{
  45. hr = E_INVALIDARG;
  46. }
  47. assert( m_pObj );
  48. //=========================================================================
  49. // Check to see if the DSO is Uninitialized
  50. //=========================================================================
  51. if( hr == S_OK ){
  52. if (!m_pObj->m_fDSOInitialized){
  53. hr = E_UNEXPECTED;
  54. }
  55. else{
  56. //=================================================================
  57. // this Data Source object can only create 1 DBSession...
  58. //=================================================================
  59. if (m_pObj->m_fDBSessionCreated){
  60. hr = DB_E_OBJECTCREATIONLIMITREACHED;
  61. }
  62. else{
  63. //=============================================================
  64. // We do not allow the riid to be anything other than
  65. // IID_IUnknown for aggregation
  66. //=============================================================
  67. if ( (pUnkOuter) && (riid != IID_IUnknown) ){
  68. hr = DB_E_NOAGGREGATION;
  69. }
  70. else{
  71. hr = m_pObj->CreateSession(pUnkOuter,riid,ppDBSession);
  72. /*
  73. try
  74. {
  75. //=========================================================
  76. // open a DBSession object
  77. //=========================================================
  78. pDBSession = new CDBSession( pUnkOuter );
  79. }
  80. catch(...)
  81. {
  82. SAFE_DELETE_PTR(pDBSession);
  83. throw;
  84. }
  85. if (!pDBSession){
  86. hr = E_OUTOFMEMORY;
  87. }
  88. else{
  89. //=====================================================
  90. // initialize the object
  91. //=====================================================
  92. if (FAILED(hr = pDBSession->FInit( m_pObj ))){
  93. SAFE_DELETE_PTR( pDBSession );
  94. }
  95. else{
  96. //=================================================
  97. // get requested interface pointer on DBSession
  98. //=================================================
  99. hr = pDBSession->QueryInterface( riid, (void **) ppDBSession );
  100. if (FAILED( hr )){
  101. SAFE_DELETE_PTR( pDBSession );
  102. }
  103. else{
  104. //=============================================
  105. // all went well
  106. //=============================================
  107. m_pObj->m_fDBSessionCreated = TRUE;
  108. }
  109. }
  110. }
  111. */
  112. }
  113. }
  114. }
  115. }
  116. CATCH_BLOCK_HRESULT(hr,L"IDBCreateSession::CreateSession");
  117. return hr;
  118. }