netstat: Initial implementation.
[wine] / dlls / ole2disp.dll16 / ole2disp.c
1 /*
2  *      OLE2DISP library
3  *
4  *      Copyright 1995  Martin von Loewis
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <string.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "oleauto.h"
32 #include "winerror.h"
33 #include "wine/windef16.h"
34 #include "wine/winbase16.h"
35
36 #include "ole2disp.h"
37
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(ole);
41
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 */
45
46 /******************************************************************************
47  *              BSTR_AllocBytes [Internal]
48  */
49 static BSTR16 BSTR_AllocBytes(int n)
50 {
51     void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
52     return (BSTR16)MapLS(ptr);
53 }
54
55 /******************************************************************************
56  * BSTR_Free [INTERNAL]
57  */
58 static void BSTR_Free(BSTR16 in)
59 {
60     void *ptr = MapSL( (SEGPTR)in );
61     UnMapLS( (SEGPTR)in );
62     HeapFree( GetProcessHeap(), 0, ptr );
63 }
64
65 /******************************************************************************
66  * BSTR_GetAddr [INTERNAL]
67  */
68 static void* BSTR_GetAddr(BSTR16 in)
69 {
70     return in ? MapSL((SEGPTR)in) : 0;
71 }
72
73 /******************************************************************************
74  *              SysAllocString  [OLE2DISP.2]
75  *
76  * Create a BSTR16 from an OLESTR16 (16 Bit).
77  *
78  * PARAMS
79  *  oleStr [I] Source to create BSTR16 from
80  *
81  * RETURNS
82  *  Success: A BSTR16 allocated with SysAllocStringLen16().
83  *  Failure: NULL, if oleStr is NULL.
84  */
85 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
86 {
87         BSTR16 out;
88
89         if (!oleStr) return 0;
90
91         out = BSTR_AllocBytes(strlen(oleStr)+1);
92         if (!out) return 0;
93         strcpy(BSTR_GetAddr(out),oleStr);
94         return out;
95 }
96
97 /******************************************************************************
98  *              SysReallocString        [OLE2DISP.3]
99  *
100  * Change the length of a previously created BSTR16 (16 Bit).
101  *
102  * PARAMS
103  *  pbstr  [I] BSTR16 to change the length of
104  *  oleStr [I] New source for pbstr
105  *
106  * RETURNS
107  *  Success: 1
108  *  Failure: 0.
109  *
110  * NOTES
111  *  SysAllocStringStringLen16().
112  */
113 INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
114 {
115         BSTR16 new=SysAllocString16(oleStr);
116         BSTR_Free(*pbstr);
117         *pbstr=new;
118         return 1;
119 }
120
121 /******************************************************************************
122  *              SysAllocStringLen       [OLE2DISP.4]
123  *
124  * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
125  *
126  * PARAMS
127  *  oleStr [I] Source to create BSTR16 from
128  *  len    [I] Length of oleStr in wide characters
129  *
130  * RETURNS
131  *  Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
132  *  Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
133  *
134  * NOTES
135  *  See SysAllocStringByteLen16().
136  */
137 BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
138 {
139     BSTR16 out=BSTR_AllocBytes(len+1);
140
141     if (!out)
142         return 0;
143
144     /*
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.
148     */
149     if (oleStr != 0)
150         strcpy(BSTR_GetAddr(out),oleStr);
151     else
152         memset(BSTR_GetAddr(out), 0, len+1);
153
154     return out;
155 }
156
157 /******************************************************************************
158  *              SysReAllocStringLen     [OLE2DISP.5]
159  *
160  * Change the length of a previously created BSTR16 (16 Bit).
161  *
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
166  *
167  * RETURNS
168  *  Success: 1. The size of pbstr is updated.
169  *  Failure: 0, if len >= 0x8000 or memory allocation fails.
170  *
171  * NOTES
172  *  See SysAllocStringByteLen16().
173  *  *pbstr may be changed by this function.
174  */
175 int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
176 {
177         /* FIXME: Check input length */
178         BSTR16 new=SysAllocStringLen16(in,len);
179         BSTR_Free(*old);
180         *old=new;
181         return 1;
182 }
183
184 /******************************************************************************
185  *              SysFreeString   [OLE2DISP.6]
186  *
187  * Free a BSTR16 (16 Bit).
188  *
189  * PARAMS
190  *  str [I] String to free.
191  *
192  * RETURNS
193  *  Nothing.
194  */
195 void WINAPI SysFreeString16(BSTR16 str)
196 {
197         BSTR_Free(str);
198 }
199
200 /******************************************************************************
201  *              SysStringLen    [OLE2DISP.7]
202  *
203  * Get the allocated length of a BSTR16 in characters (16 Bit).
204  *
205  * PARAMS
206  *  str [I] BSTR16 to find the length of
207  *
208  * RETURNS
209  *  The allocated length of str, or 0 if str is NULL.
210  */
211 int WINAPI SysStringLen16(BSTR16 str)
212 {
213         return strlen(BSTR_GetAddr(str));
214 }
215
216 /******************************************************************************
217  * CreateDispTypeInfo [OLE2DISP.31]
218  */
219 HRESULT WINAPI CreateDispTypeInfo16(
220         INTERFACEDATA *pidata,
221         LCID lcid,
222         ITypeInfo **pptinfo)
223 {
224         FIXME("(%p,%d,%p),stub\n",pidata,lcid,pptinfo);
225         return E_NOTIMPL;
226 }
227
228 /******************************************************************************
229  * CreateStdDispatch [OLE2DISP.32]
230  */
231 HRESULT WINAPI CreateStdDispatch16(
232         IUnknown* punkOuter,
233         void* pvThis,
234         ITypeInfo* ptinfo,
235         IUnknown** ppunkStdDisp)
236 {
237         FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
238                ppunkStdDisp);
239         return 0;
240 }
241
242 /******************************************************************************
243  * RegisterActiveObject [OLE2DISP.35]
244  */
245 HRESULT WINAPI RegisterActiveObject16(
246         IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
247 ) {
248         FIXME("(%p,%s,0x%08x,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
249         return E_NOTIMPL;
250 }
251
252 /******************************************************************************
253  * SetErrorInfo [OLE2DISP.110]
254  */
255 HRESULT WINAPI SetErrorInfo16(ULONG dwReserved, IErrorInfo *perrinfo)
256 {
257         FIXME("stub: (%d, %p)\n", dwReserved, perrinfo);
258         return E_INVALIDARG;
259 }