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 * SafeArrayLock [OLE2DISP.21]
122 HRESULT WINAPI
SafeArrayLock16(SAFEARRAY16
*sa
)
127 return E_INVALIDARG16
;
129 return safearray_lock(sa
);
132 /******************************************************************************
133 * SafeArrayUnlock [OLE2DISP.22]
135 HRESULT WINAPI
SafeArrayUnlock16(SAFEARRAY16
*sa
)
140 return E_INVALIDARG16
;
149 /******************************************************************************
150 * SafeArrayAccessData [OLE2DISP.23]
152 HRESULT WINAPI
SafeArrayAccessData16(SAFEARRAY16
*sa
, SEGPTR
*data
)
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
);
168 /******************************************************************************
169 * SafeArrayUnaccessData [OLE2DISP.24]
171 HRESULT WINAPI
SafeArrayUnaccessData16(SAFEARRAY16
*sa
)
174 return SafeArrayUnlock16(sa
);
177 /******************************************************************************
178 * SafeArrayAllocDescriptor [OLE2DISP.38]
180 HRESULT WINAPI
SafeArrayAllocDescriptor16(UINT16 dims
, SEGPTR
*ret
)
185 TRACE("%u, %p\n", dims
, ret
);
188 return E_INVALIDARG16
;
190 size
= sizeof(SAFEARRAY16
) + sizeof(SAFEARRAYBOUND16
) * (dims
- 1);
191 *ret
= safearray_alloc(size
);
193 return E_OUTOFMEMORY16
;
200 /******************************************************************************
201 * SafeArrayAllocData [OLE2DISP.39]
203 HRESULT WINAPI
SafeArrayAllocData16(SAFEARRAY16
*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
);
226 SAFEARRAY16
*sa
= MapSL(s
);
229 return DISP_E_ARRAYISLOCKED
;
237 /* This implementation of the BSTR API is 16-bit only. It
238 represents BSTR as a 16:16 far pointer, and the strings
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).
274 * oleStr [I] Source to create BSTR16 from
277 * Success: A BSTR16 allocated with SysAllocStringLen16().
278 * Failure: NULL, if oleStr is NULL.
280 BSTR16 WINAPI
SysAllocString16(LPCOLESTR16 oleStr
)
284 if (!oleStr
) return 0;
286 out
= BSTR_AllocBytes(strlen(oleStr
)+1);
288 strcpy(BSTR_GetAddr(out
),oleStr
);
292 /******************************************************************************
293 * SysReallocString [OLE2DISP.3]
295 * Change the length of a previously created BSTR16 (16 Bit).
298 * pbstr [I] BSTR16 to change the length of
299 * oleStr [I] New source for pbstr
306 * SysAllocStringStringLen16().
308 INT16 WINAPI
SysReAllocString16(LPBSTR16 pbstr
,LPCOLESTR16 oleStr
)
310 BSTR16
new=SysAllocString16(oleStr
);
316 /******************************************************************************
317 * SysAllocStringLen [OLE2DISP.4]
319 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
322 * oleStr [I] Source to create BSTR16 from
323 * len [I] Length of oleStr in wide characters
326 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
327 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
330 * See SysAllocStringByteLen16().
332 BSTR16 WINAPI
SysAllocStringLen16(const char *oleStr
, int len
)
334 BSTR16 out
=BSTR_AllocBytes(len
+1);
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.
345 strcpy(BSTR_GetAddr(out
),oleStr
);
347 memset(BSTR_GetAddr(out
), 0, len
+1);
352 /******************************************************************************
353 * SysReAllocStringLen [OLE2DISP.5]
355 * Change the length of a previously created BSTR16 (16 Bit).
358 * pbstr [I] BSTR16 to change the length of
359 * oleStr [I] New source for pbstr
360 * len [I] Length of oleStr in characters
363 * Success: 1. The size of pbstr is updated.
364 * Failure: 0, if len >= 0x8000 or memory allocation fails.
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
);
379 /******************************************************************************
380 * SysFreeString [OLE2DISP.6]
382 * Free a BSTR16 (16 Bit).
385 * str [I] String to free.
390 void WINAPI
SysFreeString16(BSTR16 str
)
395 /******************************************************************************
396 * SysStringLen [OLE2DISP.7]
398 * Get the allocated length of a BSTR16 in characters (16 Bit).
401 * str [I] BSTR16 to find the length of
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
);
421 /******************************************************************************
422 * CreateDispTypeInfo [OLE2DISP.31]
424 HRESULT WINAPI
CreateDispTypeInfo16(
425 INTERFACEDATA
*pidata
,
429 FIXME("(%p,%d,%p),stub\n",pidata
,lcid
,pptinfo
);
433 /******************************************************************************
434 * CreateStdDispatch [OLE2DISP.32]
436 HRESULT WINAPI
CreateStdDispatch16(
440 IUnknown
** ppunkStdDisp
)
442 FIXME("(%p,%p,%p,%p),stub\n",punkOuter
, pvThis
, ptinfo
,
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
);
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
);
466 /******************************************************************************
467 * SetErrorInfo [OLE2DISP.110]
469 HRESULT WINAPI
SetErrorInfo16(ULONG dwReserved
, IErrorInfo
*perrinfo
)
471 FIXME("stub: (%d, %p)\n", dwReserved
, perrinfo
);
475 /******************************************************************************
476 * VariantInit [OLE2DISP.8]
478 void WINAPI
VariantInit16(VARIANTARG16
*v
)