It's important to keep the original dib colour table and not just the
[wine/multimedia.git] / dlls / oleaut32 / ole2disp.c
blob7d9cf571f937b2ff2c0010144c1364a5e4c13f2c
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <string.h>
26 #include "wine/windef16.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "ole2.h"
32 #include "oleauto.h"
33 #include "winerror.h"
35 #include "ole2disp.h"
36 #include "olectl.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
44 as ISO-8859 */
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).
78 * PARAMS
79 * oleStr [I] Source to create BSTR16 from
81 * RETURNS
82 * Success: A BSTR16 allocated with SysAllocStringLen16().
83 * Failure: NULL, if oleStr is NULL.
85 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
87 BSTR16 out;
89 if (!oleStr) return 0;
91 out = BSTR_AllocBytes(strlen(oleStr)+1);
92 if (!out) return 0;
93 strcpy(BSTR_GetAddr(out),oleStr);
94 return out;
97 /******************************************************************************
98 * SysReallocString [OLE2DISP.3]
100 * Change the length of a previously created BSTR16 (16 Bit).
102 * PARAMS
103 * pbstr [I] BSTR16 to change the length of
104 * oleStr [I] New source for pbstr
106 * RETURNS
107 * Success: 1
108 * Failure: 0.
110 * NOTES
111 * SysAllocStringStringLen16().
113 INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
115 BSTR16 new=SysAllocString16(oleStr);
116 BSTR_Free(*pbstr);
117 *pbstr=new;
118 return 1;
121 /******************************************************************************
122 * SysAllocStringLen [OLE2DISP.4]
124 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
126 * PARAMS
127 * oleStr [I] Source to create BSTR16 from
128 * len [I] Length of oleStr in wide characters
130 * RETURNS
131 * Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
132 * Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
134 * NOTES
135 * See SysAllocStringByteLen16().
137 BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
139 BSTR16 out=BSTR_AllocBytes(len+1);
141 if (!out)
142 return 0;
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.
149 if (oleStr != 0)
150 strcpy(BSTR_GetAddr(out),oleStr);
151 else
152 memset(BSTR_GetAddr(out), 0, len+1);
154 return out;
157 /******************************************************************************
158 * SysReAllocStringLen [OLE2DISP.5]
160 * Change the length of a previously created BSTR16 (16 Bit).
162 * PARAMS
163 * pbstr [I] BSTR16 to change the length of
164 * oleStr [I] New source for pbstr
165 * len [I] Length of oleStr in characters
167 * RETURNS
168 * Success: 1. The size of pbstr is updated.
169 * Failure: 0, if len >= 0x8000 or memory allocation fails.
171 * NOTES
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);
179 BSTR_Free(*old);
180 *old=new;
181 return 1;
184 /******************************************************************************
185 * SysFreeString [OLE2DISP.6]
187 * Free a BSTR16 (16 Bit).
189 * PARAMS
190 * str [I] String to free.
192 * RETURNS
193 * Nothing.
195 void WINAPI SysFreeString16(BSTR16 str)
197 BSTR_Free(str);
200 /******************************************************************************
201 * SysStringLen [OLE2DISP.7]
203 * Get the allocated length of a BSTR16 in characters (16 Bit).
205 * PARAMS
206 * str [I] BSTR16 to find the length of
208 * RETURNS
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,
221 LCID lcid,
222 ITypeInfo **pptinfo)
224 FIXME("(%p,%ld,%p),stub\n",pidata,lcid,pptinfo);
225 return E_NOTIMPL;
228 /******************************************************************************
229 * CreateStdDispatch [OLE2DISP.32]
231 HRESULT WINAPI CreateStdDispatch16(
232 IUnknown* punkOuter,
233 void* pvThis,
234 ITypeInfo* ptinfo,
235 IUnknown** ppunkStdDisp)
237 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
238 ppunkStdDisp);
239 return 0;
242 /******************************************************************************
243 * RegisterActiveObject [OLE2DISP.35]
245 HRESULT WINAPI RegisterActiveObject16(
246 IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
248 FIXME("(%p,%s,0x%08lx,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
249 return E_NOTIMPL;