Btk
internal.hpp
1 #if !defined(_BTK_WIN32_INTERNAL_HPP_)
2 #define _BTK_WIN32_INTERNAL_HPP_
3 #include <ShlObj.h>
4 namespace Btk{
5 namespace Win32{
11  template<class T>
12  struct ComInstance{
13  ComInstance() = default;
14  ComInstance(const ComInstance &) = delete;
15  ~ComInstance(){
16  if(ptr != nullptr){
17  ptr->Release();
18  }
19  }
20 
21  T *operator ->(){
22  return ptr;
23  }
24  T **operator &(){
25  return &ptr;
26  }
27  T *ptr = nullptr;
28  };
34  template<class T>
35  struct ComMemPtr{
36  ComMemPtr(T *p = nullptr){
37  ptr = p;
38  }
39  ComMemPtr(const ComMemPtr &) = delete;
40  ~ComMemPtr(){
41  CoTaskMemFree(ptr);
42  }
43  T *operator ->(){
44  return ptr;
45  }
46  T **operator &(){
47  return &ptr;
48  }
49  operator T*(){
50  return ptr;
51  }
52  T *ptr;
53  };
54 }
55 }
56 
57 
58 #endif // _BTK_WIN32_INTERNAL_HPP_
This header include many useful containers.
Definition: async.hpp:7
A Helper class to manager com.
Definition: internal.hpp:12
A pointer to free memory from com.
Definition: internal.hpp:35