]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
521bf4ff | 2 | // Name: src/msw/ole/oleutils.cpp |
bbf1f0e5 KB |
3 | // Purpose: implementation of OLE helper functions |
4 | // Author: Vadim Zeitlin | |
3f4a0c5b | 5 | // Modified by: |
bbf1f0e5 KB |
6 | // Created: 19.02.98 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
65571936 | 9 | // Licence: wxWindows licence |
bbf1f0e5 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // Declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
bbf1f0e5 | 20 | // For compilers that support precompilation, includes "wx.h". |
bbf1f0e5 KB |
21 | #include "wx/wxprec.h" |
22 | ||
23 | #if defined(__BORLANDC__) | |
e4db172a | 24 | #pragma hdrstop |
bbf1f0e5 KB |
25 | #endif |
26 | ||
21709999 JS |
27 | #if wxUSE_OLE |
28 | ||
e4db172a WS |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/log.h" | |
31 | #endif | |
32 | ||
ae090fdb JS |
33 | #ifndef __CYGWIN10__ |
34 | ||
4676948b JS |
35 | #include "wx/msw/private.h" |
36 | ||
37 | #ifdef __WXWINCE__ | |
38 | #include <winreg.h> | |
39 | #include <ole2.h> | |
40 | ||
41 | #define GUID_DEFINED | |
42 | #define UUID_DEFINED | |
43 | #endif | |
bbf1f0e5 KB |
44 | |
45 | // OLE | |
4676948b | 46 | #ifndef __WXWINCE__ |
3096bd2f | 47 | #include "wx/msw/ole/uuid.h" |
4676948b JS |
48 | #endif |
49 | ||
3096bd2f | 50 | #include "wx/msw/ole/oleutils.h" |
bbf1f0e5 | 51 | |
3f4a0c5b VZ |
52 | #if defined(__VISUALC__) && (__VISUALC__ > 1000) |
53 | #include <docobj.h> | |
bbf1f0e5 KB |
54 | #endif |
55 | ||
56 | // ============================================================================ | |
57 | // Implementation | |
58 | // ============================================================================ | |
59 | ||
0a0e6a5b | 60 | // return true if the iid is in the array |
bbf1f0e5 KB |
61 | bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount) |
62 | { | |
63 | for ( size_t i = 0; i < nCount; i++ ) { | |
64 | if ( riid == *aIids[i] ) | |
0a0e6a5b | 65 | return true; |
bbf1f0e5 KB |
66 | } |
67 | ||
0a0e6a5b | 68 | return false; |
bbf1f0e5 KB |
69 | } |
70 | ||
e2898549 | 71 | WXDLLEXPORT BSTR wxConvertStringToOle(const wxString& str) |
94113cc5 | 72 | { |
c45ead7b | 73 | return wxBasicString(str).Get(); |
94113cc5 JS |
74 | } |
75 | ||
e2898549 | 76 | WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr) |
94113cc5 | 77 | { |
795b0f14 VZ |
78 | // NULL BSTR is equivalent to an empty string (this is the convention used |
79 | // by VB and hence we must follow it) | |
80 | if ( !bStr ) | |
81 | return wxString(); | |
82 | ||
94113cc5 JS |
83 | #if wxUSE_UNICODE |
84 | wxString str(bStr); | |
85 | #else | |
86 | int len = SysStringLen(bStr) + 1; | |
87 | char *buf = new char[len]; | |
88 | (void)wcstombs( buf, bStr, len); | |
89 | wxString str(buf); | |
90 | delete[] buf; | |
91 | #endif | |
92 | return str; | |
93 | } | |
94 | ||
95 | // ---------------------------------------------------------------------------- | |
96 | // wxBasicString | |
97 | // ---------------------------------------------------------------------------- | |
98 | ||
a518e508 | 99 | wxBasicString::wxBasicString(const wxString& str) |
94113cc5 | 100 | { |
a518e508 | 101 | m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent)); |
94113cc5 JS |
102 | } |
103 | ||
a518e508 | 104 | wxBasicString::wxBasicString(const wxBasicString& src) |
94113cc5 | 105 | { |
a518e508 | 106 | m_bstrBuf = src.Get(); |
94113cc5 JS |
107 | } |
108 | ||
a518e508 | 109 | wxBasicString& wxBasicString::operator=(const wxBasicString& src) |
94113cc5 | 110 | { |
a518e508 VZ |
111 | SysReAllocString(&m_bstrBuf, src); |
112 | return *this; | |
94113cc5 JS |
113 | } |
114 | ||
94113cc5 JS |
115 | wxBasicString::~wxBasicString() |
116 | { | |
a518e508 | 117 | SysFreeString(m_bstrBuf); |
94113cc5 JS |
118 | } |
119 | ||
8c18da2e | 120 | #if wxUSE_DATAOBJ |
c740f496 | 121 | |
bbf1f0e5 KB |
122 | // ---------------------------------------------------------------------------- |
123 | // Debug support | |
124 | // ---------------------------------------------------------------------------- | |
125 | ||
ba14d986 | 126 | #if defined(__WXDEBUG__) && ( ( defined(__VISUALC__) && (__VISUALC__ > 1000) ) || defined(__MWERKS__) ) |
f6bcfd97 | 127 | static wxString GetIidName(REFIID riid) |
bbf1f0e5 KB |
128 | { |
129 | // an association between symbolic name and numeric value of an IID | |
130 | struct KNOWN_IID { | |
131 | const IID *pIid; | |
f6bcfd97 | 132 | const wxChar *szName; |
bbf1f0e5 KB |
133 | }; |
134 | ||
135 | // construct the table containing all known interfaces | |
f6bcfd97 | 136 | #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) } |
bbf1f0e5 KB |
137 | |
138 | static const KNOWN_IID aKnownIids[] = { | |
139 | ADD_KNOWN_IID(AdviseSink), | |
140 | ADD_KNOWN_IID(AdviseSink2), | |
141 | ADD_KNOWN_IID(BindCtx), | |
142 | ADD_KNOWN_IID(ClassFactory), | |
ba14d986 | 143 | #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__) |
bbf1f0e5 KB |
144 | ADD_KNOWN_IID(ContinueCallback), |
145 | ADD_KNOWN_IID(EnumOleDocumentViews), | |
146 | ADD_KNOWN_IID(OleCommandTarget), | |
147 | ADD_KNOWN_IID(OleDocument), | |
148 | ADD_KNOWN_IID(OleDocumentSite), | |
149 | ADD_KNOWN_IID(OleDocumentView), | |
150 | ADD_KNOWN_IID(Print), | |
27a9bd48 | 151 | #endif |
bbf1f0e5 KB |
152 | ADD_KNOWN_IID(DataAdviseHolder), |
153 | ADD_KNOWN_IID(DataObject), | |
154 | ADD_KNOWN_IID(Debug), | |
155 | ADD_KNOWN_IID(DebugStream), | |
156 | ADD_KNOWN_IID(DfReserved1), | |
157 | ADD_KNOWN_IID(DfReserved2), | |
158 | ADD_KNOWN_IID(DfReserved3), | |
159 | ADD_KNOWN_IID(Dispatch), | |
160 | ADD_KNOWN_IID(DropSource), | |
161 | ADD_KNOWN_IID(DropTarget), | |
162 | ADD_KNOWN_IID(EnumCallback), | |
163 | ADD_KNOWN_IID(EnumFORMATETC), | |
164 | ADD_KNOWN_IID(EnumGeneric), | |
165 | ADD_KNOWN_IID(EnumHolder), | |
166 | ADD_KNOWN_IID(EnumMoniker), | |
167 | ADD_KNOWN_IID(EnumOLEVERB), | |
168 | ADD_KNOWN_IID(EnumSTATDATA), | |
169 | ADD_KNOWN_IID(EnumSTATSTG), | |
170 | ADD_KNOWN_IID(EnumString), | |
171 | ADD_KNOWN_IID(EnumUnknown), | |
172 | ADD_KNOWN_IID(EnumVARIANT), | |
173 | ADD_KNOWN_IID(ExternalConnection), | |
174 | ADD_KNOWN_IID(InternalMoniker), | |
175 | ADD_KNOWN_IID(LockBytes), | |
176 | ADD_KNOWN_IID(Malloc), | |
177 | ADD_KNOWN_IID(Marshal), | |
178 | ADD_KNOWN_IID(MessageFilter), | |
179 | ADD_KNOWN_IID(Moniker), | |
180 | ADD_KNOWN_IID(OleAdviseHolder), | |
181 | ADD_KNOWN_IID(OleCache), | |
182 | ADD_KNOWN_IID(OleCache2), | |
183 | ADD_KNOWN_IID(OleCacheControl), | |
184 | ADD_KNOWN_IID(OleClientSite), | |
185 | ADD_KNOWN_IID(OleContainer), | |
186 | ADD_KNOWN_IID(OleInPlaceActiveObject), | |
187 | ADD_KNOWN_IID(OleInPlaceFrame), | |
188 | ADD_KNOWN_IID(OleInPlaceObject), | |
189 | ADD_KNOWN_IID(OleInPlaceSite), | |
190 | ADD_KNOWN_IID(OleInPlaceUIWindow), | |
191 | ADD_KNOWN_IID(OleItemContainer), | |
192 | ADD_KNOWN_IID(OleLink), | |
193 | ADD_KNOWN_IID(OleManager), | |
194 | ADD_KNOWN_IID(OleObject), | |
195 | ADD_KNOWN_IID(OlePresObj), | |
196 | ADD_KNOWN_IID(OleWindow), | |
197 | ADD_KNOWN_IID(PSFactory), | |
198 | ADD_KNOWN_IID(ParseDisplayName), | |
199 | ADD_KNOWN_IID(Persist), | |
200 | ADD_KNOWN_IID(PersistFile), | |
201 | ADD_KNOWN_IID(PersistStorage), | |
202 | ADD_KNOWN_IID(PersistStream), | |
203 | ADD_KNOWN_IID(ProxyManager), | |
204 | ADD_KNOWN_IID(RootStorage), | |
205 | ADD_KNOWN_IID(RpcChannel), | |
206 | ADD_KNOWN_IID(RpcProxy), | |
207 | ADD_KNOWN_IID(RpcStub), | |
208 | ADD_KNOWN_IID(RunnableObject), | |
209 | ADD_KNOWN_IID(RunningObjectTable), | |
210 | ADD_KNOWN_IID(StdMarshalInfo), | |
211 | ADD_KNOWN_IID(Storage), | |
212 | ADD_KNOWN_IID(Stream), | |
213 | ADD_KNOWN_IID(StubManager), | |
214 | ADD_KNOWN_IID(Unknown), | |
215 | ADD_KNOWN_IID(ViewObject), | |
216 | ADD_KNOWN_IID(ViewObject2), | |
217 | }; | |
218 | ||
219 | // don't clobber preprocessor name space | |
220 | #undef ADD_KNOWN_IID | |
221 | ||
222 | // try to find the interface in the table | |
c86f1403 | 223 | for ( size_t ui = 0; ui < WXSIZEOF(aKnownIids); ui++ ) { |
bbf1f0e5 KB |
224 | if ( riid == *aKnownIids[ui].pIid ) { |
225 | return aKnownIids[ui].szName; | |
226 | } | |
227 | } | |
228 | ||
4676948b | 229 | #ifndef __WXWINCE__ |
bbf1f0e5 | 230 | // unknown IID, just transform to string |
f6bcfd97 BP |
231 | Uuid uuid(riid); |
232 | return wxString((const wxChar *)uuid); | |
4676948b JS |
233 | #else |
234 | return wxEmptyString; | |
235 | #endif | |
bbf1f0e5 KB |
236 | } |
237 | ||
f6bcfd97 | 238 | void wxLogQueryInterface(const wxChar *szInterface, REFIID riid) |
bbf1f0e5 | 239 | { |
ba14d986 | 240 | wxLogTrace(wxTRACE_OleCalls, wxT("%s::QueryInterface (iid = %s)"), |
f6bcfd97 | 241 | szInterface, GetIidName(riid).c_str()); |
bbf1f0e5 KB |
242 | } |
243 | ||
f6bcfd97 | 244 | void wxLogAddRef(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 245 | { |
ba14d986 | 246 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::AddRef: m_cRef = %d"), szInterface, cRef + 1); |
bbf1f0e5 KB |
247 | } |
248 | ||
f6bcfd97 | 249 | void wxLogRelease(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 250 | { |
ba14d986 | 251 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::Release: m_cRef = %d"), szInterface, cRef - 1); |
bbf1f0e5 KB |
252 | } |
253 | ||
aeab10d0 JS |
254 | #elif defined(__WXDEBUG__) && defined(__VISUALC__) && (__VISUALC__ <= 1000) |
255 | ||
256 | // For VC++ 4 | |
257 | void wxLogQueryInterface(const char *szInterface, REFIID riid) | |
258 | { | |
259 | wxLogTrace("%s::QueryInterface", szInterface); | |
260 | } | |
261 | ||
262 | void wxLogAddRef(const char *szInterface, ULONG cRef) | |
263 | { | |
264 | wxLogTrace("After %s::AddRef: m_cRef = %d", szInterface, cRef + 1); | |
265 | } | |
266 | ||
267 | void wxLogRelease(const char *szInterface, ULONG cRef) | |
268 | { | |
269 | wxLogTrace("After %s::Release: m_cRef = %d", szInterface, cRef - 1); | |
270 | } | |
271 | ||
81099467 | 272 | #endif // __WXDEBUG__ |
bbf1f0e5 KB |
273 | |
274 | #endif | |
47d67540 | 275 | // wxUSE_DRAG_AND_DROP |
ae090fdb JS |
276 | |
277 | #endif | |
278 | // __CYGWIN10__ | |
279 | ||
21709999 JS |
280 | #endif |
281 | // wxUSE_OLE |