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
32 #include "wine/windef16.h"
33 #include "wine/winbase16.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
41 #define E_OUTOFMEMORY16 MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 2)
42 #define E_INVALIDARG16 MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 3)
44 /* 16-bit SAFEARRAY implementation */
45 typedef struct tagSAFEARRAYBOUND16
51 typedef struct tagSAFEARRAY16
59 SAFEARRAYBOUND16 rgsabound
[1];
62 static SEGPTR
safearray_alloc(ULONG size
)
65 return WOWGlobalAllocLock16(GPTR
, size
, &h
);
68 static void safearray_free(SEGPTR ptr
)
70 WOWGlobalUnlockFree16(ptr
);
73 static ULONG
safearray_getcellcount(const SAFEARRAY16
*sa
)
75 const SAFEARRAYBOUND16
*sab
= sa
->rgsabound
;
76 USHORT count
= sa
->cDims
;
83 cells
*= sab
->cElements
;
90 static HRESULT
safearray_lock(SAFEARRAY16
*sa
)
92 if (sa
->cLocks
== 0xffff)
99 /******************************************************************************
100 * SafeArrayGetDim [OLE2DISP.17]
102 USHORT WINAPI
SafeArrayGetDim16(SAFEARRAY16
*sa
)
108 /******************************************************************************
109 * SafeArrayGetElemsize [OLE2DISP.18]
111 USHORT WINAPI
SafeArrayGetElemsize16(SAFEARRAY16
*sa
)
114 return sa
->cbElements
;
117 /******************************************************************************
118 * SafeArrayGetUBound [OLE2DISP.19]
120 HRESULT WINAPI
SafeArrayGetUBound16(SAFEARRAY16
*sa
, UINT16 dim
, LONG
*ubound
)
122 TRACE("(%p, %u, %p)\n", sa
, dim
, ubound
);
125 return E_INVALIDARG16
;
127 if (!dim
|| dim
> sa
->cDims
)
128 return DISP_E_BADINDEX
;
130 *ubound
= sa
->rgsabound
[sa
->cDims
- dim
].lLbound
+ sa
->rgsabound
[sa
->cDims
- dim
].cElements
- 1;
135 /******************************************************************************
136 * SafeArrayGetLBound [OLE2DISP.20]
138 HRESULT WINAPI
SafeArrayGetLBound16(SAFEARRAY16
*sa
, UINT16 dim
, LONG
*lbound
)
140 TRACE("(%p, %u, %p)\n", sa
, dim
, lbound
);
143 return E_INVALIDARG16
;
145 if (!dim
|| dim
> sa
->cDims
)
146 return DISP_E_BADINDEX
;
148 *lbound
= sa
->rgsabound
[sa
->cDims
- dim
].lLbound
;
153 /******************************************************************************
154 * SafeArrayLock [OLE2DISP.21]
156 HRESULT WINAPI
SafeArrayLock16(SAFEARRAY16
*sa
)
161 return E_INVALIDARG16
;
163 return safearray_lock(sa
);
166 /******************************************************************************
167 * SafeArrayUnlock [OLE2DISP.22]
169 HRESULT WINAPI
SafeArrayUnlock16(SAFEARRAY16
*sa
)
174 return E_INVALIDARG16
;
183 /******************************************************************************
184 * SafeArrayAccessData [OLE2DISP.23]
186 HRESULT WINAPI
SafeArrayAccessData16(SAFEARRAY16
*sa
, SEGPTR
*data
)
190 TRACE("(%p, %p)\n", sa
, data
);
192 /* arguments are not tested, it crashes if any of them is NULL */
194 hr
= safearray_lock(sa
);
202 /******************************************************************************
203 * SafeArrayUnaccessData [OLE2DISP.24]
205 HRESULT WINAPI
SafeArrayUnaccessData16(SAFEARRAY16
*sa
)
208 return SafeArrayUnlock16(sa
);
211 /******************************************************************************
212 * SafeArrayAllocDescriptor [OLE2DISP.38]
214 HRESULT WINAPI
SafeArrayAllocDescriptor16(UINT16 dims
, SEGPTR
*ret
)
219 TRACE("%u, %p\n", dims
, ret
);
222 return E_INVALIDARG16
;
224 size
= sizeof(SAFEARRAY16
) + sizeof(SAFEARRAYBOUND16
) * (dims
- 1);
225 *ret
= safearray_alloc(size
);
227 return E_OUTOFMEMORY16
;
234 /******************************************************************************
235 * SafeArrayAllocData [OLE2DISP.39]
237 HRESULT WINAPI
SafeArrayAllocData16(SAFEARRAY16
*sa
)
244 return E_INVALIDARG16
;
246 size
= safearray_getcellcount(sa
);
247 sa
->pvData
= safearray_alloc(size
* sa
->cbElements
);
248 return sa
->pvData
? S_OK
: E_OUTOFMEMORY16
;
251 /******************************************************************************
252 * SafeArrayDestroyDescriptor [OLE2DISP.40]
254 HRESULT WINAPI
SafeArrayDestroyDescriptor16(SEGPTR s
)
256 TRACE("0x%08lx\n", s
);
260 SAFEARRAY16
*sa
= MapSL(s
);
263 return DISP_E_ARRAYISLOCKED
;
271 /******************************************************************************
272 * SafeArrayDestroyData [OLE2DISP.41]
274 HRESULT WINAPI
SafeArrayDestroyData16(SAFEARRAY16
*sa
)
282 return DISP_E_ARRAYISLOCKED
;
284 if (!(sa
->fFeatures
& FADF_STATIC
))
285 safearray_free(sa
->pvData
);
290 /* This implementation of the BSTR API is 16-bit only. It
291 represents BSTR as a 16:16 far pointer, and the strings
294 /******************************************************************************
295 * BSTR_AllocBytes [Internal]
297 static BSTR16
BSTR_AllocBytes(int n
)
299 void *ptr
= HeapAlloc( GetProcessHeap(), 0, n
);
300 return (BSTR16
)MapLS(ptr
);
303 /******************************************************************************
304 * BSTR_Free [INTERNAL]
306 static void BSTR_Free(BSTR16 in
)
308 void *ptr
= MapSL( (SEGPTR
)in
);
309 UnMapLS( (SEGPTR
)in
);
310 HeapFree( GetProcessHeap(), 0, ptr
);
313 /******************************************************************************
314 * BSTR_GetAddr [INTERNAL]
316 static void* BSTR_GetAddr(BSTR16 in
)
318 return in
? MapSL((SEGPTR
)in
) : 0;
321 /******************************************************************************
322 * SysAllocString [OLE2DISP.2]
324 * Create a BSTR16 from an OLESTR16 (16 Bit).
327 * oleStr [I] Source to create BSTR16 from
330 * Success: A BSTR16 allocated with SysAllocStringLen16().
331 * Failure: NULL, if oleStr is NULL.
333 BSTR16 WINAPI
SysAllocString16(LPCOLESTR16 oleStr
)
337 if (!oleStr
) return 0;
339 out
= BSTR_AllocBytes(strlen(oleStr
)+1);
341 strcpy(BSTR_GetAddr(out
),oleStr
);
345 /******************************************************************************
346 * SysReallocString [OLE2DISP.3]
348 * Change the length of a previously created BSTR16 (16 Bit).
351 * pbstr [I] BSTR16 to change the length of
352 * oleStr [I] New source for pbstr
359 * SysAllocStringStringLen16().
361 INT16 WINAPI
SysReAllocString16(LPBSTR16 pbstr
,LPCOLESTR16 oleStr
)
363 BSTR16
new=SysAllocString16(oleStr
);
369 /******************************************************************************
370 * SysAllocStringLen [OLE2DISP.4]
372 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
375 * oleStr [I] Source to create BSTR16 from
376 * len [I] Length of oleStr in wide characters
379 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
380 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
383 * See SysAllocStringByteLen16().
385 BSTR16 WINAPI
SysAllocStringLen16(const char *oleStr
, int len
)
387 BSTR16 out
=BSTR_AllocBytes(len
+1);
393 * Copy the information in the buffer.
394 * Since it is valid to pass a NULL pointer here, we'll initialize the
395 * buffer to nul if it is the case.
398 strcpy(BSTR_GetAddr(out
),oleStr
);
400 memset(BSTR_GetAddr(out
), 0, len
+1);
405 /******************************************************************************
406 * SysReAllocStringLen [OLE2DISP.5]
408 * Change the length of a previously created BSTR16 (16 Bit).
411 * pbstr [I] BSTR16 to change the length of
412 * oleStr [I] New source for pbstr
413 * len [I] Length of oleStr in characters
416 * Success: 1. The size of pbstr is updated.
417 * Failure: 0, if len >= 0x8000 or memory allocation fails.
420 * See SysAllocStringByteLen16().
421 * *pbstr may be changed by this function.
423 int WINAPI
SysReAllocStringLen16(BSTR16
*old
,const char *in
,int len
)
425 /* FIXME: Check input length */
426 BSTR16
new=SysAllocStringLen16(in
,len
);
432 /******************************************************************************
433 * SysFreeString [OLE2DISP.6]
435 * Free a BSTR16 (16 Bit).
438 * str [I] String to free.
443 void WINAPI
SysFreeString16(BSTR16 str
)
448 /******************************************************************************
449 * SysStringLen [OLE2DISP.7]
451 * Get the allocated length of a BSTR16 in characters (16 Bit).
454 * str [I] BSTR16 to find the length of
457 * The allocated length of str, or 0 if str is NULL.
459 int WINAPI
SysStringLen16(BSTR16 str
)
461 return strlen(BSTR_GetAddr(str
));
464 /******************************************************************************
465 * VariantChangeType [OLE2DISP.12]
467 HRESULT WINAPI
VariantChangeType16(VARIANTARG
*vargDest
, VARIANTARG
*varSrc
, unsigned short flags
, VARTYPE vt
)
469 FIXME("stub: (%p, %p, %d, %d)\n", vargDest
, varSrc
, flags
, vt
);
474 /******************************************************************************
475 * CreateDispTypeInfo [OLE2DISP.31]
477 HRESULT WINAPI
CreateDispTypeInfo16(
478 INTERFACEDATA
*pidata
,
482 FIXME("(%p,%ld,%p),stub\n",pidata
,lcid
,pptinfo
);
486 /******************************************************************************
487 * CreateStdDispatch [OLE2DISP.32]
489 HRESULT WINAPI
CreateStdDispatch16(
493 IUnknown
** ppunkStdDisp
)
495 FIXME("(%p,%p,%p,%p),stub\n",punkOuter
, pvThis
, ptinfo
,
500 /******************************************************************************
501 * RegisterActiveObject [OLE2DISP.35]
503 HRESULT WINAPI
RegisterActiveObject16(
504 IUnknown
*punk
, REFCLSID rclsid
, DWORD dwFlags
, unsigned long *pdwRegister
506 FIXME("(%p,%s,0x%08lx,%p):stub\n",punk
,debugstr_guid(rclsid
),dwFlags
,pdwRegister
);
510 /******************************************************************************
511 * VariantChangeTypeEx [OLE2DISP.108]
513 HRESULT WINAPI
VariantChangeTypeEx16(VARIANTARG
*dest
, const VARIANTARG
*src
, LCID lcid
, USHORT flags
, VARTYPE vt
)
515 FIXME("stub: %p %p %ld %d %d\n", dest
, src
, lcid
, flags
, vt
);
519 /******************************************************************************
520 * SetErrorInfo [OLE2DISP.110]
522 HRESULT WINAPI
SetErrorInfo16(ULONG dwReserved
, IErrorInfo
*perrinfo
)
524 FIXME("stub: (%ld, %p)\n", dwReserved
, perrinfo
);
528 /******************************************************************************
529 * VariantInit [OLE2DISP.8]
531 void WINAPI
VariantInit16(VARIANTARG16
*v
)