fdopen: don't rewind the file after creating the FILE* handle. Added
[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 <string.h>
24
25 #include "wine/windef16.h"
26 #include "ole2.h"
27 #include "oleauto.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33
34 #include "ole2disp.h"
35 #include "olectl.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 BSTR16 WINAPI SysAllocString16(LPCOLESTR16 in)
76 {
77         BSTR16 out;
78
79         if (!in) return 0;
80
81         out = BSTR_AllocBytes(strlen(in)+1);
82         if (!out) return 0;
83         strcpy(BSTR_GetAddr(out),in);
84         return out;
85 }
86
87 /******************************************************************************
88  *              SysReallocString        [OLE2DISP.3]
89  */
90 INT16 WINAPI SysReAllocString16(LPBSTR16 old,LPCOLESTR16 in)
91 {
92         BSTR16 new=SysAllocString16(in);
93         BSTR_Free(*old);
94         *old=new;
95         return 1;
96 }
97
98 /******************************************************************************
99  *              SysAllocStringLen       [OLE2DISP.4]
100  */
101 BSTR16 WINAPI SysAllocStringLen16(const char *in, int len)
102 {
103         BSTR16 out=BSTR_AllocBytes(len+1);
104
105         if (!out)
106                 return 0;
107
108     /*
109      * Copy the information in the buffer.
110      * Since it is valid to pass a NULL pointer here, we'll initialize the
111      * buffer to nul if it is the case.
112      */
113     if (in != 0)
114         strcpy(BSTR_GetAddr(out),in);
115     else
116       memset(BSTR_GetAddr(out), 0, len+1);
117
118         return out;
119 }
120
121 /******************************************************************************
122  *              SysReAllocStringLen     [OLE2DISP.5]
123  */
124 int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
125 {
126         BSTR16 new=SysAllocStringLen16(in,len);
127         BSTR_Free(*old);
128         *old=new;
129         return 1;
130 }
131
132 /******************************************************************************
133  *              SysFreeString   [OLE2DISP.6]
134  */
135 void WINAPI SysFreeString16(BSTR16 in)
136 {
137         BSTR_Free(in);
138 }
139
140 /******************************************************************************
141  *              SysStringLen    [OLE2DISP.7]
142  */
143 int WINAPI SysStringLen16(BSTR16 str)
144 {
145         return strlen(BSTR_GetAddr(str));
146 }
147
148 /******************************************************************************
149  * CreateDispTypeInfo [OLE2DISP.31]
150  */
151 HRESULT WINAPI CreateDispTypeInfo16(
152         INTERFACEDATA *pidata,
153         LCID lcid,
154         ITypeInfo **pptinfo)
155 {
156         FIXME("(%p,%ld,%p),stub\n",pidata,lcid,pptinfo);
157         return E_NOTIMPL;
158 }
159
160 /******************************************************************************
161  * CreateStdDispatch [OLE2DISP.32]
162  */
163 HRESULT WINAPI CreateStdDispatch16(
164         IUnknown* punkOuter,
165         void* pvThis,
166         ITypeInfo* ptinfo,
167         IUnknown** ppunkStdDisp)
168 {
169         FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
170                ppunkStdDisp);
171         return 0;
172 }
173
174 /******************************************************************************
175  * RegisterActiveObject [OLE2DISP.35]
176  */
177 HRESULT WINAPI RegisterActiveObject16(
178         IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
179 ) {
180         FIXME("(%p,%s,0x%08lx,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
181         return E_NOTIMPL;
182 }