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