]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/oleutils.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/ole/oleutils.cpp
3 // Purpose: implementation of OLE helper functions
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
35 #include "wx/msw/private.h"
47 #include "wx/msw/ole/uuid.h"
50 #include "wx/msw/ole/oleutils.h"
52 #if defined(__VISUALC__) && (__VISUALC__ > 1000)
56 // ============================================================================
58 // ============================================================================
60 // return true if the iid is in the array
61 bool IsIidFromList(REFIID riid
, const IID
*aIids
[], size_t nCount
)
63 for ( size_t i
= 0; i
< nCount
; i
++ ) {
64 if ( riid
== *aIids
[i
] )
71 WXDLLEXPORT BSTR
wxConvertStringToOle(const wxString
& str
)
73 return wxBasicString(str
).Get();
76 WXDLLEXPORT wxString
wxConvertStringFromOle(BSTR bStr
)
78 // NULL BSTR is equivalent to an empty string (this is the convention used
79 // by VB and hence we must follow it)
87 const int len
= SysStringLen(bStr
) + 1;
88 if ( !::WideCharToMultiByte(CP_ACP
, 0 /* no flags */,
90 wxStringBuffer(str
, len
), len
,
91 NULL
, NULL
/* no default char */) )
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 wxBasicString::wxBasicString(const wxString
& str
)
105 m_bstrBuf
= SysAllocString(str
.wc_str(*wxConvCurrent
));
108 wxBasicString::wxBasicString(const wxBasicString
& src
)
110 m_bstrBuf
= src
.Get();
113 wxBasicString
& wxBasicString::operator=(const wxBasicString
& src
)
115 SysReAllocString(&m_bstrBuf
, src
);
119 wxBasicString::~wxBasicString()
121 SysFreeString(m_bstrBuf
);
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 #if defined(__WXDEBUG__) && ( ( defined(__VISUALC__) && (__VISUALC__ > 1000) ) || defined(__MWERKS__) )
131 static wxString
GetIidName(REFIID riid
)
133 // an association between symbolic name and numeric value of an IID
136 const wxChar
*szName
;
139 // construct the table containing all known interfaces
140 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
142 static const KNOWN_IID aKnownIids
[] = {
143 ADD_KNOWN_IID(AdviseSink
),
144 ADD_KNOWN_IID(AdviseSink2
),
145 ADD_KNOWN_IID(BindCtx
),
146 ADD_KNOWN_IID(ClassFactory
),
147 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
148 ADD_KNOWN_IID(ContinueCallback
),
149 ADD_KNOWN_IID(EnumOleDocumentViews
),
150 ADD_KNOWN_IID(OleCommandTarget
),
151 ADD_KNOWN_IID(OleDocument
),
152 ADD_KNOWN_IID(OleDocumentSite
),
153 ADD_KNOWN_IID(OleDocumentView
),
154 ADD_KNOWN_IID(Print
),
156 ADD_KNOWN_IID(DataAdviseHolder
),
157 ADD_KNOWN_IID(DataObject
),
158 ADD_KNOWN_IID(Debug
),
159 ADD_KNOWN_IID(DebugStream
),
160 ADD_KNOWN_IID(DfReserved1
),
161 ADD_KNOWN_IID(DfReserved2
),
162 ADD_KNOWN_IID(DfReserved3
),
163 ADD_KNOWN_IID(Dispatch
),
164 ADD_KNOWN_IID(DropSource
),
165 ADD_KNOWN_IID(DropTarget
),
166 ADD_KNOWN_IID(EnumCallback
),
167 ADD_KNOWN_IID(EnumFORMATETC
),
168 ADD_KNOWN_IID(EnumGeneric
),
169 ADD_KNOWN_IID(EnumHolder
),
170 ADD_KNOWN_IID(EnumMoniker
),
171 ADD_KNOWN_IID(EnumOLEVERB
),
172 ADD_KNOWN_IID(EnumSTATDATA
),
173 ADD_KNOWN_IID(EnumSTATSTG
),
174 ADD_KNOWN_IID(EnumString
),
175 ADD_KNOWN_IID(EnumUnknown
),
176 ADD_KNOWN_IID(EnumVARIANT
),
177 ADD_KNOWN_IID(ExternalConnection
),
178 ADD_KNOWN_IID(InternalMoniker
),
179 ADD_KNOWN_IID(LockBytes
),
180 ADD_KNOWN_IID(Malloc
),
181 ADD_KNOWN_IID(Marshal
),
182 ADD_KNOWN_IID(MessageFilter
),
183 ADD_KNOWN_IID(Moniker
),
184 ADD_KNOWN_IID(OleAdviseHolder
),
185 ADD_KNOWN_IID(OleCache
),
186 ADD_KNOWN_IID(OleCache2
),
187 ADD_KNOWN_IID(OleCacheControl
),
188 ADD_KNOWN_IID(OleClientSite
),
189 ADD_KNOWN_IID(OleContainer
),
190 ADD_KNOWN_IID(OleInPlaceActiveObject
),
191 ADD_KNOWN_IID(OleInPlaceFrame
),
192 ADD_KNOWN_IID(OleInPlaceObject
),
193 ADD_KNOWN_IID(OleInPlaceSite
),
194 ADD_KNOWN_IID(OleInPlaceUIWindow
),
195 ADD_KNOWN_IID(OleItemContainer
),
196 ADD_KNOWN_IID(OleLink
),
197 ADD_KNOWN_IID(OleManager
),
198 ADD_KNOWN_IID(OleObject
),
199 ADD_KNOWN_IID(OlePresObj
),
200 ADD_KNOWN_IID(OleWindow
),
201 ADD_KNOWN_IID(PSFactory
),
202 ADD_KNOWN_IID(ParseDisplayName
),
203 ADD_KNOWN_IID(Persist
),
204 ADD_KNOWN_IID(PersistFile
),
205 ADD_KNOWN_IID(PersistStorage
),
206 ADD_KNOWN_IID(PersistStream
),
207 ADD_KNOWN_IID(ProxyManager
),
208 ADD_KNOWN_IID(RootStorage
),
209 ADD_KNOWN_IID(RpcChannel
),
210 ADD_KNOWN_IID(RpcProxy
),
211 ADD_KNOWN_IID(RpcStub
),
212 ADD_KNOWN_IID(RunnableObject
),
213 ADD_KNOWN_IID(RunningObjectTable
),
214 ADD_KNOWN_IID(StdMarshalInfo
),
215 ADD_KNOWN_IID(Storage
),
216 ADD_KNOWN_IID(Stream
),
217 ADD_KNOWN_IID(StubManager
),
218 ADD_KNOWN_IID(Unknown
),
219 ADD_KNOWN_IID(ViewObject
),
220 ADD_KNOWN_IID(ViewObject2
),
223 // don't clobber preprocessor name space
226 // try to find the interface in the table
227 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ ) {
228 if ( riid
== *aKnownIids
[ui
].pIid
) {
229 return aKnownIids
[ui
].szName
;
234 // unknown IID, just transform to string
236 return wxString((const wxChar
*)uuid
);
238 return wxEmptyString
;
242 void wxLogQueryInterface(const wxChar
*szInterface
, REFIID riid
)
244 wxLogTrace(wxTRACE_OleCalls
, wxT("%s::QueryInterface (iid = %s)"),
245 szInterface
, GetIidName(riid
).c_str());
248 void wxLogAddRef(const wxChar
*szInterface
, ULONG cRef
)
250 wxLogTrace(wxTRACE_OleCalls
, wxT("After %s::AddRef: m_cRef = %d"), szInterface
, cRef
+ 1);
253 void wxLogRelease(const wxChar
*szInterface
, ULONG cRef
)
255 wxLogTrace(wxTRACE_OleCalls
, wxT("After %s::Release: m_cRef = %d"), szInterface
, cRef
- 1);
258 #elif defined(__WXDEBUG__) && defined(__VISUALC__) && (__VISUALC__ <= 1000)
261 void wxLogQueryInterface(const char *szInterface
, REFIID riid
)
263 wxLogTrace("%s::QueryInterface", szInterface
);
266 void wxLogAddRef(const char *szInterface
, ULONG cRef
)
268 wxLogTrace("After %s::AddRef: m_cRef = %d", szInterface
, cRef
+ 1);
271 void wxLogRelease(const char *szInterface
, ULONG cRef
)
273 wxLogTrace("After %s::Release: m_cRef = %d", szInterface
, cRef
- 1);
276 #endif // __WXDEBUG__
279 // wxUSE_DRAG_AND_DROP