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