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
33 #include "wine/windef16.h"
34 #include "wine/winbase16.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
42 /* This implementation of the BSTR API is 16-bit only. It
43 represents BSTR as a 16:16 far pointer, and the strings
46 /******************************************************************************
47 * BSTR_AllocBytes [Internal]
49 static BSTR16 BSTR_AllocBytes(int n)
51 void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
52 return (BSTR16)MapLS(ptr);
55 /******************************************************************************
56 * BSTR_Free [INTERNAL]
58 static void BSTR_Free(BSTR16 in)
60 void *ptr = MapSL( (SEGPTR)in );
61 UnMapLS( (SEGPTR)in );
62 HeapFree( GetProcessHeap(), 0, ptr );
65 /******************************************************************************
66 * BSTR_GetAddr [INTERNAL]
68 static void* BSTR_GetAddr(BSTR16 in)
70 return in ? MapSL((SEGPTR)in) : 0;
73 /******************************************************************************
74 * SysAllocString [OLE2DISP.2]
76 * Create a BSTR16 from an OLESTR16 (16 Bit).
79 * oleStr [I] Source to create BSTR16 from
82 * Success: A BSTR16 allocated with SysAllocStringLen16().
83 * Failure: NULL, if oleStr is NULL.
85 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
89 if (!oleStr) return 0;
91 out = BSTR_AllocBytes(strlen(oleStr)+1);
93 strcpy(BSTR_GetAddr(out),oleStr);
97 /******************************************************************************
98 * SysReallocString [OLE2DISP.3]
100 * Change the length of a previously created BSTR16 (16 Bit).
103 * pbstr [I] BSTR16 to change the length of
104 * oleStr [I] New source for pbstr
111 * SysAllocStringStringLen16().
113 INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
115 BSTR16 new=SysAllocString16(oleStr);
121 /******************************************************************************
122 * SysAllocStringLen [OLE2DISP.4]
124 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
127 * oleStr [I] Source to create BSTR16 from
128 * len [I] Length of oleStr in wide characters
131 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
132 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
135 * See SysAllocStringByteLen16().
137 BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
139 BSTR16 out=BSTR_AllocBytes(len+1);
145 * Copy the information in the buffer.
146 * Since it is valid to pass a NULL pointer here, we'll initialize the
147 * buffer to nul if it is the case.
150 strcpy(BSTR_GetAddr(out),oleStr);
152 memset(BSTR_GetAddr(out), 0, len+1);
157 /******************************************************************************
158 * SysReAllocStringLen [OLE2DISP.5]
160 * Change the length of a previously created BSTR16 (16 Bit).
163 * pbstr [I] BSTR16 to change the length of
164 * oleStr [I] New source for pbstr
165 * len [I] Length of oleStr in characters
168 * Success: 1. The size of pbstr is updated.
169 * Failure: 0, if len >= 0x8000 or memory allocation fails.
172 * See SysAllocStringByteLen16().
173 * *pbstr may be changed by this function.
175 int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
177 /* FIXME: Check input length */
178 BSTR16 new=SysAllocStringLen16(in,len);
184 /******************************************************************************
185 * SysFreeString [OLE2DISP.6]
187 * Free a BSTR16 (16 Bit).
190 * str [I] String to free.
195 void WINAPI SysFreeString16(BSTR16 str)
200 /******************************************************************************
201 * SysStringLen [OLE2DISP.7]
203 * Get the allocated length of a BSTR16 in characters (16 Bit).
206 * str [I] BSTR16 to find the length of
209 * The allocated length of str, or 0 if str is NULL.
211 int WINAPI SysStringLen16(BSTR16 str)
213 return strlen(BSTR_GetAddr(str));
216 /******************************************************************************
217 * CreateDispTypeInfo [OLE2DISP.31]
219 HRESULT WINAPI CreateDispTypeInfo16(
220 INTERFACEDATA *pidata,
224 FIXME("(%p,%d,%p),stub\n",pidata,lcid,pptinfo);
228 /******************************************************************************
229 * CreateStdDispatch [OLE2DISP.32]
231 HRESULT WINAPI CreateStdDispatch16(
235 IUnknown** ppunkStdDisp)
237 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
242 /******************************************************************************
243 * RegisterActiveObject [OLE2DISP.35]
245 HRESULT WINAPI RegisterActiveObject16(
246 IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
248 FIXME("(%p,%s,0x%08x,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
252 /******************************************************************************
253 * SetErrorInfo [OLE2DISP.110]
255 HRESULT WINAPI SetErrorInfo16(ULONG dwReserved, IErrorInfo *perrinfo)
257 FIXME("stub: (%d, %p)\n", dwReserved, perrinfo);