MCPcopy Create free account
hub / github.com/Nevcairiel/LAVFilters / CreateInstance

Method CreateInstance

common/baseclasses/dllentry.cpp:113–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113STDMETHODIMP
114CClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, __deref_out void **pv)
115{
116 CheckPointer(pv, E_POINTER) ValidateReadWritePtr(pv, sizeof(void *));
117 *pv = NULL;
118
119 /* Enforce the normal OLE rules regarding interfaces and delegation */
120
121 if (pUnkOuter != NULL)
122 {
123 if (IsEqualIID(riid, IID_IUnknown) == FALSE)
124 {
125 *pv = NULL;
126 return ResultFromScode(E_NOINTERFACE);
127 }
128 }
129
130 /* Create the new object through the derived class's create function */
131
132 HRESULT hr = NOERROR;
133 CUnknown *pObj = m_pTemplate->CreateInstance(pUnkOuter, &hr);
134
135 if (pObj == NULL)
136 {
137 *pv = NULL;
138 if (SUCCEEDED(hr))
139 {
140 hr = E_OUTOFMEMORY;
141 }
142 return hr;
143 }
144
145 /* Delete the object if we got a construction error */
146
147 if (FAILED(hr))
148 {
149 delete pObj;
150 *pv = NULL;
151 return hr;
152 }
153
154 /* Get a reference counted interface on the object */
155
156 /* We wrap the non-delegating QI with NDAddRef & NDRelease. */
157 /* This protects any outer object from being prematurely */
158 /* released by an inner object that may have to be created */
159 /* in order to supply the requested interface. */
160 pObj->NonDelegatingAddRef();
161 hr = pObj->NonDelegatingQueryInterface(riid, pv);
162 pObj->NonDelegatingRelease();
163 /* Note that if NonDelegatingQueryInterface fails, it will */
164 /* not increment the ref count, so the NonDelegatingRelease */
165 /* will drop the ref back to zero and the object will "self-*/
166 /* destruct". Hence we don't need additional tidy-up code */
167 /* to cope with NonDelegatingQueryInterface failing. */
168
169 if (SUCCEEDED(hr))
170 {

Callers

nothing calls this directly

Calls 4

SUCCEEDEDFunction · 0.85
NonDelegatingAddRefMethod · 0.45
NonDelegatingReleaseMethod · 0.45

Tested by

no test coverage detected