@@ -22,43 +22,10 @@ namespace datadog::shared::nativeloader
2222 DynamicDispatcherImpl::DynamicDispatcherImpl () :
2323 m_continuousProfilerInstance (nullptr ),
2424 m_tracerInstance (nullptr ),
25- m_customInstance (nullptr ),
26- m_initialized (false ),
27- m_initializationResult (E_UNEXPECTED)
25+ m_customInstance (nullptr )
2826 {
2927 }
3028
31- HRESULT DynamicDispatcherImpl::Initialize ()
32- {
33- if (m_initialized)
34- {
35- return m_initializationResult;
36- }
37-
38- m_initialized = true ;
39-
40- LoadConfiguration (GetConfigurationFilePath ());
41-
42- m_initializationResult = LoadClassFactory (IID_IClassFactory);
43-
44- if (FAILED (m_initializationResult))
45- {
46- Log::Error (" Error loading all cor profiler class factories." );
47- return m_initializationResult;
48- }
49-
50- m_initializationResult = LoadInstance ();
51-
52- if (FAILED (m_initializationResult))
53- {
54- Log::Error (" Error loading all cor profiler instances." );
55- return m_initializationResult;
56- }
57-
58- m_initializationResult = S_OK;
59- return m_initializationResult;
60- }
61-
6229 void DynamicDispatcherImpl::LoadConfiguration (fs::path&& configFilePath)
6330 {
6431 ::shared::WSTRING nativeLoaderPath = ::shared::GetCurrentModuleFileName ();
@@ -190,28 +157,19 @@ namespace datadog::shared::nativeloader
190157
191158 HRESULT DynamicDispatcherImpl::LoadClassFactory (REFIID riid)
192159 {
193- // We consider the loading a success if at least one class factory is properly loaded.
194- HRESULT GHR = E_FAIL;
160+ HRESULT GHR = S_OK;
195161
196162 if (m_continuousProfilerInstance != nullptr )
197163 {
198164 HRESULT result = m_continuousProfilerInstance->LoadClassFactory (riid);
199165 if (FAILED (result))
200166 {
201167 Log::Warn (" DynamicDispatcherImpl::LoadClassFactory: Error trying to load continuous profiler class factory in: " ,
202- m_continuousProfilerInstance->GetFilePath (), " , error code: " , result );
168+ m_continuousProfilerInstance->GetFilePath ());
203169
204170 // If we cannot load the class factory we release the instance.
205171 m_continuousProfilerInstance.release ();
206-
207- if (GHR != S_OK)
208- {
209- GHR = result;
210- }
211- }
212- else
213- {
214- GHR = S_OK;
172+ GHR = result;
215173 }
216174 }
217175
@@ -220,20 +178,11 @@ namespace datadog::shared::nativeloader
220178 HRESULT result = m_tracerInstance->LoadClassFactory (riid);
221179 if (FAILED (result))
222180 {
223- Log::Warn (" DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: " ,
224- m_tracerInstance->GetFilePath (), " , error code: " , result);
181+ Log::Warn (" DynamicDispatcherImpl::LoadClassFactory: Error trying to load tracer class factory in: " , m_tracerInstance->GetFilePath ());
225182
226183 // If we cannot load the class factory we release the instance.
227184 m_tracerInstance.release ();
228-
229- if (GHR != S_OK)
230- {
231- GHR = result;
232- }
233- }
234- else
235- {
236- GHR = S_OK;
185+ GHR = result;
237186 }
238187 }
239188
@@ -242,94 +191,58 @@ namespace datadog::shared::nativeloader
242191 HRESULT result = m_customInstance->LoadClassFactory (riid);
243192 if (FAILED (result))
244193 {
245- Log::Warn (" DynamicDispatcherImpl::LoadClassFactory: Error trying to load custom class factory in: " ,
246- m_customInstance->GetFilePath (), " , error code: " , result);
194+ Log::Warn (" DynamicDispatcherImpl::LoadClassFactory: Error trying to load custom class factory in: " , m_customInstance->GetFilePath ());
247195
248196 // If we cannot load the class factory we release the instance.
249197 m_customInstance.release ();
250-
251- if (GHR != S_OK)
252- {
253- GHR = result;
254- }
255- }
256- else
257- {
258- GHR = S_OK;
198+ GHR = result;
259199 }
260200 }
261201
262202 return GHR;
263203 }
264204
265- HRESULT DynamicDispatcherImpl::LoadInstance ()
205+ HRESULT DynamicDispatcherImpl::LoadInstance (IUnknown* pUnkOuter, REFIID riid )
266206 {
267- // We consider the loading a success if at least one class factory is properly loaded.
268- HRESULT GHR = E_FAIL;
207+ HRESULT GHR = S_OK;
269208
270209 if (m_continuousProfilerInstance != nullptr )
271210 {
272- HRESULT result = m_continuousProfilerInstance->LoadInstance ();
211+ HRESULT result = m_continuousProfilerInstance->LoadInstance (pUnkOuter, riid );
273212 if (FAILED (result))
274213 {
275214 Log::Warn (" DynamicDispatcherImpl::LoadInstance: Error trying to load the continuous profiler instance in: " ,
276- m_continuousProfilerInstance->GetFilePath (), " , error code: " , result );
215+ m_continuousProfilerInstance->GetFilePath ());
277216
278217 // If we cannot load the class factory we release the instance.
279218 m_continuousProfilerInstance.release ();
280-
281- if (GHR != S_OK)
282- {
283- GHR = result;
284- }
285- }
286- else
287- {
288- GHR = S_OK;
219+ GHR = result;
289220 }
290221 }
291222
292223 if (m_tracerInstance != nullptr )
293224 {
294- HRESULT result = m_tracerInstance->LoadInstance ();
225+ HRESULT result = m_tracerInstance->LoadInstance (pUnkOuter, riid );
295226 if (FAILED (result))
296227 {
297- Log::Warn (" DynamicDispatcherImpl::LoadInstance: Error trying to load the tracer instance in: " ,
298- m_tracerInstance->GetFilePath (), " , error code: " , result);
228+ Log::Warn (" DynamicDispatcherImpl::LoadInstance: Error trying to load the tracer instance in: " , m_tracerInstance->GetFilePath ());
299229
300230 // If we cannot load the class factory we release the instance.
301231 m_tracerInstance.release ();
302-
303- if (GHR != S_OK)
304- {
305- GHR = result;
306- }
307- }
308- else
309- {
310- GHR = S_OK;
232+ GHR = result;
311233 }
312234 }
313235
314236 if (m_customInstance != nullptr )
315237 {
316- HRESULT result = m_customInstance->LoadInstance ();
238+ HRESULT result = m_customInstance->LoadInstance (pUnkOuter, riid );
317239 if (FAILED (result))
318240 {
319- Log::Warn (" DynamicDispatcherImpl::LoadInstance: Error trying to load the custom instance in: " ,
320- m_customInstance->GetFilePath (), " , error code: " , result);
241+ Log::Warn (" DynamicDispatcherImpl::LoadInstance: Error trying to load the custom instance in: " , m_customInstance->GetFilePath ());
321242
322243 // If we cannot load the class factory we release the instance.
323244 m_customInstance.release ();
324-
325- if (GHR != S_OK)
326- {
327- GHR = result;
328- }
329- }
330- else
331- {
332- GHR = S_OK;
245+ GHR = result;
333246 }
334247 }
335248
@@ -404,4 +317,4 @@ namespace datadog::shared::nativeloader
404317 return m_customInstance.get ();
405318 }
406319
407- } // namespace datadog::shared::nativeloader
320+ } // namespace datadog::shared::nativeloader
0 commit comments