]>
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 |
d0400222 | 61 | WXDLLEXPORT bool IsIidFromList(REFIID riid, const IID *aIids[], size_t nCount) |
bbf1f0e5 KB |
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 | ||
59af032a VZ |
83 | const int len = SysStringLen(bStr); |
84 | ||
94113cc5 | 85 | #if wxUSE_UNICODE |
59af032a | 86 | wxString str(bStr, len); |
94113cc5 | 87 | #else |
bba85010 | 88 | wxString str; |
9968f7b4 | 89 | if (len) |
bba85010 | 90 | { |
9968f7b4 VZ |
91 | wxStringBufferLength buf(str, len); // asserts if len == 0 |
92 | buf.SetLength(WideCharToMultiByte(CP_ACP, 0 /* no flags */, | |
93 | bStr, len /* not necessarily NUL-terminated */, | |
94 | buf, len, | |
95 | NULL, NULL /* no default char */)); | |
bba85010 | 96 | } |
94113cc5 | 97 | #endif |
59af032a | 98 | |
94113cc5 JS |
99 | return str; |
100 | } | |
101 | ||
102 | // ---------------------------------------------------------------------------- | |
103 | // wxBasicString | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
a518e508 | 106 | wxBasicString::wxBasicString(const wxString& str) |
94113cc5 | 107 | { |
a518e508 | 108 | m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent)); |
94113cc5 JS |
109 | } |
110 | ||
a518e508 | 111 | wxBasicString::wxBasicString(const wxBasicString& src) |
94113cc5 | 112 | { |
a518e508 | 113 | m_bstrBuf = src.Get(); |
94113cc5 JS |
114 | } |
115 | ||
a518e508 | 116 | wxBasicString& wxBasicString::operator=(const wxBasicString& src) |
94113cc5 | 117 | { |
a518e508 VZ |
118 | SysReAllocString(&m_bstrBuf, src); |
119 | return *this; | |
94113cc5 JS |
120 | } |
121 | ||
94113cc5 JS |
122 | wxBasicString::~wxBasicString() |
123 | { | |
a518e508 | 124 | SysFreeString(m_bstrBuf); |
94113cc5 JS |
125 | } |
126 | ||
a2fd865b VS |
127 | |
128 | // ---------------------------------------------------------------------------- | |
129 | // Convert variants | |
130 | // ---------------------------------------------------------------------------- | |
131 | ||
132 | #if wxUSE_VARIANT | |
133 | ||
f0d38b65 VZ |
134 | namespace |
135 | { | |
136 | ||
137 | // Helper class for creating and filling SAFEARRAY. To use it, call Create() | |
138 | // first, then SetElement() for each element and finally Detach() the SAFEARRAY | |
139 | // from it if you don't want it to be deleted when this class is. | |
140 | class wxSafeArrayHelper | |
141 | { | |
142 | public: | |
143 | wxSafeArrayHelper(); | |
144 | ~wxSafeArrayHelper(); | |
145 | ||
146 | bool Create(VARTYPE vt, long count); // creates and locks the array | |
147 | ||
148 | bool SetElement(size_t index, const wxVariant& variant); | |
149 | bool SetElement(size_t index, const wxString& str); | |
150 | ||
151 | SAFEARRAY* Detach(); // unlocks the array and gives up its ownership | |
152 | ||
153 | private: | |
154 | void Unlock(); | |
155 | ||
156 | SAFEARRAY* m_array; | |
157 | }; | |
158 | ||
159 | wxSafeArrayHelper::wxSafeArrayHelper() | |
160 | { | |
161 | m_array = NULL; | |
162 | } | |
163 | ||
164 | wxSafeArrayHelper::~wxSafeArrayHelper() | |
165 | { | |
166 | if ( m_array ) | |
167 | { | |
168 | Unlock(); | |
169 | SafeArrayDestroy(m_array); | |
170 | } | |
171 | } | |
172 | ||
173 | bool wxSafeArrayHelper::Create(VARTYPE vt, long count) | |
174 | { | |
175 | SAFEARRAYBOUND saBound; | |
176 | ||
177 | saBound.lLbound = 0; | |
178 | saBound.cElements = count; | |
179 | m_array = SafeArrayCreate(vt, 1, &saBound); | |
180 | if ( !m_array ) | |
181 | return false; | |
182 | return SUCCEEDED( SafeArrayLock(m_array) ); | |
183 | } | |
184 | ||
185 | bool wxSafeArrayHelper::SetElement(size_t index, const wxVariant& variant) | |
186 | { | |
187 | VARIANT* data = (VARIANT*)m_array->pvData; | |
188 | return wxConvertVariantToOle(variant, data[index]); | |
189 | } | |
190 | ||
191 | bool wxSafeArrayHelper::SetElement(size_t index, const wxString& str) | |
192 | { | |
193 | BSTR bstr = wxConvertStringToOle(str); | |
194 | ||
195 | if ( !bstr && !str.empty() ) | |
196 | { | |
197 | // BSTR can be NULL for empty strings but if the string was | |
198 | // not empty, it means we failed to allocate memory for it. | |
199 | return false; | |
200 | } | |
201 | ||
202 | BSTR* data = (BSTR*)m_array->pvData; | |
203 | data[index] = bstr; | |
204 | return true; | |
205 | } | |
206 | ||
207 | SAFEARRAY* wxSafeArrayHelper::Detach() | |
208 | { | |
209 | Unlock(); | |
210 | SAFEARRAY* result = m_array; | |
211 | m_array = NULL; | |
212 | return result; | |
213 | } | |
214 | ||
215 | void wxSafeArrayHelper::Unlock() | |
216 | { | |
217 | if ( m_array ) | |
218 | SafeArrayUnlock(m_array); | |
219 | } | |
220 | ||
221 | } // unnamed namespace | |
222 | ||
223 | ||
6c32fb8f VZ |
224 | // ---------------------------------------------------------------------------- |
225 | // wxVariantDataCurrency | |
226 | // ---------------------------------------------------------------------------- | |
227 | ||
228 | ||
229 | #if wxUSE_ANY | |
230 | ||
231 | bool wxVariantDataCurrency::GetAsAny(wxAny* any) const | |
232 | { | |
233 | *any = m_value; | |
234 | return true; | |
235 | } | |
236 | ||
237 | wxVariantData* wxVariantDataCurrency::VariantDataFactory(const wxAny& any) | |
238 | { | |
239 | return new wxVariantDataCurrency(wxANY_AS(any, CURRENCY)); | |
240 | } | |
241 | ||
242 | REGISTER_WXANY_CONVERSION(CURRENCY, wxVariantDataCurrency) | |
243 | ||
244 | #endif // wxUSE_ANY | |
245 | ||
246 | bool wxVariantDataCurrency::Eq(wxVariantData& data) const | |
247 | { | |
248 | wxASSERT_MSG( (data.GetType() == wxS("currency")), | |
249 | "wxVariantDataCurrency::Eq: argument mismatch" ); | |
250 | ||
251 | wxVariantDataCurrency& otherData = (wxVariantDataCurrency&) data; | |
252 | ||
253 | return otherData.m_value.int64 == m_value.int64; | |
254 | } | |
255 | ||
256 | #if wxUSE_STD_IOSTREAM | |
257 | bool wxVariantDataCurrency::Write(wxSTD ostream& str) const | |
258 | { | |
259 | wxString s; | |
260 | Write(s); | |
261 | str << s; | |
262 | return true; | |
263 | } | |
264 | #endif | |
265 | ||
266 | bool wxVariantDataCurrency::Write(wxString& str) const | |
267 | { | |
268 | BSTR bStr = NULL; | |
269 | if ( SUCCEEDED(VarBstrFromCy(m_value, LOCALE_USER_DEFAULT, 0, &bStr)) ) | |
270 | { | |
271 | str = wxConvertStringFromOle(bStr); | |
272 | SysFreeString(bStr); | |
273 | return true; | |
274 | } | |
275 | return false; | |
276 | } | |
277 | ||
278 | // ---------------------------------------------------------------------------- | |
279 | // wxVariantDataErrorCode | |
280 | // ---------------------------------------------------------------------------- | |
281 | ||
282 | #if wxUSE_ANY | |
283 | ||
284 | bool wxVariantDataErrorCode::GetAsAny(wxAny* any) const | |
285 | { | |
286 | *any = m_value; | |
287 | return true; | |
288 | } | |
289 | ||
290 | wxVariantData* wxVariantDataErrorCode::VariantDataFactory(const wxAny& any) | |
291 | { | |
292 | return new wxVariantDataErrorCode(wxANY_AS(any, SCODE)); | |
293 | } | |
294 | ||
295 | REGISTER_WXANY_CONVERSION(SCODE, wxVariantDataErrorCode) | |
296 | ||
297 | #endif // wxUSE_ANY | |
298 | ||
299 | bool wxVariantDataErrorCode::Eq(wxVariantData& data) const | |
300 | { | |
301 | wxASSERT_MSG( (data.GetType() == wxS("errorcode")), | |
302 | "wxVariantDataErrorCode::Eq: argument mismatch" ); | |
303 | ||
304 | wxVariantDataErrorCode& otherData = (wxVariantDataErrorCode&) data; | |
305 | ||
306 | return otherData.m_value == m_value; | |
307 | } | |
308 | ||
309 | #if wxUSE_STD_IOSTREAM | |
310 | bool wxVariantDataErrorCode::Write(wxSTD ostream& str) const | |
311 | { | |
312 | wxString s; | |
313 | Write(s); | |
314 | str << s; | |
315 | return true; | |
316 | } | |
317 | #endif | |
318 | ||
319 | bool wxVariantDataErrorCode::Write(wxString& str) const | |
320 | { | |
321 | str << m_value; | |
322 | return true; | |
323 | } | |
324 | ||
325 | ||
326 | ||
a2fd865b VS |
327 | WXDLLEXPORT bool wxConvertVariantToOle(const wxVariant& variant, VARIANTARG& oleVariant) |
328 | { | |
1fbfbfb0 | 329 | VariantInit(&oleVariant); |
a2fd865b VS |
330 | if (variant.IsNull()) |
331 | { | |
332 | oleVariant.vt = VT_NULL; | |
333 | return true; | |
334 | } | |
335 | ||
336 | wxString type(variant.GetType()); | |
337 | ||
6c32fb8f VZ |
338 | if (type == wxT("errorcode")) |
339 | { | |
340 | wxVariantDataErrorCode* const | |
341 | ec = wxDynamicCastVariantData(variant.GetData(), | |
342 | wxVariantDataErrorCode); | |
343 | oleVariant.vt = VT_ERROR; | |
344 | oleVariant.scode = ec->GetValue(); | |
345 | } | |
346 | else if (type == wxT("currency")) | |
347 | { | |
348 | wxVariantDataCurrency* const | |
349 | c = wxDynamicCastVariantData(variant.GetData(), | |
350 | wxVariantDataCurrency); | |
351 | oleVariant.vt = VT_CY; | |
352 | oleVariant.cyVal = c->GetValue(); | |
353 | } | |
354 | else if (type == wxT("long")) | |
a2fd865b VS |
355 | { |
356 | oleVariant.vt = VT_I4; | |
357 | oleVariant.lVal = variant.GetLong() ; | |
358 | } | |
30ee0b97 VZ |
359 | // Original VC6 came with SDK too old to contain VARIANT::llVal declaration |
360 | // and there doesn't seem to be any way to test for it as Microsoft simply | |
361 | // added it to the later version of oaidl.h without changing anything else. | |
362 | // So assume it's not present for VC6, even though it might be if an | |
363 | // updated SDK is used. In this case the user would need to disable this | |
364 | // check himself. | |
365 | #if wxUSE_LONGLONG && !defined(__VISUALC6__) | |
4b666be6 VZ |
366 | else if (type == wxT("longlong")) |
367 | { | |
368 | oleVariant.vt = VT_I8; | |
369 | oleVariant.llVal = variant.GetLongLong().GetValue(); | |
370 | } | |
371 | #endif | |
a2fd865b VS |
372 | else if (type == wxT("char")) |
373 | { | |
374 | oleVariant.vt=VT_I1; // Signed Char | |
375 | oleVariant.cVal=variant.GetChar(); | |
376 | } | |
a2fd865b VS |
377 | else if (type == wxT("double")) |
378 | { | |
379 | oleVariant.vt = VT_R8; | |
380 | oleVariant.dblVal = variant.GetDouble(); | |
381 | } | |
382 | else if (type == wxT("bool")) | |
383 | { | |
384 | oleVariant.vt = VT_BOOL; | |
85ecb1d5 | 385 | oleVariant.boolVal = variant.GetBool() ? VARIANT_TRUE : VARIANT_FALSE; |
a2fd865b VS |
386 | } |
387 | else if (type == wxT("string")) | |
388 | { | |
389 | wxString str( variant.GetString() ); | |
390 | oleVariant.vt = VT_BSTR; | |
391 | oleVariant.bstrVal = wxConvertStringToOle(str); | |
392 | } | |
393 | #if wxUSE_DATETIME | |
394 | else if (type == wxT("datetime")) | |
395 | { | |
396 | wxDateTime date( variant.GetDateTime() ); | |
397 | oleVariant.vt = VT_DATE; | |
398 | ||
399 | SYSTEMTIME st; | |
400 | date.GetAsMSWSysTime(&st); | |
401 | ||
402 | SystemTimeToVariantTime(&st, &oleVariant.date); | |
403 | } | |
404 | #endif | |
405 | else if (type == wxT("void*")) | |
406 | { | |
407 | oleVariant.vt = VT_DISPATCH; | |
408 | oleVariant.pdispVal = (IDispatch*) variant.GetVoidPtr(); | |
409 | } | |
f0d38b65 | 410 | else if (type == wxT("list")) |
a2fd865b | 411 | { |
f0d38b65 VZ |
412 | wxSafeArrayHelper sah; |
413 | ||
414 | if (!sah.Create(VT_VARIANT, variant.GetCount())) | |
a2fd865b VS |
415 | return false; |
416 | ||
f0d38b65 | 417 | for (size_t i = 0; i < variant.GetCount(); i++) |
a2fd865b | 418 | { |
f0d38b65 VZ |
419 | if (!sah.SetElement(i, variant[i])) |
420 | return false; | |
a2fd865b VS |
421 | } |
422 | ||
f0d38b65 VZ |
423 | oleVariant.vt = VT_VARIANT | VT_ARRAY; |
424 | oleVariant.parray = sah.Detach(); | |
425 | } | |
426 | else if (type == wxT("arrstring")) | |
427 | { | |
428 | wxArrayString strings(variant.GetArrayString()); | |
429 | wxSafeArrayHelper sah; | |
430 | ||
431 | if (!sah.Create(VT_BSTR, strings.GetCount())) | |
82c372a7 | 432 | return false; |
f0d38b65 VZ |
433 | |
434 | for (size_t i = 0; i < strings.GetCount(); i++) | |
435 | { | |
436 | if (!sah.SetElement(i, strings[i])) | |
437 | return false; | |
82c372a7 | 438 | } |
a2fd865b | 439 | |
f0d38b65 VZ |
440 | oleVariant.vt = VT_BSTR | VT_ARRAY; |
441 | oleVariant.parray = sah.Detach(); | |
a2fd865b VS |
442 | } |
443 | else | |
444 | { | |
445 | oleVariant.vt = VT_NULL; | |
446 | return false; | |
447 | } | |
448 | return true; | |
449 | } | |
450 | ||
451 | #ifndef VT_TYPEMASK | |
452 | #define VT_TYPEMASK 0xfff | |
453 | #endif | |
454 | ||
455 | WXDLLEXPORT bool | |
456 | wxConvertOleToVariant(const VARIANTARG& oleVariant, wxVariant& variant) | |
457 | { | |
458 | bool ok = true; | |
459 | if ( oleVariant.vt & VT_ARRAY ) | |
460 | { | |
461 | ||
462 | // Compute the total number of elements in all array dimensions | |
463 | int cElements = 1; | |
464 | for ( int cDims = 0; cDims < oleVariant.parray->cDims; cDims++ ) | |
465 | cElements *= oleVariant.parray->rgsabound[cDims].cElements; | |
466 | ||
467 | // Get a pointer to the data | |
468 | void* pvdata; | |
469 | HRESULT hr = SafeArrayAccessData(oleVariant.parray, &pvdata); | |
470 | if ( FAILED(hr) ) | |
471 | return false; | |
472 | ||
473 | switch (oleVariant.vt & VT_TYPEMASK) | |
474 | { | |
475 | case VT_VARIANT: | |
476 | { | |
477 | variant.ClearList(); | |
478 | VARIANTARG *variant_data=(VARIANTARG*)pvdata; | |
479 | for ( int i = 0; i < cElements; i++ ) | |
480 | { | |
481 | VARIANTARG& oleElement = variant_data[i]; | |
482 | wxVariant vElement; | |
483 | if ( !wxConvertOleToVariant(oleElement, vElement) ) | |
484 | { | |
485 | ok = false; | |
486 | variant.ClearList(); | |
487 | break; | |
488 | } | |
489 | ||
490 | variant.Append(vElement); | |
491 | } | |
492 | } | |
493 | break; | |
494 | ||
495 | case VT_BSTR: | |
496 | { | |
497 | wxArrayString strings; | |
498 | BSTR *string_val=(BSTR*)pvdata; | |
499 | for ( int i = 0; i < cElements; ++i ) | |
500 | { | |
501 | wxString str=wxConvertStringFromOle(*string_val); | |
502 | strings.Add(str); | |
503 | ++string_val; | |
504 | } | |
505 | variant=strings; | |
506 | } | |
507 | break; | |
508 | ||
509 | default: | |
510 | wxLogDebug(wxT("unhandled VT_ARRAY type %x in wxConvertOleToVariant"), | |
511 | oleVariant.vt & VT_TYPEMASK); | |
512 | variant = wxVariant(); | |
513 | ok = false; | |
514 | break; | |
515 | } | |
516 | ||
517 | SafeArrayUnaccessData(oleVariant.parray); | |
518 | } | |
519 | else if ( oleVariant.vt & VT_BYREF ) | |
520 | { | |
521 | switch ( oleVariant.vt & VT_TYPEMASK ) | |
522 | { | |
523 | case VT_VARIANT: | |
524 | { | |
525 | VARIANTARG& oleReference = *((LPVARIANT)oleVariant.byref); | |
526 | if (!wxConvertOleToVariant(oleReference,variant)) | |
527 | return false; | |
528 | break; | |
529 | } | |
530 | ||
531 | default: | |
532 | wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: [as yet] unhandled reference %X"), | |
533 | oleVariant.vt); | |
534 | return false; | |
535 | } | |
536 | } | |
537 | else // simply type (not array or reference) | |
538 | { | |
539 | switch ( oleVariant.vt & VT_TYPEMASK ) | |
540 | { | |
6c32fb8f VZ |
541 | case VT_ERROR: |
542 | variant.SetData(new wxVariantDataErrorCode(oleVariant.scode)); | |
543 | break; | |
544 | ||
545 | case VT_CY: | |
546 | variant.SetData(new wxVariantDataCurrency(oleVariant.cyVal)); | |
547 | break; | |
548 | ||
a2fd865b VS |
549 | case VT_BSTR: |
550 | { | |
551 | wxString str(wxConvertStringFromOle(oleVariant.bstrVal)); | |
552 | variant = str; | |
553 | } | |
554 | break; | |
555 | ||
556 | case VT_DATE: | |
557 | #if wxUSE_DATETIME | |
558 | { | |
559 | SYSTEMTIME st; | |
560 | VariantTimeToSystemTime(oleVariant.date, &st); | |
561 | ||
562 | wxDateTime date; | |
563 | date.SetFromMSWSysTime(st); | |
564 | variant = date; | |
565 | } | |
566 | #endif // wxUSE_DATETIME | |
567 | break; | |
568 | ||
30ee0b97 VZ |
569 | // See the comment before the __VISUALC6__ test above. |
570 | #if wxUSE_LONGLONG && !defined(__VISUALC6__) | |
4b666be6 VZ |
571 | case VT_I8: |
572 | variant = wxLongLong(oleVariant.llVal); | |
573 | break; | |
574 | #endif // wxUSE_LONGLONG | |
575 | ||
a2fd865b VS |
576 | case VT_I4: |
577 | variant = (long) oleVariant.lVal; | |
578 | break; | |
579 | ||
580 | case VT_I2: | |
581 | variant = (long) oleVariant.iVal; | |
582 | break; | |
583 | ||
584 | case VT_BOOL: | |
585 | variant = oleVariant.boolVal != 0; | |
586 | break; | |
587 | ||
51909b8b VZ |
588 | case VT_R4: |
589 | variant = oleVariant.fltVal; | |
590 | break; | |
591 | ||
a2fd865b VS |
592 | case VT_R8: |
593 | variant = oleVariant.dblVal; | |
594 | break; | |
595 | ||
596 | case VT_DISPATCH: | |
597 | variant = (void*) oleVariant.pdispVal; | |
598 | break; | |
599 | ||
600 | case VT_NULL: | |
601 | variant.MakeNull(); | |
602 | break; | |
603 | ||
604 | case VT_EMPTY: | |
605 | break; // Ignore Empty Variant, used only during destruction of objects | |
606 | ||
607 | default: | |
608 | wxLogError(wxT("wxAutomationObject::ConvertOleToVariant: Unknown variant value type %X -> %X"), | |
609 | oleVariant.vt,oleVariant.vt&VT_TYPEMASK); | |
610 | return false; | |
611 | } | |
612 | } | |
613 | ||
614 | return ok; | |
615 | } | |
616 | ||
617 | #endif // wxUSE_VARIANT | |
618 | ||
c740f496 | 619 | |
bbf1f0e5 KB |
620 | // ---------------------------------------------------------------------------- |
621 | // Debug support | |
622 | // ---------------------------------------------------------------------------- | |
623 | ||
a2fd865b VS |
624 | #if wxUSE_DATAOBJ |
625 | ||
2415cf67 | 626 | #if wxDEBUG_LEVEL && (( defined(__VISUALC__) && (__VISUALC__ > 1000) )) |
f6bcfd97 | 627 | static wxString GetIidName(REFIID riid) |
bbf1f0e5 KB |
628 | { |
629 | // an association between symbolic name and numeric value of an IID | |
630 | struct KNOWN_IID { | |
631 | const IID *pIid; | |
f6bcfd97 | 632 | const wxChar *szName; |
bbf1f0e5 KB |
633 | }; |
634 | ||
635 | // construct the table containing all known interfaces | |
9a83f860 | 636 | #define ADD_KNOWN_IID(name) { &IID_I##name, wxT(#name) } |
bbf1f0e5 KB |
637 | |
638 | static const KNOWN_IID aKnownIids[] = { | |
639 | ADD_KNOWN_IID(AdviseSink), | |
640 | ADD_KNOWN_IID(AdviseSink2), | |
641 | ADD_KNOWN_IID(BindCtx), | |
642 | ADD_KNOWN_IID(ClassFactory), | |
2415cf67 | 643 | #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) |
bbf1f0e5 KB |
644 | ADD_KNOWN_IID(ContinueCallback), |
645 | ADD_KNOWN_IID(EnumOleDocumentViews), | |
646 | ADD_KNOWN_IID(OleCommandTarget), | |
647 | ADD_KNOWN_IID(OleDocument), | |
648 | ADD_KNOWN_IID(OleDocumentSite), | |
649 | ADD_KNOWN_IID(OleDocumentView), | |
650 | ADD_KNOWN_IID(Print), | |
27a9bd48 | 651 | #endif |
bbf1f0e5 KB |
652 | ADD_KNOWN_IID(DataAdviseHolder), |
653 | ADD_KNOWN_IID(DataObject), | |
654 | ADD_KNOWN_IID(Debug), | |
655 | ADD_KNOWN_IID(DebugStream), | |
656 | ADD_KNOWN_IID(DfReserved1), | |
657 | ADD_KNOWN_IID(DfReserved2), | |
658 | ADD_KNOWN_IID(DfReserved3), | |
659 | ADD_KNOWN_IID(Dispatch), | |
660 | ADD_KNOWN_IID(DropSource), | |
661 | ADD_KNOWN_IID(DropTarget), | |
662 | ADD_KNOWN_IID(EnumCallback), | |
663 | ADD_KNOWN_IID(EnumFORMATETC), | |
664 | ADD_KNOWN_IID(EnumGeneric), | |
665 | ADD_KNOWN_IID(EnumHolder), | |
666 | ADD_KNOWN_IID(EnumMoniker), | |
667 | ADD_KNOWN_IID(EnumOLEVERB), | |
668 | ADD_KNOWN_IID(EnumSTATDATA), | |
669 | ADD_KNOWN_IID(EnumSTATSTG), | |
670 | ADD_KNOWN_IID(EnumString), | |
671 | ADD_KNOWN_IID(EnumUnknown), | |
672 | ADD_KNOWN_IID(EnumVARIANT), | |
673 | ADD_KNOWN_IID(ExternalConnection), | |
674 | ADD_KNOWN_IID(InternalMoniker), | |
675 | ADD_KNOWN_IID(LockBytes), | |
676 | ADD_KNOWN_IID(Malloc), | |
677 | ADD_KNOWN_IID(Marshal), | |
678 | ADD_KNOWN_IID(MessageFilter), | |
679 | ADD_KNOWN_IID(Moniker), | |
680 | ADD_KNOWN_IID(OleAdviseHolder), | |
681 | ADD_KNOWN_IID(OleCache), | |
682 | ADD_KNOWN_IID(OleCache2), | |
683 | ADD_KNOWN_IID(OleCacheControl), | |
684 | ADD_KNOWN_IID(OleClientSite), | |
685 | ADD_KNOWN_IID(OleContainer), | |
686 | ADD_KNOWN_IID(OleInPlaceActiveObject), | |
687 | ADD_KNOWN_IID(OleInPlaceFrame), | |
688 | ADD_KNOWN_IID(OleInPlaceObject), | |
689 | ADD_KNOWN_IID(OleInPlaceSite), | |
690 | ADD_KNOWN_IID(OleInPlaceUIWindow), | |
691 | ADD_KNOWN_IID(OleItemContainer), | |
692 | ADD_KNOWN_IID(OleLink), | |
693 | ADD_KNOWN_IID(OleManager), | |
694 | ADD_KNOWN_IID(OleObject), | |
695 | ADD_KNOWN_IID(OlePresObj), | |
696 | ADD_KNOWN_IID(OleWindow), | |
697 | ADD_KNOWN_IID(PSFactory), | |
698 | ADD_KNOWN_IID(ParseDisplayName), | |
699 | ADD_KNOWN_IID(Persist), | |
700 | ADD_KNOWN_IID(PersistFile), | |
701 | ADD_KNOWN_IID(PersistStorage), | |
702 | ADD_KNOWN_IID(PersistStream), | |
703 | ADD_KNOWN_IID(ProxyManager), | |
704 | ADD_KNOWN_IID(RootStorage), | |
705 | ADD_KNOWN_IID(RpcChannel), | |
706 | ADD_KNOWN_IID(RpcProxy), | |
707 | ADD_KNOWN_IID(RpcStub), | |
708 | ADD_KNOWN_IID(RunnableObject), | |
709 | ADD_KNOWN_IID(RunningObjectTable), | |
710 | ADD_KNOWN_IID(StdMarshalInfo), | |
711 | ADD_KNOWN_IID(Storage), | |
712 | ADD_KNOWN_IID(Stream), | |
713 | ADD_KNOWN_IID(StubManager), | |
714 | ADD_KNOWN_IID(Unknown), | |
715 | ADD_KNOWN_IID(ViewObject), | |
716 | ADD_KNOWN_IID(ViewObject2), | |
717 | }; | |
718 | ||
719 | // don't clobber preprocessor name space | |
720 | #undef ADD_KNOWN_IID | |
721 | ||
722 | // try to find the interface in the table | |
c86f1403 | 723 | for ( size_t ui = 0; ui < WXSIZEOF(aKnownIids); ui++ ) { |
bbf1f0e5 KB |
724 | if ( riid == *aKnownIids[ui].pIid ) { |
725 | return aKnownIids[ui].szName; | |
726 | } | |
727 | } | |
728 | ||
4676948b | 729 | #ifndef __WXWINCE__ |
bbf1f0e5 | 730 | // unknown IID, just transform to string |
f6bcfd97 BP |
731 | Uuid uuid(riid); |
732 | return wxString((const wxChar *)uuid); | |
4676948b JS |
733 | #else |
734 | return wxEmptyString; | |
735 | #endif | |
bbf1f0e5 KB |
736 | } |
737 | ||
d0400222 | 738 | WXDLLEXPORT void wxLogQueryInterface(const wxChar *szInterface, REFIID riid) |
bbf1f0e5 | 739 | { |
ba14d986 | 740 | wxLogTrace(wxTRACE_OleCalls, wxT("%s::QueryInterface (iid = %s)"), |
f6bcfd97 | 741 | szInterface, GetIidName(riid).c_str()); |
bbf1f0e5 KB |
742 | } |
743 | ||
d0400222 | 744 | WXDLLEXPORT void wxLogAddRef(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 745 | { |
ba14d986 | 746 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::AddRef: m_cRef = %d"), szInterface, cRef + 1); |
bbf1f0e5 KB |
747 | } |
748 | ||
d0400222 | 749 | WXDLLEXPORT void wxLogRelease(const wxChar *szInterface, ULONG cRef) |
bbf1f0e5 | 750 | { |
ba14d986 | 751 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::Release: m_cRef = %d"), szInterface, cRef - 1); |
bbf1f0e5 KB |
752 | } |
753 | ||
4b6a582b | 754 | #endif // wxDEBUG_LEVEL |
aeab10d0 | 755 | |
a2fd865b | 756 | #endif // wxUSE_DATAOBJ |
aeab10d0 | 757 | |
4b6a582b | 758 | #endif // __CYGWIN10__ |
aeab10d0 | 759 | |
4b6a582b | 760 | #endif // wxUSE_OLE |