Changeset 49 for trunk/Utilities/MaxMindGeoLite/Location.h
- Timestamp:
- Feb 11, 2012, 2:47:53 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/MaxMindGeoLite/Location.h
r48 r49 262 262 }; 263 263 264 //////////////////////////////////////////////////// 265 // CDispatchExT 266 // 267 // TODO: IDispatch methods should take care of IID argument 268 269 template <typename T> 270 class ATL_NO_VTABLE CDispatchExT : 271 public IDispatchEx 272 { 273 public: 274 275 //////////////////////////////////////////////////////// 276 // CDispatchData 277 278 class CDispatchData 279 { 280 public: 281 IID m_InterfaceIdentifier; 282 IDispatch* m_pDispatch; 283 284 public: 285 // CDispatchData 286 CDispatchData() throw() : 287 m_InterfaceIdentifier(IID_NULL), 288 m_pDispatch(NULL) 289 { 290 } 291 CDispatchData(IDispatchEx* pDispatchEx, const IID& InterfaceIdentifier) 292 { 293 CComPtr<IDispatch> pDispatch; 294 __C(pDispatchEx->QueryInterface(InterfaceIdentifier, (VOID**) &pDispatch)); 295 m_InterfaceIdentifier = InterfaceIdentifier; 296 m_pDispatch = pDispatch; 297 } 298 }; 299 300 private: 301 CRoArrayT<CDispatchData> m_DispatchDataArray; 302 303 public: 304 // CDispatchExT 305 VOID ResetDispatchInterfaceIdentifiers() throw() 306 { 307 m_DispatchDataArray.RemoveAll(); 308 } 309 VOID SetDispatchInterfaceIdentifiers(const IID* pInterfaceIdentifiers, SIZE_T nInterfaceIdentifierCount) 310 { 311 _A(m_DispatchDataArray.IsEmpty()); 312 for(SIZE_T nIndex = 0; nIndex < nInterfaceIdentifierCount; nIndex++) 313 _W(m_DispatchDataArray.Add(CDispatchData(this, pInterfaceIdentifiers[nIndex])) >= 0); 314 } 315 VOID SetDispatchInterfaceIdentifiers(const IID& InterfaceIdentifier) 316 { 317 SetDispatchInterfaceIdentifiers(&InterfaceIdentifier, 1); 318 } 319 VOID SetDispatchInterfaceIdentifiers(SIZE_T nInterfaceIdentifierCount, ...) 320 { 321 _A(nInterfaceIdentifierCount); 322 va_list Arguments; 323 va_start(Arguments, nInterfaceIdentifierCount); 324 CTempBufferT<IID> pInterfaceIdentifiers(nInterfaceIdentifierCount); 325 for(SIZE_T nIndex = 0; nIndex < nInterfaceIdentifierCount; nIndex++) 326 pInterfaceIdentifiers[nIndex] = *va_arg(Arguments, IID*); 327 va_end(Arguments); 328 SetDispatchInterfaceIdentifiers(pInterfaceIdentifiers, nInterfaceIdentifierCount); 329 } 330 IDispatch* GetDispatch(DISPID nDispIdentifier) const throw() 331 { 332 const SIZE_T nDispatchIndex = (UINT) (nDispIdentifier >> 12); 333 _A(nDispatchIndex < m_DispatchDataArray.GetCount()); 334 return m_DispatchDataArray[nDispatchIndex].m_pDispatch; 335 } 336 337 // IDispatchEx 338 STDMETHOD(GetDispID)(BSTR sName, DWORD nFlags, DISPID* pid) throw() 339 { 340 _Z4(atlTraceCOM, 4, _T("this 0x%p, sName \"%s\", nFlags 0x%x\n"), static_cast<T*>(this), CString(sName), nFlags); 341 _ATLTRY 342 { 343 __D(pid, E_POINTER); 344 nFlags; 345 OLECHAR* ppszNames[] = { const_cast<OLECHAR*>(sName), }; 346 const LCID nLocaleIdentifier = GetThreadLocale(); 347 *pid = -1; 348 HRESULT nResult = DISP_E_UNKNOWNNAME; 349 for(SIZE_T nIndex = 0; nIndex < m_DispatchDataArray.GetCount(); nIndex++) 350 { 351 DISPID nDispatchDispIdentifier; 352 const HRESULT nDispatchResult = m_DispatchDataArray[nIndex].m_pDispatch->GetIDsOfNames(IID_NULL, ppszNames, DIM(ppszNames), nLocaleIdentifier, &nDispatchDispIdentifier); 353 if(SUCCEEDED(nDispatchResult)) 354 { 355 _A(!(nDispatchDispIdentifier & ~0x0FFF)); 356 *pid = (DISPID) (nIndex << 12) + nDispatchDispIdentifier; 357 nResult = nDispatchResult; 358 break; 359 } 360 } 361 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x, *pid %d\n"), nResult, *pid); 362 return nResult; 363 } 364 _ATLCATCH(Exception) 365 { 366 _C(Exception); 367 } 368 return E_NOTIMPL; 369 } 370 STDMETHOD(InvokeEx)(DISPID id, LCID nLocaleIdentifier, WORD nFlags, DISPPARAMS* pdp, VARIANT* pvarRes, EXCEPINFO* pei, IServiceProvider* pServiceProvider) throw() 371 { 372 _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d, nLocaleIdentifier %d, nFlags 0x%x\n"), static_cast<T*>(this), id, nLocaleIdentifier, nFlags); 373 _ATLTRY 374 { 375 pServiceProvider; 376 UINT nErroneousArgument; 377 _A((id & ~0xFFFF) == 0); 378 const HRESULT nResult = GetDispatch(id)->Invoke(id & 0x0FFF, IID_NULL, nLocaleIdentifier, nFlags, pdp, pvarRes, pei, &nErroneousArgument); 379 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); 380 return nResult; 381 } 382 _ATLCATCH(Exception) 383 { 384 _C(Exception); 385 } 386 return E_NOTIMPL; 387 } 388 STDMETHOD(DeleteMemberByName)(BSTR sName, DWORD nFlags) throw() 389 { 390 _Z4(atlTraceCOM, 4, _T("this 0x%p, sName \"%s\", nFlags 0x%x\n"), static_cast<T*>(this), CString(sName), nFlags); 391 return E_NOTIMPL; 392 } 393 STDMETHOD(DeleteMemberByDispID)(DISPID id) throw() 394 { 395 _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d\n"), static_cast<T*>(this), id); 396 return E_NOTIMPL; 397 } 398 STDMETHOD(GetMemberProperties)(DISPID id, DWORD nFlagMask, DWORD* pnFlags) throw() 399 { 400 _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d, nFlagMask 0x%x\n"), static_cast<T*>(this), id, nFlagMask); 401 return E_NOTIMPL; 402 } 403 STDMETHOD(GetMemberName)(DISPID id, BSTR* psName) throw() 404 { 405 _Z4(atlTraceCOM, 4, _T("this 0x%p, id %d\n"), static_cast<T*>(this), id); 406 return E_NOTIMPL; 407 } 408 STDMETHOD(GetNextDispID)(DWORD nFlags, DISPID id, DISPID* pid) throw() 409 { 410 _Z4(atlTraceCOM, 4, _T("this 0x%p, nFlags 0x%x, id %d\n"), static_cast<T*>(this), nFlags, id); 411 return E_NOTIMPL; 412 } 413 STDMETHOD(GetNameSpaceParent)(IUnknown** ppunk) throw() 414 { 415 _Z4(atlTraceCOM, 4, _T("this 0x%p\n"), static_cast<T*>(this)); 416 return E_NOTIMPL; 417 } 418 419 // IDispatch 420 STDMETHOD(GetTypeInfoCount)(UINT* pnCount) throw() 421 { 422 _Z4(atlTraceCOM, 4, _T("this 0x%p\n"), static_cast<T*>(this)); 423 _ATLTRY 424 { 425 const HRESULT nResult = GetDispatch(0)->GetTypeInfoCount(pnCount); 426 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); 427 return nResult; 428 } 429 _ATLCATCH(Exception) 430 { 431 _C(Exception); 432 } 433 return E_NOTIMPL; 434 } 435 STDMETHOD(GetTypeInfo)(UINT nIndex, LCID nLocaleIdentifier, ITypeInfo** ppTypeInfo) throw() 436 { 437 _Z4(atlTraceCOM, 4, _T("this 0x%p, nIndex %d, nLocaleIdentifier %d\n"), static_cast<T*>(this), nIndex, nLocaleIdentifier); 438 _ATLTRY 439 { 440 const HRESULT nResult = GetDispatch(0)->GetTypeInfo(nIndex, nLocaleIdentifier, ppTypeInfo); 441 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); 442 return nResult; 443 } 444 _ATLCATCH(Exception) 445 { 446 _C(Exception); 447 } 448 return E_NOTIMPL; 449 } 450 STDMETHOD(GetIDsOfNames)(REFIID InterfaceIdentifier, LPOLESTR* ppszNames, UINT nNameCount, LCID nLocaleIdentifier, DISPID* rgDispId) throw() 451 { 452 _Z4(atlTraceCOM, 4, _T("this 0x%p, nNameCount %d, nLocaleIdentifier %d\n"), static_cast<T*>(this), nNameCount, nLocaleIdentifier); 453 _ATLTRY 454 { 455 const HRESULT nResult = GetDispatch(0)->GetIDsOfNames(InterfaceIdentifier, ppszNames, nNameCount, nLocaleIdentifier, rgDispId); 456 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); 457 return nResult; 458 } 459 _ATLCATCH(Exception) 460 { 461 _C(Exception); 462 } 463 return E_NOTIMPL; 464 } 465 STDMETHOD(Invoke)(DISPID dispIdMember, REFIID InterfaceIdentifier, LCID nLocaleIdentifier, WORD nFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) throw() 466 { 467 _Z4(atlTraceCOM, 4, _T("this 0x%p, dispIdMember %d, nLocaleIdentifier %d, nFlags 0x%x\n"), static_cast<T*>(this), dispIdMember, nLocaleIdentifier, nFlags); 468 _ATLTRY 469 { 470 const HRESULT nResult = GetDispatch(0)->Invoke(dispIdMember, InterfaceIdentifier, nLocaleIdentifier, nFlags, pDispParams, pVarResult, pExcepInfo, puArgErr); 471 _Z4(atlTraceGeneral, 4, _T("nResult 0x%08x\n"), nResult); 472 return nResult; 473 } 474 _ATLCATCH(Exception) 475 { 476 _C(Exception); 477 } 478 return E_NOTIMPL; 479 } 480 }; 481 264 482 //////////////////////////////////////////////////////////// 265 483 // CLocations … … 558 776 public CComObjectRootEx<CComMultiThreadModelNoCS>, 559 777 public CComCoClass<CLazyLocations, &__uuidof(LazyLocations)>, 560 public IDispatchImpl<ILazyLocations> 778 public IDispatchImpl<ILazyLocations>, 779 public IDispatchImpl<ILocations>, 780 public CDispatchExT<CLazyLocations> 561 781 { 562 782 typedef CThreadT<CLazyLocations> CThread; … … 573 793 BEGIN_COM_MAP(CLazyLocations) 574 794 COM_INTERFACE_ENTRY(ILazyLocations) 575 COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), ILazyLocations)576 795 COM_INTERFACE_ENTRY(ILocations) 796 COM_INTERFACE_ENTRY_IID(__uuidof(IDispatch), ILocations) 797 COM_INTERFACE_ENTRY(IDispatchEx) 577 798 COM_INTERFACE_ENTRY_AGGREGATE(__uuidof(IMarshal), m_FreeThreadedMarshaler) 578 799 END_COM_MAP() … … 636 857 _ATLTRY 637 858 { 859 SetDispatchInterfaceIdentifiers(2, &__uuidof(ILazyLocations), &__uuidof(ILocations)); 638 860 CRoCriticalSectionLock ThreadLock(m_ThreadCriticalSection); 639 861 CObjectPtr<CThread> pThread;
Note: See TracChangeset
for help on using the changeset viewer.