]>
Commit | Line | Data |
---|---|---|
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 | |
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] ) | |
65 | return true; | |
66 | } | |
67 | ||
68 | return false; | |
69 | } | |
70 | ||
71 | WXDLLEXPORT BSTR wxConvertStringToOle(const wxString& str) | |
72 | { | |
73 | return wxBasicString(str).Get(); | |
74 | } | |
75 | ||
76 | WXDLLEXPORT wxString wxConvertStringFromOle(BSTR bStr) | |
77 | { | |
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 | ||
83 | const int len = SysStringLen(bStr); | |
84 | ||
85 | #if wxUSE_UNICODE | |
86 | wxString str(bStr, len); | |
87 | #else | |
88 | wxString str; | |
89 | if (len) | |
90 | { | |
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 */)); | |
96 | } | |
97 | #endif | |
98 | ||
99 | return str; | |
100 | } | |
101 | ||
102 | // ---------------------------------------------------------------------------- | |
103 | // wxBasicString | |
104 | // ---------------------------------------------------------------------------- | |
105 | ||
106 | wxBasicString::wxBasicString(const wxString& str) | |
107 | { | |
108 | m_bstrBuf = SysAllocString(str.wc_str(*wxConvCurrent)); | |
109 | } | |
110 | ||
111 | wxBasicString::wxBasicString(const wxBasicString& src) | |
112 | { | |
113 | m_bstrBuf = src.Get(); | |
114 | } | |
115 | ||
116 | wxBasicString& wxBasicString::operator=(const wxBasicString& src) | |
117 | { | |
118 | SysReAllocString(&m_bstrBuf, src); | |
119 | return *this; | |
120 | } | |
121 | ||
122 | wxBasicString::~wxBasicString() | |
123 | { | |
124 | SysFreeString(m_bstrBuf); | |
125 | } | |
126 | ||
127 | #if wxUSE_DATAOBJ | |
128 | ||
129 | // ---------------------------------------------------------------------------- | |
130 | // Debug support | |
131 | // ---------------------------------------------------------------------------- | |
132 | ||
133 | #if wxDEBUG_LEVEL && ( ( defined(__VISUALC__) && (__VISUALC__ > 1000) ) || defined(__MWERKS__) ) | |
134 | static wxString GetIidName(REFIID riid) | |
135 | { | |
136 | // an association between symbolic name and numeric value of an IID | |
137 | struct KNOWN_IID { | |
138 | const IID *pIid; | |
139 | const wxChar *szName; | |
140 | }; | |
141 | ||
142 | // construct the table containing all known interfaces | |
143 | #define ADD_KNOWN_IID(name) { &IID_I##name, wxT(#name) } | |
144 | ||
145 | static const KNOWN_IID aKnownIids[] = { | |
146 | ADD_KNOWN_IID(AdviseSink), | |
147 | ADD_KNOWN_IID(AdviseSink2), | |
148 | ADD_KNOWN_IID(BindCtx), | |
149 | ADD_KNOWN_IID(ClassFactory), | |
150 | #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__) | |
151 | ADD_KNOWN_IID(ContinueCallback), | |
152 | ADD_KNOWN_IID(EnumOleDocumentViews), | |
153 | ADD_KNOWN_IID(OleCommandTarget), | |
154 | ADD_KNOWN_IID(OleDocument), | |
155 | ADD_KNOWN_IID(OleDocumentSite), | |
156 | ADD_KNOWN_IID(OleDocumentView), | |
157 | ADD_KNOWN_IID(Print), | |
158 | #endif | |
159 | ADD_KNOWN_IID(DataAdviseHolder), | |
160 | ADD_KNOWN_IID(DataObject), | |
161 | ADD_KNOWN_IID(Debug), | |
162 | ADD_KNOWN_IID(DebugStream), | |
163 | ADD_KNOWN_IID(DfReserved1), | |
164 | ADD_KNOWN_IID(DfReserved2), | |
165 | ADD_KNOWN_IID(DfReserved3), | |
166 | ADD_KNOWN_IID(Dispatch), | |
167 | ADD_KNOWN_IID(DropSource), | |
168 | ADD_KNOWN_IID(DropTarget), | |
169 | ADD_KNOWN_IID(EnumCallback), | |
170 | ADD_KNOWN_IID(EnumFORMATETC), | |
171 | ADD_KNOWN_IID(EnumGeneric), | |
172 | ADD_KNOWN_IID(EnumHolder), | |
173 | ADD_KNOWN_IID(EnumMoniker), | |
174 | ADD_KNOWN_IID(EnumOLEVERB), | |
175 | ADD_KNOWN_IID(EnumSTATDATA), | |
176 | ADD_KNOWN_IID(EnumSTATSTG), | |
177 | ADD_KNOWN_IID(EnumString), | |
178 | ADD_KNOWN_IID(EnumUnknown), | |
179 | ADD_KNOWN_IID(EnumVARIANT), | |
180 | ADD_KNOWN_IID(ExternalConnection), | |
181 | ADD_KNOWN_IID(InternalMoniker), | |
182 | ADD_KNOWN_IID(LockBytes), | |
183 | ADD_KNOWN_IID(Malloc), | |
184 | ADD_KNOWN_IID(Marshal), | |
185 | ADD_KNOWN_IID(MessageFilter), | |
186 | ADD_KNOWN_IID(Moniker), | |
187 | ADD_KNOWN_IID(OleAdviseHolder), | |
188 | ADD_KNOWN_IID(OleCache), | |
189 | ADD_KNOWN_IID(OleCache2), | |
190 | ADD_KNOWN_IID(OleCacheControl), | |
191 | ADD_KNOWN_IID(OleClientSite), | |
192 | ADD_KNOWN_IID(OleContainer), | |
193 | ADD_KNOWN_IID(OleInPlaceActiveObject), | |
194 | ADD_KNOWN_IID(OleInPlaceFrame), | |
195 | ADD_KNOWN_IID(OleInPlaceObject), | |
196 | ADD_KNOWN_IID(OleInPlaceSite), | |
197 | ADD_KNOWN_IID(OleInPlaceUIWindow), | |
198 | ADD_KNOWN_IID(OleItemContainer), | |
199 | ADD_KNOWN_IID(OleLink), | |
200 | ADD_KNOWN_IID(OleManager), | |
201 | ADD_KNOWN_IID(OleObject), | |
202 | ADD_KNOWN_IID(OlePresObj), | |
203 | ADD_KNOWN_IID(OleWindow), | |
204 | ADD_KNOWN_IID(PSFactory), | |
205 | ADD_KNOWN_IID(ParseDisplayName), | |
206 | ADD_KNOWN_IID(Persist), | |
207 | ADD_KNOWN_IID(PersistFile), | |
208 | ADD_KNOWN_IID(PersistStorage), | |
209 | ADD_KNOWN_IID(PersistStream), | |
210 | ADD_KNOWN_IID(ProxyManager), | |
211 | ADD_KNOWN_IID(RootStorage), | |
212 | ADD_KNOWN_IID(RpcChannel), | |
213 | ADD_KNOWN_IID(RpcProxy), | |
214 | ADD_KNOWN_IID(RpcStub), | |
215 | ADD_KNOWN_IID(RunnableObject), | |
216 | ADD_KNOWN_IID(RunningObjectTable), | |
217 | ADD_KNOWN_IID(StdMarshalInfo), | |
218 | ADD_KNOWN_IID(Storage), | |
219 | ADD_KNOWN_IID(Stream), | |
220 | ADD_KNOWN_IID(StubManager), | |
221 | ADD_KNOWN_IID(Unknown), | |
222 | ADD_KNOWN_IID(ViewObject), | |
223 | ADD_KNOWN_IID(ViewObject2), | |
224 | }; | |
225 | ||
226 | // don't clobber preprocessor name space | |
227 | #undef ADD_KNOWN_IID | |
228 | ||
229 | // try to find the interface in the table | |
230 | for ( size_t ui = 0; ui < WXSIZEOF(aKnownIids); ui++ ) { | |
231 | if ( riid == *aKnownIids[ui].pIid ) { | |
232 | return aKnownIids[ui].szName; | |
233 | } | |
234 | } | |
235 | ||
236 | #ifndef __WXWINCE__ | |
237 | // unknown IID, just transform to string | |
238 | Uuid uuid(riid); | |
239 | return wxString((const wxChar *)uuid); | |
240 | #else | |
241 | return wxEmptyString; | |
242 | #endif | |
243 | } | |
244 | ||
245 | void wxLogQueryInterface(const wxChar *szInterface, REFIID riid) | |
246 | { | |
247 | wxLogTrace(wxTRACE_OleCalls, wxT("%s::QueryInterface (iid = %s)"), | |
248 | szInterface, GetIidName(riid).c_str()); | |
249 | } | |
250 | ||
251 | void wxLogAddRef(const wxChar *szInterface, ULONG cRef) | |
252 | { | |
253 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::AddRef: m_cRef = %d"), szInterface, cRef + 1); | |
254 | } | |
255 | ||
256 | void wxLogRelease(const wxChar *szInterface, ULONG cRef) | |
257 | { | |
258 | wxLogTrace(wxTRACE_OleCalls, wxT("After %s::Release: m_cRef = %d"), szInterface, cRef - 1); | |
259 | } | |
260 | ||
261 | #endif // wxDEBUG_LEVEL | |
262 | ||
263 | #endif // wxUSE_DRAG_AND_DROP | |
264 | ||
265 | #endif // __CYGWIN10__ | |
266 | ||
267 | #endif // wxUSE_OLE |