win_nanoafx.h 849 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef __WIN_NANOAFX_HPP__
  2. #define __WIN_NANOAFX_HPP__
  3. #define _T(n) L##n
  4. class CComBSTR : public _bstr_t
  5. {
  6. public:
  7. inline CComBSTR(const wchar_t *str) : _bstr_t(str)
  8. {
  9. }
  10. inline CComBSTR(const char *str) : _bstr_t(str)
  11. {
  12. }
  13. };
  14. class CComVariant : public tagVARIANT
  15. {
  16. };
  17. template<class T>
  18. class CComPtr
  19. {
  20. private:
  21. T *_ptr;
  22. public:
  23. inline CComPtr()
  24. {
  25. _ptr = NULL;
  26. }
  27. inline CComPtr(T *ptr)
  28. {
  29. if(ptr)
  30. {
  31. ptr->AddRef();
  32. _ptr = ptr;
  33. }
  34. }
  35. inline ~CComPtr()
  36. {
  37. if(_ptr)
  38. _ptr->Release();
  39. _ptr = NULL;
  40. }
  41. inline CComPtr &operator = (T *ptr)
  42. {
  43. if(ptr)
  44. {
  45. ptr->AddRef();
  46. _ptr = ptr;
  47. }
  48. }
  49. inline bool operator == (T *ptr)
  50. {
  51. return _ptr == ptr;
  52. }
  53. inline T *operator -> ()
  54. {
  55. return _ptr;
  56. }
  57. inline T **operator & ()
  58. {
  59. return &_ptr;
  60. }
  61. inline operator T *()
  62. {
  63. return _ptr;
  64. }
  65. };
  66. #endif