xref: /trunk/main/extensions/source/ole/windata.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef AUTOMATION_BRIDGE_WINDATA_HXX
28 #define AUTOMATION_BRIDGE_WINDATA_HXX
29 
30 #pragma warning (push,1)
31 #pragma warning (disable:4668)
32 #pragma warning (disable:4548)
33 #include "oleidl.h"
34 
35 #include <atlbase.h>
36 #pragma warning (pop)
37 #include "osl/diagnose.h"
38 
39 namespace ole_adapter
40 {
41 //Wrapper for VARDESC
42 class VarDesc
43 {
44 	VARDESC* operator = (const VarDesc*);
45 	VarDesc(const VarDesc&);
46 // Construction
47 public:
48 	CComPtr< ITypeInfo > m_pTypeInfo;
49 	VARDESC* m_pVarDesc;
50 
51 	VarDesc(ITypeInfo* pTypeInfo) :
52 	  m_pVarDesc(NULL),
53 	  m_pTypeInfo(pTypeInfo)
54    {
55 	   OSL_ASSERT(pTypeInfo);
56    }
57    ~VarDesc()
58    {
59 	  if (m_pVarDesc != NULL)
60 	  {
61 		 m_pTypeInfo->ReleaseVarDesc(m_pVarDesc);
62 	  }
63    }
64 
65    VARDESC* operator->()
66    {
67 	  return m_pVarDesc;
68    }
69 
70    VARDESC** operator&()
71    {
72 	  return &m_pVarDesc;
73    }
74 
75     operator VARDESC* ()
76     {
77         return m_pVarDesc;
78     }
79 };
80 
81 //Wrapper for FUNCDESC structure
82 class FuncDesc
83 {
84 	FUNCDESC* operator = (const FuncDesc &);
85 	FuncDesc(const FuncDesc&);
86 	CComPtr<ITypeInfo> m_pTypeInfo;
87     FUNCDESC * m_pFuncDesc;
88 
89 public:
90 
91 	FuncDesc(ITypeInfo * pTypeInfo) :
92 		m_pFuncDesc(NULL),
93 		m_pTypeInfo(pTypeInfo)
94 		{
95 			OSL_ASSERT(pTypeInfo);
96 		}
97 	~FuncDesc()
98 	{
99 		ReleaseFUNCDESC();
100 	}
101 
102 	FUNCDESC* operator -> ()
103 	{
104 		return m_pFuncDesc;
105 	}
106 
107 	FUNCDESC** operator & ()
108 	{
109 		return & m_pFuncDesc;
110 	}
111 
112     operator FUNCDESC* ()
113     {
114         return m_pFuncDesc;
115     }
116 
117 	FUNCDESC* operator = (FUNCDESC* pDesc)
118 	{
119 		ReleaseFUNCDESC();
120 		m_pFuncDesc = pDesc;
121 		return m_pFuncDesc;
122 	}
123 	FUNCDESC* Detach()
124 	{
125 		FUNCDESC* pDesc = m_pFuncDesc;
126 		m_pFuncDesc = NULL;
127 		return pDesc;
128 	}
129 
130 	void ReleaseFUNCDESC()
131 	{
132 		if (m_pFuncDesc != NULL)
133 		{
134 			m_pTypeInfo->ReleaseFuncDesc(m_pFuncDesc);
135 		}
136 		m_pFuncDesc = NULL;
137 	}
138 };
139 //Wrapper for EXCEPINFO structure
140 class ExcepInfo : public EXCEPINFO
141 {
142 	EXCEPINFO* operator = (const ExcepInfo& );
143 	ExcepInfo(const ExcepInfo &);
144 public:
145    ExcepInfo()
146    {
147 	  memset(this, 0, sizeof(ExcepInfo));
148    }
149    ~ExcepInfo()
150    {
151    	  if (bstrSource != NULL)
152 		 ::SysFreeString(bstrSource);
153 	  if (bstrDescription != NULL)
154 		::SysFreeString(bstrDescription);
155 	  if (bstrHelpFile != NULL)
156 		::SysFreeString(bstrHelpFile);
157    }
158 };
159 
160 //Wrapper for TYPEATTR
161 class TypeAttr
162 {
163 	TYPEATTR* operator = (const TypeAttr &);
164 	TypeAttr(const TypeAttr &);
165 public:
166 	CComPtr< ITypeInfo > m_pTypeInfo;
167 	TYPEATTR* m_pTypeAttr;
168 
169 	TypeAttr(ITypeInfo* pTypeInfo) :
170 	  m_pTypeAttr( NULL ),
171 	  m_pTypeInfo( pTypeInfo )
172    {
173 	   OSL_ASSERT(pTypeInfo);
174    }
175    ~TypeAttr() throw()
176    {
177 		if (m_pTypeAttr != NULL)
178 		{
179 			m_pTypeInfo->ReleaseTypeAttr(m_pTypeAttr);
180 		}
181    }
182 
183    TYPEATTR** operator&() throw()
184    {
185 	  return &m_pTypeAttr;
186    }
187 
188    TYPEATTR* operator->() throw()
189    {
190 	  return m_pTypeAttr;
191    }
192 };
193 
194 
195 
196 }
197 
198 #endif
199