]>
Commit | Line | Data |
---|---|---|
bbf1f0e5 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: ole/oleutils.cpp | |
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__) | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
3096bd2f VZ |
27 | #include "wx/setup.h" |
28 | #include "wx/log.h" | |
bbf1f0e5 | 29 | |
21709999 JS |
30 | #if wxUSE_OLE |
31 | ||
ae090fdb JS |
32 | #ifndef __CYGWIN10__ |
33 | ||
4676948b JS |
34 | #include "wx/msw/private.h" |
35 | ||
36 | #ifdef __WXWINCE__ | |
37 | #include <winreg.h> | |
38 | #include <ole2.h> | |
39 | ||
40 | #define GUID_DEFINED | |
41 | #define UUID_DEFINED | |
42 | #endif | |
bbf1f0e5 KB |
43 | |
44 | // OLE | |
4676948b | 45 | #ifndef __WXWINCE__ |
3096bd2f | 46 | #include "wx/msw/ole/uuid.h" |
4676948b JS |
47 | #endif |
48 | ||
3096bd2f | 49 | #include "wx/msw/ole/oleutils.h" |
bbf1f0e5 | 50 | |
3f4a0c5b VZ |
51 | #if defined(__VISUALC__) && (__VISUALC__ > 1000) |
52 | #include <docobj.h> | |
bbf1f0e5 KB |
53 | #endif |
54 | ||
55 | // ============================================================================ | |
56 | // Implementation | |
57 | // ============================================================================ | |
58 | ||
0a0e6a5b | 59 | // return true if the iid is in the array |
bbf1f0e5 KB |
60 | bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount) |
61 | { | |
62 | for ( size_t i = 0; i < nCount; i++ ) { | |
63 | if ( riid == *aIids[i] ) | |
0a0e6a5b | 64 | return true; |
bbf1f0e5 KB |
65 | } |
66 | ||
0a0e6a5b | 67 | return false; |
bbf1f0e5 KB |
68 | } |
69 | ||
94113cc5 JS |
70 | BSTR wxConvertStringToOle(const wxString& str) |
71 | { | |
72 | /* | |
73 | unsigned int len = strlen((const char*) str); | |
74 | unsigned short* s = new unsigned short[len*2+2]; | |
75 | unsigned int i; | |
76 | memset(s, 0, len*2+2); | |
77 | for (i=0; i < len; i++) | |
78 | s[i*2] = str[i]; | |
79 | */ | |
80 | wxBasicString bstr(str.mb_str()); | |
81 | return bstr.Get(); | |
82 | } | |
83 | ||
84 | wxString wxConvertStringFromOle(BSTR bStr) | |
85 | { | |
86 | #if wxUSE_UNICODE | |
87 | wxString str(bStr); | |
88 | #else | |
89 | int len = SysStringLen(bStr) + 1; | |
90 | char *buf = new char[len]; | |
91 | (void)wcstombs( buf, bStr, len); | |
92 | wxString str(buf); | |
93 | delete[] buf; | |
94 | #endif | |
95 | return str; | |
96 | } | |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
99 | // wxBasicString | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | // ctor takes an ANSI string and transforms it to Unicode | |
103 | wxBasicString::wxBasicString(const char *sz) | |
104 | { | |
105 | Init(sz); | |
106 | } | |
107 | ||
108 | // ctor takes an ANSI or Unicode string and transforms it to Unicode | |
109 | wxBasicString::wxBasicString(const wxString& str) | |
110 | { | |
111 | #if wxUSE_UNICODE | |
112 | m_wzBuf = new OLECHAR[str.Length() + 1]; | |
113 | memcpy(m_wzBuf, str.c_str(), str.Length()*2); | |
114 | m_wzBuf[str.Length()] = L'\0'; | |
115 | #else | |
116 | Init(str.c_str()); | |
117 | #endif | |
118 | } | |
119 | ||
120 | // Takes an ANSI string and transforms it to Unicode | |
121 | void wxBasicString::Init(const char *sz) | |
122 | { | |
123 | // get the size of required buffer | |
124 | UINT lenAnsi = strlen(sz); | |
125 | #ifdef __MWERKS__ | |
126 | UINT lenWide = lenAnsi * 2 ; | |
127 | #else | |
128 | UINT lenWide = mbstowcs(NULL, sz, lenAnsi); | |
129 | #endif | |
130 | ||
131 | if ( lenWide > 0 ) { | |
132 | m_wzBuf = new OLECHAR[lenWide + 1]; | |
133 | mbstowcs(m_wzBuf, sz, lenAnsi); | |
134 | m_wzBuf[lenWide] = L'\0'; | |
135 | } | |
136 | else { | |
137 | m_wzBuf = NULL; | |
138 | } | |
139 | } | |
140 | ||
141 | // dtor frees memory | |
142 | wxBasicString::~wxBasicString() | |
143 | { | |
144 | delete [] m_wzBuf; | |
145 | } | |
146 | ||
8c18da2e | 147 | #if wxUSE_DATAOBJ |
c740f496 | 148 | |
bbf1f0e5 KB |
149 | // ---------------------------------------------------------------------------- |
150 | // Debug support | |
151 | // ---------------------------------------------------------------------------- | |
152 | ||
ba14d986 | 153 | #if defined(__WXDEBUG__) && ( ( defined(__VISUALC__) && (__VISUALC__ > 1000) ) || defined(__MWERKS__) ) |
f6bcfd97 | 154 | static wxString GetIidName(REFIID riid) |
bbf1f0e5 KB |
155 | { |
156 | // an association between symbolic name and numeric value of an IID | |
157 | struct KNOWN_IID { | |
158 | const IID *pIid; | |
f6bcfd97 | 159 | const wxChar *szName; |
bbf1f0e5 KB |
160 | }; |
161 | ||
162 | // construct the table containing all known interfaces | |
f6bcfd97 | 163 | #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) } |
bbf1f0e5 KB |
164 | |
165 | static const KNOWN_IID aKnownIids[] = { | |
166 | ADD_KNOWN_IID(AdviseSink), | |
167 | ADD_KNOWN_IID(AdviseSink2), | |
168 | ADD_KNOWN_IID(BindCtx), | |
169 | ADD_KNOWN_IID(ClassFactory), | |
ba14d986 | 170 | #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__) |
bbf1f0e5 KB |
171 | ADD_KNOWN_IID(ContinueCallback), |
172 | ADD_KNOWN_IID(EnumOleDocumentViews), | |
173 | ADD_KNOWN_IID(OleCommandTarget), | |
174 | ADD_KNOWN_IID(OleDocument), | |
175 | ADD_KNOWN_IID(OleDocumentSite), | |
176 | ADD_KNOWN_IID(OleDocumentView), | |
177 | ADD_KNOWN_IID(Print), | |
27a9bd48 | 178 | #endif |
bbf1f0e5 KB |
179 | ADD_KNOWN_IID(DataAdviseHolder), |
180 | ADD_KNOWN_IID(DataObject), | |
181 | ADD_KNOWN_IID(Debug), | |
182 | ADD_KNOWN_IID(DebugStream), | |
183 | ADD_KNOWN_IID(DfReserved1), | |
184 | ADD_KNOWN_IID(DfReserved2), | |
185 | ADD_KNOWN_IID(DfReserved3), | |
186 | ADD_KNOWN_IID(Dispatch), | |
187 | ADD_KNOWN_IID(DropSource), | |
188 | ADD_KNOWN_IID(DropTarget), | |
189 | ADD_KNOWN_IID(EnumCallback), | |
190 | ADD_KNOWN_IID(EnumFORMATETC), | |
191 | ADD_KNOWN_IID(EnumGeneric), | |
192 | ADD_KNOWN_IID(EnumHolder), | |
193 | ADD_KNOWN_IID(EnumMoniker), | |
194 | ADD_KNOWN_IID(EnumOLEVERB), | |
195 | ADD_KNOWN_IID(EnumSTATDATA), | |
196 | ADD_KNOWN_IID(EnumSTATSTG), | |
197 | ADD_KNOWN_IID(EnumString), | |
198 | ADD_KNOWN_IID(EnumUnknown), | |
199 | ADD_KNOWN_IID(EnumVARIANT), | |
200 | ADD_KNOWN_IID(ExternalConnection), | |
201 | ADD_KNOWN_IID(InternalMoniker), | |
202 | ADD_KNOWN_IID(LockBytes), | |
203 | ADD_KNOWN_IID(Malloc), | |
204 | ADD_KNOWN_IID(Marshal), | |
205 | ADD_KNOWN_IID(MessageFilter), | |
206 | ADD_KNOWN_IID(Moniker), | |
207 | ADD_KNOWN_IID(OleAdviseHolder), | |
208 | ADD_KNOWN_IID(OleCache), | |
209 | ADD_KNOWN_IID(OleCache2), | |
210 | ADD_KNOWN_IID(OleCacheControl), | |
211 | ADD_KNOWN_IID(OleClientSite), | |
212 | ADD_KNOWN_IID(OleContainer), | |
213 | ADD_KNOWN_IID(OleInPlaceActiveObject), | |
214 | ADD_KNOWN_IID(OleInPlaceFrame), | |
215 | ADD_KNOWN_IID(OleInPlaceObject), | |
216 | ADD_KNOWN_IID(OleInPlaceSite), | |
217 | ADD_KNOWN_IID(OleInPlaceUIWindow), | |
218 | ADD_KNOWN_IID(OleItemContainer), | |
219 | ADD_KNOWN_IID(OleLink), | |
220 | ADD_KNOWN_IID(OleManager), | |
221 | ADD_KNOWN_IID(OleObject), | |
222 | ADD_KNOWN_IID(OlePresObj), | |
223 | ADD_KNOWN_IID(OleWindow), | |
224 | ADD_KNOWN_IID(PSFactory), | |
225 | ADD_KNOWN_IID(ParseDisplayName), | |
226 | ADD_KNOWN_IID(Persist), | |
227 | ADD_KNOWN_IID(PersistFile), | |
228 | ADD_KNOWN_IID(PersistStorage), | |
229 | ADD_KNOWN_IID(PersistStream), | |
230 | ADD_KNOWN_IID(ProxyManager), | |
231 | ADD_KNOWN_IID(RootStorage), | |
232 | ADD_KNOWN_IID(RpcChannel), | |
233 | ADD_KNOWN_IID(RpcProxy), | |
234 | ADD_KNOWN_IID(RpcStub), | |
235 | ADD_KNOWN_IID(RunnableObject), | |
236 | ADD_KNOWN_IID(RunningObjectTable), | |
237 | ADD_KNOWN_IID(StdMarshalInfo), | |
238 | ADD_KNOWN_IID(Storage), | |
239 | ADD_KNOWN_IID(Stream), | |
240 | ADD_KNOWN_IID(StubManager), | |
241 | ADD_KNOWN_IID(Unknown), | |
242 | ADD_KNOWN_IID(ViewObject), | |
243 | ADD_KNOWN_IID(ViewObject2), | |
244 | }; | |
245 | ||
246 | // don't clobber preprocessor name space | |
247 | #undef ADD_KNOWN_IID | |
248 | ||
249 | // try to find the interface in the table | |
c86f1403 | 250 | for ( size_t ui = 0; ui < WXSIZEOF(aKnownIids); ui++ ) { |
bbf1f0e5 KB |
251 | if ( riid == *aKnownIids[ui].pIid ) { |
252 | return aKnownIids[ui].szName; | |
253 | } | |
254 | } | |
255 | ||
4676948b | 256 | #ifndef __WXWINCE__ |
bbf1f0e5 | 257 | // unknown IID, just transform to string |
f6bcfd97 BP |
258 | Uuid uuid(riid); |
259 | return wxString((const wxChar *)uuid); | |
4676948b JS |
260 | #else |
261 | return wxEmptyString; | |
262 | #endif | |
bbf1f0e5 KB |
263 | } |
264 | ||
f6bcfd97 | 265 | void wxLogQueryInterface(const wxChar *szInterface, REFIID riid) |
bbf1f0e5 | 266 | { |
ba14d986 | 267 | wxLogTrace(wxTRACE_OleCalls, wxT("%s::QueryInterface (iid = %s)"), |
f6bcfd97 | 268 | szInterface, GetIidName(riid).c_str()); |
bbf1f0e5 KB |
269 | } |
270 | ||
f6bcfd97 | 271 | void wxLogAddRef(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 272 | { |
ba14d986 | 273 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::AddRef: m_cRef = %d"), szInterface, cRef + 1); |
bbf1f0e5 KB |
274 | } |
275 | ||
f6bcfd97 | 276 | void wxLogRelease(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 277 | { |
ba14d986 | 278 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::Release: m_cRef = %d"), szInterface, cRef - 1); |
bbf1f0e5 KB |
279 | } |
280 | ||
aeab10d0 JS |
281 | #elif defined(__WXDEBUG__) && defined(__VISUALC__) && (__VISUALC__ <= 1000) |
282 | ||
283 | // For VC++ 4 | |
284 | void wxLogQueryInterface(const char *szInterface, REFIID riid) | |
285 | { | |
286 | wxLogTrace("%s::QueryInterface", szInterface); | |
287 | } | |
288 | ||
289 | void wxLogAddRef(const char *szInterface, ULONG cRef) | |
290 | { | |
291 | wxLogTrace("After %s::AddRef: m_cRef = %d", szInterface, cRef + 1); | |
292 | } | |
293 | ||
294 | void wxLogRelease(const char *szInterface, ULONG cRef) | |
295 | { | |
296 | wxLogTrace("After %s::Release: m_cRef = %d", szInterface, cRef - 1); | |
297 | } | |
298 | ||
81099467 | 299 | #endif // __WXDEBUG__ |
bbf1f0e5 KB |
300 | |
301 | #endif | |
47d67540 | 302 | // wxUSE_DRAG_AND_DROP |
ae090fdb JS |
303 | |
304 | #endif | |
305 | // __CYGWIN10__ | |
306 | ||
21709999 JS |
307 | #endif |
308 | // wxUSE_OLE | |
309 |