msctf: Fix spelling of a private struct's field name.
[wine.git] / dlls / ole2disp.dll16 / ole2disp.c
blobd61b5e8c5a1178609dcf5bbe6d34b11da6ebc1b1
1 /*
2 * OLE2DISP library
4 * Copyright 1995 Martin von Loewis
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "oleauto.h"
32 #include "winerror.h"
33 #include "wownt32.h"
34 #include "wine/windef16.h"
35 #include "wine/winbase16.h"
37 #include "ole2disp.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(ole);
43 #define E_OUTOFMEMORY16 MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 2)
44 #define E_INVALIDARG16 MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 3)
46 /* 16-bit SAFEARRAY implementation */
47 typedef struct tagSAFEARRAYBOUND16
49 ULONG cElements;
50 LONG lLbound;
51 } SAFEARRAYBOUND16;
53 typedef struct tagSAFEARRAY16
55 USHORT cDims;
56 USHORT fFeatures;
57 USHORT cbElements;
58 USHORT cLocks;
59 ULONG handle;
60 SEGPTR pvData;
61 SAFEARRAYBOUND16 rgsabound[1];
62 } SAFEARRAY16;
64 static SEGPTR safearray_alloc(ULONG size)
66 HANDLE16 h;
67 return WOWGlobalAllocLock16(GPTR, size, &h);
70 static void safearray_free(SEGPTR ptr)
72 WOWGlobalUnlockFree16(ptr);
75 static ULONG safearray_getcellcount(const SAFEARRAY16 *sa)
77 const SAFEARRAYBOUND16 *sab = sa->rgsabound;
78 USHORT count = sa->cDims;
79 ULONG cells = 1;
81 while (count--)
83 if (!sab->cElements)
84 return 0;
85 cells *= sab->cElements;
86 sab++;
89 return cells;
92 static HRESULT safearray_lock(SAFEARRAY16 *sa)
94 if (sa->cLocks == 0xffff)
95 return E_UNEXPECTED;
97 sa->cLocks++;
98 return S_OK;
101 /******************************************************************************
102 * SafeArrayGetDim [OLE2DISP.17]
104 USHORT WINAPI SafeArrayGetDim16(SAFEARRAY16 *sa)
106 TRACE("(%p)\n", sa);
107 return sa->cDims;
110 /******************************************************************************
111 * SafeArrayGetElemsize [OLE2DISP.18]
113 USHORT WINAPI SafeArrayGetElemsize16(SAFEARRAY16 *sa)
115 TRACE("(%p)\n", sa);
116 return sa->cbElements;
119 /******************************************************************************
120 * SafeArrayLock [OLE2DISP.21]
122 HRESULT WINAPI SafeArrayLock16(SAFEARRAY16 *sa)
124 TRACE("(%p)\n", sa);
126 if (!sa)
127 return E_INVALIDARG16;
129 return safearray_lock(sa);
132 /******************************************************************************
133 * SafeArrayUnlock [OLE2DISP.22]
135 HRESULT WINAPI SafeArrayUnlock16(SAFEARRAY16 *sa)
137 TRACE("(%p)\n", sa);
139 if (!sa)
140 return E_INVALIDARG16;
142 if (sa->cLocks == 0)
143 return E_UNEXPECTED;
145 sa->cLocks--;
146 return S_OK;
149 /******************************************************************************
150 * SafeArrayAccessData [OLE2DISP.23]
152 HRESULT WINAPI SafeArrayAccessData16(SAFEARRAY16 *sa, SEGPTR *data)
154 HRESULT hr;
156 TRACE("(%p, %p)\n", sa, data);
158 /* arguments are not tested, it crashes if any of them is NULL */
160 hr = safearray_lock(sa);
161 if (FAILED(hr))
162 return hr;
164 *data = sa->pvData;
165 return S_OK;
168 /******************************************************************************
169 * SafeArrayUnaccessData [OLE2DISP.24]
171 HRESULT WINAPI SafeArrayUnaccessData16(SAFEARRAY16 *sa)
173 TRACE("(%p)\n", sa);
174 return SafeArrayUnlock16(sa);
177 /******************************************************************************
178 * SafeArrayAllocDescriptor [OLE2DISP.38]
180 HRESULT WINAPI SafeArrayAllocDescriptor16(UINT16 dims, SEGPTR *ret)
182 SAFEARRAY16 *sa;
183 ULONG size;
185 TRACE("%u, %p\n", dims, ret);
187 if (!dims)
188 return E_INVALIDARG16;
190 size = sizeof(SAFEARRAY16) + sizeof(SAFEARRAYBOUND16) * (dims - 1);
191 *ret = safearray_alloc(size);
192 if (!*ret)
193 return E_OUTOFMEMORY16;
195 sa = MapSL(*ret);
196 sa->cDims = dims;
197 return S_OK;
200 /******************************************************************************
201 * SafeArrayAllocData [OLE2DISP.39]
203 HRESULT WINAPI SafeArrayAllocData16(SAFEARRAY16 *sa)
205 ULONG size;
207 TRACE("%p\n", sa);
209 if (!sa)
210 return E_INVALIDARG16;
212 size = safearray_getcellcount(sa);
213 sa->pvData = safearray_alloc(size * sa->cbElements);
214 return sa->pvData ? S_OK : E_OUTOFMEMORY16;
217 /******************************************************************************
218 * SafeArrayDestroyDescriptor [OLE2DISP.40]
220 HRESULT WINAPI SafeArrayDestroyDescriptor16(SEGPTR s)
222 TRACE("0x%08x\n", s);
224 if (s)
226 SAFEARRAY16 *sa = MapSL(s);
228 if (sa->cLocks)
229 return DISP_E_ARRAYISLOCKED;
231 safearray_free(s);
234 return S_OK;
237 /* This implementation of the BSTR API is 16-bit only. It
238 represents BSTR as a 16:16 far pointer, and the strings
239 as ISO-8859 */
241 /******************************************************************************
242 * BSTR_AllocBytes [Internal]
244 static BSTR16 BSTR_AllocBytes(int n)
246 void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
247 return (BSTR16)MapLS(ptr);
250 /******************************************************************************
251 * BSTR_Free [INTERNAL]
253 static void BSTR_Free(BSTR16 in)
255 void *ptr = MapSL( (SEGPTR)in );
256 UnMapLS( (SEGPTR)in );
257 HeapFree( GetProcessHeap(), 0, ptr );
260 /******************************************************************************
261 * BSTR_GetAddr [INTERNAL]
263 static void* BSTR_GetAddr(BSTR16 in)
265 return in ? MapSL((SEGPTR)in) : 0;
268 /******************************************************************************
269 * SysAllocString [OLE2DISP.2]
271 * Create a BSTR16 from an OLESTR16 (16 Bit).
273 * PARAMS
274 * oleStr [I] Source to create BSTR16 from
276 * RETURNS
277 * Success: A BSTR16 allocated with SysAllocStringLen16().
278 * Failure: NULL, if oleStr is NULL.
280 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
282 BSTR16 out;
284 if (!oleStr) return 0;
286 out = BSTR_AllocBytes(strlen(oleStr)+1);
287 if (!out) return 0;
288 strcpy(BSTR_GetAddr(out),oleStr);
289 return out;
292 /******************************************************************************
293 * SysReallocString [OLE2DISP.3]
295 * Change the length of a previously created BSTR16 (16 Bit).
297 * PARAMS
298 * pbstr [I] BSTR16 to change the length of
299 * oleStr [I] New source for pbstr
301 * RETURNS
302 * Success: 1
303 * Failure: 0.
305 * NOTES
306 * SysAllocStringStringLen16().
308 INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
310 BSTR16 new=SysAllocString16(oleStr);
311 BSTR_Free(*pbstr);
312 *pbstr=new;
313 return 1;
316 /******************************************************************************
317 * SysAllocStringLen [OLE2DISP.4]
319 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
321 * PARAMS
322 * oleStr [I] Source to create BSTR16 from
323 * len [I] Length of oleStr in wide characters
325 * RETURNS
326 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
327 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
329 * NOTES
330 * See SysAllocStringByteLen16().
332 BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
334 BSTR16 out=BSTR_AllocBytes(len+1);
336 if (!out)
337 return 0;
340 * Copy the information in the buffer.
341 * Since it is valid to pass a NULL pointer here, we'll initialize the
342 * buffer to nul if it is the case.
344 if (oleStr != 0)
345 strcpy(BSTR_GetAddr(out),oleStr);
346 else
347 memset(BSTR_GetAddr(out), 0, len+1);
349 return out;
352 /******************************************************************************
353 * SysReAllocStringLen [OLE2DISP.5]
355 * Change the length of a previously created BSTR16 (16 Bit).
357 * PARAMS
358 * pbstr [I] BSTR16 to change the length of
359 * oleStr [I] New source for pbstr
360 * len [I] Length of oleStr in characters
362 * RETURNS
363 * Success: 1. The size of pbstr is updated.
364 * Failure: 0, if len >= 0x8000 or memory allocation fails.
366 * NOTES
367 * See SysAllocStringByteLen16().
368 * *pbstr may be changed by this function.
370 int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
372 /* FIXME: Check input length */
373 BSTR16 new=SysAllocStringLen16(in,len);
374 BSTR_Free(*old);
375 *old=new;
376 return 1;
379 /******************************************************************************
380 * SysFreeString [OLE2DISP.6]
382 * Free a BSTR16 (16 Bit).
384 * PARAMS
385 * str [I] String to free.
387 * RETURNS
388 * Nothing.
390 void WINAPI SysFreeString16(BSTR16 str)
392 BSTR_Free(str);
395 /******************************************************************************
396 * SysStringLen [OLE2DISP.7]
398 * Get the allocated length of a BSTR16 in characters (16 Bit).
400 * PARAMS
401 * str [I] BSTR16 to find the length of
403 * RETURNS
404 * The allocated length of str, or 0 if str is NULL.
406 int WINAPI SysStringLen16(BSTR16 str)
408 return strlen(BSTR_GetAddr(str));
411 /******************************************************************************
412 * VariantChangeType [OLE2DISP.12]
414 HRESULT WINAPI VariantChangeType16(VARIANTARG *vargDest, VARIANTARG *varSrc, unsigned short flags, VARTYPE vt)
416 FIXME("stub: (%p, %p, %d, %d)\n", vargDest, varSrc, flags, vt);
417 return E_NOTIMPL;
421 /******************************************************************************
422 * CreateDispTypeInfo [OLE2DISP.31]
424 HRESULT WINAPI CreateDispTypeInfo16(
425 INTERFACEDATA *pidata,
426 LCID lcid,
427 ITypeInfo **pptinfo)
429 FIXME("(%p,%d,%p),stub\n",pidata,lcid,pptinfo);
430 return E_NOTIMPL;
433 /******************************************************************************
434 * CreateStdDispatch [OLE2DISP.32]
436 HRESULT WINAPI CreateStdDispatch16(
437 IUnknown* punkOuter,
438 void* pvThis,
439 ITypeInfo* ptinfo,
440 IUnknown** ppunkStdDisp)
442 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
443 ppunkStdDisp);
444 return 0;
447 /******************************************************************************
448 * RegisterActiveObject [OLE2DISP.35]
450 HRESULT WINAPI RegisterActiveObject16(
451 IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
453 FIXME("(%p,%s,0x%08x,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
454 return E_NOTIMPL;
457 /******************************************************************************
458 * VariantChangeTypeEx [OLE2DISP.108]
460 HRESULT WINAPI VariantChangeTypeEx16(VARIANTARG *dest, const VARIANTARG *src, LCID lcid, USHORT flags, VARTYPE vt)
462 FIXME("stub: %p %p %d %d %d\n", dest, src, lcid, flags, vt);
463 return E_INVALIDARG;
466 /******************************************************************************
467 * SetErrorInfo [OLE2DISP.110]
469 HRESULT WINAPI SetErrorInfo16(ULONG dwReserved, IErrorInfo *perrinfo)
471 FIXME("stub: (%d, %p)\n", dwReserved, perrinfo);
472 return E_INVALIDARG;
475 /******************************************************************************
476 * VariantInit [OLE2DISP.8]
478 void WINAPI VariantInit16(VARIANTARG16 *v)
480 TRACE("(%p)\n", v);
481 v->vt = VT_EMPTY;