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