wined3d: Implement multisample resolve for typed resources.
[wine.git] / dlls / ole2disp.dll16 / ole2disp.c
blobb98148550f06b35bfb4d822cb7a0af37bcc44683
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 * SafeArrayGetUBound [OLE2DISP.19]
122 HRESULT WINAPI SafeArrayGetUBound16(SAFEARRAY16 *sa, UINT16 dim, LONG *ubound)
124 TRACE("(%p, %u, %p)\n", sa, dim, ubound);
126 if (!sa)
127 return E_INVALIDARG16;
129 if (!dim || dim > sa->cDims)
130 return DISP_E_BADINDEX;
132 *ubound = sa->rgsabound[sa->cDims - dim].lLbound + sa->rgsabound[sa->cDims - dim].cElements - 1;
134 return S_OK;
137 /******************************************************************************
138 * SafeArrayGetLBound [OLE2DISP.20]
140 HRESULT WINAPI SafeArrayGetLBound16(SAFEARRAY16 *sa, UINT16 dim, LONG *lbound)
142 TRACE("(%p, %u, %p)\n", sa, dim, lbound);
144 if (!sa)
145 return E_INVALIDARG16;
147 if (!dim || dim > sa->cDims)
148 return DISP_E_BADINDEX;
150 *lbound = sa->rgsabound[sa->cDims - dim].lLbound;
152 return S_OK;
155 /******************************************************************************
156 * SafeArrayLock [OLE2DISP.21]
158 HRESULT WINAPI SafeArrayLock16(SAFEARRAY16 *sa)
160 TRACE("(%p)\n", sa);
162 if (!sa)
163 return E_INVALIDARG16;
165 return safearray_lock(sa);
168 /******************************************************************************
169 * SafeArrayUnlock [OLE2DISP.22]
171 HRESULT WINAPI SafeArrayUnlock16(SAFEARRAY16 *sa)
173 TRACE("(%p)\n", sa);
175 if (!sa)
176 return E_INVALIDARG16;
178 if (sa->cLocks == 0)
179 return E_UNEXPECTED;
181 sa->cLocks--;
182 return S_OK;
185 /******************************************************************************
186 * SafeArrayAccessData [OLE2DISP.23]
188 HRESULT WINAPI SafeArrayAccessData16(SAFEARRAY16 *sa, SEGPTR *data)
190 HRESULT hr;
192 TRACE("(%p, %p)\n", sa, data);
194 /* arguments are not tested, it crashes if any of them is NULL */
196 hr = safearray_lock(sa);
197 if (FAILED(hr))
198 return hr;
200 *data = sa->pvData;
201 return S_OK;
204 /******************************************************************************
205 * SafeArrayUnaccessData [OLE2DISP.24]
207 HRESULT WINAPI SafeArrayUnaccessData16(SAFEARRAY16 *sa)
209 TRACE("(%p)\n", sa);
210 return SafeArrayUnlock16(sa);
213 /******************************************************************************
214 * SafeArrayAllocDescriptor [OLE2DISP.38]
216 HRESULT WINAPI SafeArrayAllocDescriptor16(UINT16 dims, SEGPTR *ret)
218 SAFEARRAY16 *sa;
219 ULONG size;
221 TRACE("%u, %p\n", dims, ret);
223 if (!dims)
224 return E_INVALIDARG16;
226 size = sizeof(SAFEARRAY16) + sizeof(SAFEARRAYBOUND16) * (dims - 1);
227 *ret = safearray_alloc(size);
228 if (!*ret)
229 return E_OUTOFMEMORY16;
231 sa = MapSL(*ret);
232 sa->cDims = dims;
233 return S_OK;
236 /******************************************************************************
237 * SafeArrayAllocData [OLE2DISP.39]
239 HRESULT WINAPI SafeArrayAllocData16(SAFEARRAY16 *sa)
241 ULONG size;
243 TRACE("%p\n", sa);
245 if (!sa)
246 return E_INVALIDARG16;
248 size = safearray_getcellcount(sa);
249 sa->pvData = safearray_alloc(size * sa->cbElements);
250 return sa->pvData ? S_OK : E_OUTOFMEMORY16;
253 /******************************************************************************
254 * SafeArrayDestroyDescriptor [OLE2DISP.40]
256 HRESULT WINAPI SafeArrayDestroyDescriptor16(SEGPTR s)
258 TRACE("0x%08x\n", s);
260 if (s)
262 SAFEARRAY16 *sa = MapSL(s);
264 if (sa->cLocks)
265 return DISP_E_ARRAYISLOCKED;
267 safearray_free(s);
270 return S_OK;
273 /******************************************************************************
274 * SafeArrayDestroyData [OLE2DISP.41]
276 HRESULT WINAPI SafeArrayDestroyData16(SAFEARRAY16 *sa)
278 TRACE("%p\n", sa);
280 if (!sa)
281 return S_OK;
283 if (sa->cLocks)
284 return DISP_E_ARRAYISLOCKED;
286 if (!(sa->fFeatures & FADF_STATIC))
287 safearray_free(sa->pvData);
289 return S_OK;
292 /* This implementation of the BSTR API is 16-bit only. It
293 represents BSTR as a 16:16 far pointer, and the strings
294 as ISO-8859 */
296 /******************************************************************************
297 * BSTR_AllocBytes [Internal]
299 static BSTR16 BSTR_AllocBytes(int n)
301 void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
302 return (BSTR16)MapLS(ptr);
305 /******************************************************************************
306 * BSTR_Free [INTERNAL]
308 static void BSTR_Free(BSTR16 in)
310 void *ptr = MapSL( (SEGPTR)in );
311 UnMapLS( (SEGPTR)in );
312 HeapFree( GetProcessHeap(), 0, ptr );
315 /******************************************************************************
316 * BSTR_GetAddr [INTERNAL]
318 static void* BSTR_GetAddr(BSTR16 in)
320 return in ? MapSL((SEGPTR)in) : 0;
323 /******************************************************************************
324 * SysAllocString [OLE2DISP.2]
326 * Create a BSTR16 from an OLESTR16 (16 Bit).
328 * PARAMS
329 * oleStr [I] Source to create BSTR16 from
331 * RETURNS
332 * Success: A BSTR16 allocated with SysAllocStringLen16().
333 * Failure: NULL, if oleStr is NULL.
335 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
337 BSTR16 out;
339 if (!oleStr) return 0;
341 out = BSTR_AllocBytes(strlen(oleStr)+1);
342 if (!out) return 0;
343 strcpy(BSTR_GetAddr(out),oleStr);
344 return out;
347 /******************************************************************************
348 * SysReallocString [OLE2DISP.3]
350 * Change the length of a previously created BSTR16 (16 Bit).
352 * PARAMS
353 * pbstr [I] BSTR16 to change the length of
354 * oleStr [I] New source for pbstr
356 * RETURNS
357 * Success: 1
358 * Failure: 0.
360 * NOTES
361 * SysAllocStringStringLen16().
363 INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
365 BSTR16 new=SysAllocString16(oleStr);
366 BSTR_Free(*pbstr);
367 *pbstr=new;
368 return 1;
371 /******************************************************************************
372 * SysAllocStringLen [OLE2DISP.4]
374 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
376 * PARAMS
377 * oleStr [I] Source to create BSTR16 from
378 * len [I] Length of oleStr in wide characters
380 * RETURNS
381 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
382 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
384 * NOTES
385 * See SysAllocStringByteLen16().
387 BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
389 BSTR16 out=BSTR_AllocBytes(len+1);
391 if (!out)
392 return 0;
395 * Copy the information in the buffer.
396 * Since it is valid to pass a NULL pointer here, we'll initialize the
397 * buffer to nul if it is the case.
399 if (oleStr != 0)
400 strcpy(BSTR_GetAddr(out),oleStr);
401 else
402 memset(BSTR_GetAddr(out), 0, len+1);
404 return out;
407 /******************************************************************************
408 * SysReAllocStringLen [OLE2DISP.5]
410 * Change the length of a previously created BSTR16 (16 Bit).
412 * PARAMS
413 * pbstr [I] BSTR16 to change the length of
414 * oleStr [I] New source for pbstr
415 * len [I] Length of oleStr in characters
417 * RETURNS
418 * Success: 1. The size of pbstr is updated.
419 * Failure: 0, if len >= 0x8000 or memory allocation fails.
421 * NOTES
422 * See SysAllocStringByteLen16().
423 * *pbstr may be changed by this function.
425 int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
427 /* FIXME: Check input length */
428 BSTR16 new=SysAllocStringLen16(in,len);
429 BSTR_Free(*old);
430 *old=new;
431 return 1;
434 /******************************************************************************
435 * SysFreeString [OLE2DISP.6]
437 * Free a BSTR16 (16 Bit).
439 * PARAMS
440 * str [I] String to free.
442 * RETURNS
443 * Nothing.
445 void WINAPI SysFreeString16(BSTR16 str)
447 BSTR_Free(str);
450 /******************************************************************************
451 * SysStringLen [OLE2DISP.7]
453 * Get the allocated length of a BSTR16 in characters (16 Bit).
455 * PARAMS
456 * str [I] BSTR16 to find the length of
458 * RETURNS
459 * The allocated length of str, or 0 if str is NULL.
461 int WINAPI SysStringLen16(BSTR16 str)
463 return strlen(BSTR_GetAddr(str));
466 /******************************************************************************
467 * VariantChangeType [OLE2DISP.12]
469 HRESULT WINAPI VariantChangeType16(VARIANTARG *vargDest, VARIANTARG *varSrc, unsigned short flags, VARTYPE vt)
471 FIXME("stub: (%p, %p, %d, %d)\n", vargDest, varSrc, flags, vt);
472 return E_NOTIMPL;
476 /******************************************************************************
477 * CreateDispTypeInfo [OLE2DISP.31]
479 HRESULT WINAPI CreateDispTypeInfo16(
480 INTERFACEDATA *pidata,
481 LCID lcid,
482 ITypeInfo **pptinfo)
484 FIXME("(%p,%d,%p),stub\n",pidata,lcid,pptinfo);
485 return E_NOTIMPL;
488 /******************************************************************************
489 * CreateStdDispatch [OLE2DISP.32]
491 HRESULT WINAPI CreateStdDispatch16(
492 IUnknown* punkOuter,
493 void* pvThis,
494 ITypeInfo* ptinfo,
495 IUnknown** ppunkStdDisp)
497 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
498 ppunkStdDisp);
499 return 0;
502 /******************************************************************************
503 * RegisterActiveObject [OLE2DISP.35]
505 HRESULT WINAPI RegisterActiveObject16(
506 IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
508 FIXME("(%p,%s,0x%08x,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
509 return E_NOTIMPL;
512 /******************************************************************************
513 * VariantChangeTypeEx [OLE2DISP.108]
515 HRESULT WINAPI VariantChangeTypeEx16(VARIANTARG *dest, const VARIANTARG *src, LCID lcid, USHORT flags, VARTYPE vt)
517 FIXME("stub: %p %p %d %d %d\n", dest, src, lcid, flags, vt);
518 return E_INVALIDARG;
521 /******************************************************************************
522 * SetErrorInfo [OLE2DISP.110]
524 HRESULT WINAPI SetErrorInfo16(ULONG dwReserved, IErrorInfo *perrinfo)
526 FIXME("stub: (%d, %p)\n", dwReserved, perrinfo);
527 return E_INVALIDARG;
530 /******************************************************************************
531 * VariantInit [OLE2DISP.8]
533 void WINAPI VariantInit16(VARIANTARG16 *v)
535 TRACE("(%p)\n", v);
536 v->vt = VT_EMPTY;