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
34 #include "wine/windef16.h"
35 #include "wine/winbase16.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
53 typedef struct tagSAFEARRAY16
61 SAFEARRAYBOUND16 rgsabound
[1];
64 static SEGPTR
safearray_alloc(ULONG size
)
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
;
85 cells
*= sab
->cElements
;
92 static HRESULT
safearray_lock(SAFEARRAY16
*sa
)
94 if (sa
->cLocks
== 0xffff)
101 /******************************************************************************
102 * SafeArrayGetDim [OLE2DISP.17]
104 USHORT WINAPI
SafeArrayGetDim16(SAFEARRAY16
*sa
)
110 /******************************************************************************
111 * SafeArrayGetElemsize [OLE2DISP.18]
113 USHORT WINAPI
SafeArrayGetElemsize16(SAFEARRAY16
*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
);
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;
137 /******************************************************************************
138 * SafeArrayGetLBound [OLE2DISP.20]
140 HRESULT WINAPI
SafeArrayGetLBound16(SAFEARRAY16
*sa
, UINT16 dim
, LONG
*lbound
)
142 TRACE("(%p, %u, %p)\n", sa
, dim
, lbound
);
145 return E_INVALIDARG16
;
147 if (!dim
|| dim
> sa
->cDims
)
148 return DISP_E_BADINDEX
;
150 *lbound
= sa
->rgsabound
[sa
->cDims
- dim
].lLbound
;
155 /******************************************************************************
156 * SafeArrayLock [OLE2DISP.21]
158 HRESULT WINAPI
SafeArrayLock16(SAFEARRAY16
*sa
)
163 return E_INVALIDARG16
;
165 return safearray_lock(sa
);
168 /******************************************************************************
169 * SafeArrayUnlock [OLE2DISP.22]
171 HRESULT WINAPI
SafeArrayUnlock16(SAFEARRAY16
*sa
)
176 return E_INVALIDARG16
;
185 /******************************************************************************
186 * SafeArrayAccessData [OLE2DISP.23]
188 HRESULT WINAPI
SafeArrayAccessData16(SAFEARRAY16
*sa
, SEGPTR
*data
)
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
);
204 /******************************************************************************
205 * SafeArrayUnaccessData [OLE2DISP.24]
207 HRESULT WINAPI
SafeArrayUnaccessData16(SAFEARRAY16
*sa
)
210 return SafeArrayUnlock16(sa
);
213 /******************************************************************************
214 * SafeArrayAllocDescriptor [OLE2DISP.38]
216 HRESULT WINAPI
SafeArrayAllocDescriptor16(UINT16 dims
, SEGPTR
*ret
)
221 TRACE("%u, %p\n", dims
, ret
);
224 return E_INVALIDARG16
;
226 size
= sizeof(SAFEARRAY16
) + sizeof(SAFEARRAYBOUND16
) * (dims
- 1);
227 *ret
= safearray_alloc(size
);
229 return E_OUTOFMEMORY16
;
236 /******************************************************************************
237 * SafeArrayAllocData [OLE2DISP.39]
239 HRESULT WINAPI
SafeArrayAllocData16(SAFEARRAY16
*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
);
262 SAFEARRAY16
*sa
= MapSL(s
);
265 return DISP_E_ARRAYISLOCKED
;
273 /******************************************************************************
274 * SafeArrayDestroyData [OLE2DISP.41]
276 HRESULT WINAPI
SafeArrayDestroyData16(SAFEARRAY16
*sa
)
284 return DISP_E_ARRAYISLOCKED
;
286 if (!(sa
->fFeatures
& FADF_STATIC
))
287 safearray_free(sa
->pvData
);
292 /* This implementation of the BSTR API is 16-bit only. It
293 represents BSTR as a 16:16 far pointer, and the strings
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).
329 * oleStr [I] Source to create BSTR16 from
332 * Success: A BSTR16 allocated with SysAllocStringLen16().
333 * Failure: NULL, if oleStr is NULL.
335 BSTR16 WINAPI
SysAllocString16(LPCOLESTR16 oleStr
)
339 if (!oleStr
) return 0;
341 out
= BSTR_AllocBytes(strlen(oleStr
)+1);
343 strcpy(BSTR_GetAddr(out
),oleStr
);
347 /******************************************************************************
348 * SysReallocString [OLE2DISP.3]
350 * Change the length of a previously created BSTR16 (16 Bit).
353 * pbstr [I] BSTR16 to change the length of
354 * oleStr [I] New source for pbstr
361 * SysAllocStringStringLen16().
363 INT16 WINAPI
SysReAllocString16(LPBSTR16 pbstr
,LPCOLESTR16 oleStr
)
365 BSTR16
new=SysAllocString16(oleStr
);
371 /******************************************************************************
372 * SysAllocStringLen [OLE2DISP.4]
374 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
377 * oleStr [I] Source to create BSTR16 from
378 * len [I] Length of oleStr in wide characters
381 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
382 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
385 * See SysAllocStringByteLen16().
387 BSTR16 WINAPI
SysAllocStringLen16(const char *oleStr
, int len
)
389 BSTR16 out
=BSTR_AllocBytes(len
+1);
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.
400 strcpy(BSTR_GetAddr(out
),oleStr
);
402 memset(BSTR_GetAddr(out
), 0, len
+1);
407 /******************************************************************************
408 * SysReAllocStringLen [OLE2DISP.5]
410 * Change the length of a previously created BSTR16 (16 Bit).
413 * pbstr [I] BSTR16 to change the length of
414 * oleStr [I] New source for pbstr
415 * len [I] Length of oleStr in characters
418 * Success: 1. The size of pbstr is updated.
419 * Failure: 0, if len >= 0x8000 or memory allocation fails.
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
);
434 /******************************************************************************
435 * SysFreeString [OLE2DISP.6]
437 * Free a BSTR16 (16 Bit).
440 * str [I] String to free.
445 void WINAPI
SysFreeString16(BSTR16 str
)
450 /******************************************************************************
451 * SysStringLen [OLE2DISP.7]
453 * Get the allocated length of a BSTR16 in characters (16 Bit).
456 * str [I] BSTR16 to find the length of
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
);
476 /******************************************************************************
477 * CreateDispTypeInfo [OLE2DISP.31]
479 HRESULT WINAPI
CreateDispTypeInfo16(
480 INTERFACEDATA
*pidata
,
484 FIXME("(%p,%d,%p),stub\n",pidata
,lcid
,pptinfo
);
488 /******************************************************************************
489 * CreateStdDispatch [OLE2DISP.32]
491 HRESULT WINAPI
CreateStdDispatch16(
495 IUnknown
** ppunkStdDisp
)
497 FIXME("(%p,%p,%p,%p),stub\n",punkOuter
, pvThis
, ptinfo
,
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
);
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
);
521 /******************************************************************************
522 * SetErrorInfo [OLE2DISP.110]
524 HRESULT WINAPI
SetErrorInfo16(ULONG dwReserved
, IErrorInfo
*perrinfo
)
526 FIXME("stub: (%d, %p)\n", dwReserved
, perrinfo
);
530 /******************************************************************************
531 * VariantInit [OLE2DISP.8]
533 void WINAPI
VariantInit16(VARIANTARG16
*v
)