ole2disp.c 6.45 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4
/*
 *	OLE2DISP library
 *
 *	Copyright 1995	Martin von Loewis
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
19
 */
20 21 22

#include "config.h"

23
#include <stdarg.h>
24
#include <string.h>
25

26
#include "windef.h"
27
#include "winbase.h"
28 29
#include "wingdi.h"
#include "winuser.h"
30 31
#include "ole2.h"
#include "oleauto.h"
32
#include "winerror.h"
33 34
#include "wine/windef16.h"
#include "wine/winbase16.h"
35 36 37

#include "ole2disp.h"

38
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
39

40
WINE_DEFAULT_DEBUG_CHANNEL(ole);
41

Alexandre Julliard's avatar
Alexandre Julliard committed
42 43 44 45
/* This implementation of the BSTR API is 16-bit only. It
   represents BSTR as a 16:16 far pointer, and the strings
   as ISO-8859 */

46 47 48
/******************************************************************************
 *		BSTR_AllocBytes	[Internal]
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
49
static BSTR16 BSTR_AllocBytes(int n)
Alexandre Julliard's avatar
Alexandre Julliard committed
50
{
51 52
    void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
    return (BSTR16)MapLS(ptr);
Alexandre Julliard's avatar
Alexandre Julliard committed
53 54
}

Matthew Becker's avatar
Matthew Becker committed
55 56 57
/******************************************************************************
 * BSTR_Free [INTERNAL]
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
58
static void BSTR_Free(BSTR16 in)
Alexandre Julliard's avatar
Alexandre Julliard committed
59
{
60 61 62
    void *ptr = MapSL( (SEGPTR)in );
    UnMapLS( (SEGPTR)in );
    HeapFree( GetProcessHeap(), 0, ptr );
Alexandre Julliard's avatar
Alexandre Julliard committed
63 64
}

Matthew Becker's avatar
Matthew Becker committed
65 66 67
/******************************************************************************
 * BSTR_GetAddr [INTERNAL]
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
68
static void* BSTR_GetAddr(BSTR16 in)
Alexandre Julliard's avatar
Alexandre Julliard committed
69
{
70
    return in ? MapSL((SEGPTR)in) : 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
71 72
}

73
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
74
 *		SysAllocString	[OLE2DISP.2]
Jon Griffiths's avatar
Jon Griffiths committed
75 76 77 78 79 80 81 82 83
 *
 * Create a BSTR16 from an OLESTR16 (16 Bit).
 *
 * PARAMS
 *  oleStr [I] Source to create BSTR16 from
 *
 * RETURNS
 *  Success: A BSTR16 allocated with SysAllocStringLen16().
 *  Failure: NULL, if oleStr is NULL.
Alexandre Julliard's avatar
Alexandre Julliard committed
84
 */
Jon Griffiths's avatar
Jon Griffiths committed
85
BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
Alexandre Julliard's avatar
Alexandre Julliard committed
86
{
87
	BSTR16 out;
88

Jon Griffiths's avatar
Jon Griffiths committed
89
	if (!oleStr) return 0;
90

Jon Griffiths's avatar
Jon Griffiths committed
91
	out = BSTR_AllocBytes(strlen(oleStr)+1);
Andreas Mohr's avatar
Andreas Mohr committed
92
	if (!out) return 0;
Jon Griffiths's avatar
Jon Griffiths committed
93
	strcpy(BSTR_GetAddr(out),oleStr);
Alexandre Julliard's avatar
Alexandre Julliard committed
94 95 96
	return out;
}

97
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
98
 *		SysReallocString	[OLE2DISP.3]
Jon Griffiths's avatar
Jon Griffiths committed
99 100 101 102 103 104 105 106 107 108 109 110 111
 *
 * Change the length of a previously created BSTR16 (16 Bit).
 *
 * PARAMS
 *  pbstr  [I] BSTR16 to change the length of
 *  oleStr [I] New source for pbstr
 *
 * RETURNS
 *  Success: 1
 *  Failure: 0.
 *
 * NOTES
 *  SysAllocStringStringLen16().
Alexandre Julliard's avatar
Alexandre Julliard committed
112
 */
Jon Griffiths's avatar
Jon Griffiths committed
113
INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
Alexandre Julliard's avatar
Alexandre Julliard committed
114
{
Jon Griffiths's avatar
Jon Griffiths committed
115 116 117
	BSTR16 new=SysAllocString16(oleStr);
	BSTR_Free(*pbstr);
	*pbstr=new;
Alexandre Julliard's avatar
Alexandre Julliard committed
118 119 120
	return 1;
}

121
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
122
 *		SysAllocStringLen	[OLE2DISP.4]
Jon Griffiths's avatar
Jon Griffiths committed
123 124 125 126 127 128 129 130 131 132 133 134 135
 *
 * Create a BSTR16 from an OLESTR16 of a given character length (16 Bit).
 *
 * PARAMS
 *  oleStr [I] Source to create BSTR16 from
 *  len    [I] Length of oleStr in wide characters
 *
 * RETURNS
 *  Success: A newly allocated BSTR16 from SysAllocStringByteLen16()
 *  Failure: NULL, if len is >= 0x80000000, or memory allocation fails.
 *
 * NOTES
 *  See SysAllocStringByteLen16().
Alexandre Julliard's avatar
Alexandre Julliard committed
136
 */
Jon Griffiths's avatar
Jon Griffiths committed
137
BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
Alexandre Julliard's avatar
Alexandre Julliard committed
138
{
Alexandre Julliard's avatar
Alexandre Julliard committed
139
	BSTR16 out=BSTR_AllocBytes(len+1);
140 141 142 143 144 145 146 147 148

	if (!out)
		return 0;

    /*
     * Copy the information in the buffer.
     * Since it is valid to pass a NULL pointer here, we'll initialize the
     * buffer to nul if it is the case.
     */
Jon Griffiths's avatar
Jon Griffiths committed
149 150
    if (oleStr != 0)
	strcpy(BSTR_GetAddr(out),oleStr);
151 152 153
    else
      memset(BSTR_GetAddr(out), 0, len+1);

Alexandre Julliard's avatar
Alexandre Julliard committed
154 155 156
	return out;
}

157
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
158
 *		SysReAllocStringLen	[OLE2DISP.5]
Jon Griffiths's avatar
Jon Griffiths committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
 *
 * Change the length of a previously created BSTR16 (16 Bit).
 *
 * PARAMS
 *  pbstr  [I] BSTR16 to change the length of
 *  oleStr [I] New source for pbstr
 *  len    [I] Length of oleStr in characters
 *
 * RETURNS
 *  Success: 1. The size of pbstr is updated.
 *  Failure: 0, if len >= 0x8000 or memory allocation fails.
 *
 * NOTES
 *  See SysAllocStringByteLen16().
 *  *pbstr may be changed by this function.
Alexandre Julliard's avatar
Alexandre Julliard committed
174
 */
175
int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
Alexandre Julliard's avatar
Alexandre Julliard committed
176
{
Jon Griffiths's avatar
Jon Griffiths committed
177
	/* FIXME: Check input length */
Alexandre Julliard's avatar
Alexandre Julliard committed
178
	BSTR16 new=SysAllocStringLen16(in,len);
Alexandre Julliard's avatar
Alexandre Julliard committed
179 180 181 182 183
	BSTR_Free(*old);
	*old=new;
	return 1;
}

184
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
185
 *		SysFreeString	[OLE2DISP.6]
Jon Griffiths's avatar
Jon Griffiths committed
186 187 188 189 190 191 192 193
 *
 * Free a BSTR16 (16 Bit).
 *
 * PARAMS
 *  str [I] String to free.
 *
 * RETURNS
 *  Nothing.
Alexandre Julliard's avatar
Alexandre Julliard committed
194
 */
Jon Griffiths's avatar
Jon Griffiths committed
195
void WINAPI SysFreeString16(BSTR16 str)
Alexandre Julliard's avatar
Alexandre Julliard committed
196
{
Jon Griffiths's avatar
Jon Griffiths committed
197
	BSTR_Free(str);
Alexandre Julliard's avatar
Alexandre Julliard committed
198 199
}

200
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
201
 *		SysStringLen	[OLE2DISP.7]
Jon Griffiths's avatar
Jon Griffiths committed
202 203 204 205 206 207 208 209
 *
 * Get the allocated length of a BSTR16 in characters (16 Bit).
 *
 * PARAMS
 *  str [I] BSTR16 to find the length of
 *
 * RETURNS
 *  The allocated length of str, or 0 if str is NULL.
Alexandre Julliard's avatar
Alexandre Julliard committed
210
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
211
int WINAPI SysStringLen16(BSTR16 str)
Alexandre Julliard's avatar
Alexandre Julliard committed
212 213 214
{
	return strlen(BSTR_GetAddr(str));
}
Alexandre Julliard's avatar
Alexandre Julliard committed
215

Matthew Becker's avatar
Matthew Becker committed
216
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
217
 * CreateDispTypeInfo [OLE2DISP.31]
Matthew Becker's avatar
Matthew Becker committed
218
 */
Andreas Mohr's avatar
Andreas Mohr committed
219
HRESULT WINAPI CreateDispTypeInfo16(
Alexandre Julliard's avatar
Alexandre Julliard committed
220 221
	INTERFACEDATA *pidata,
	LCID lcid,
222 223
	ITypeInfo **pptinfo)
{
224
	FIXME("(%p,%d,%p),stub\n",pidata,lcid,pptinfo);
225
	return E_NOTIMPL;
226 227 228
}

/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
229
 * CreateStdDispatch [OLE2DISP.32]
230 231 232 233 234 235
 */
HRESULT WINAPI CreateStdDispatch16(
        IUnknown* punkOuter,
        void* pvThis,
	ITypeInfo* ptinfo,
	IUnknown** ppunkStdDisp)
236 237 238 239 240 241
{
	FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
               ppunkStdDisp);
	return 0;
}

Matthew Becker's avatar
Matthew Becker committed
242 243 244
/******************************************************************************
 * RegisterActiveObject [OLE2DISP.35]
 */
Andreas Mohr's avatar
Andreas Mohr committed
245
HRESULT WINAPI RegisterActiveObject16(
246
	IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
Alexandre Julliard's avatar
Alexandre Julliard committed
247
) {
248
	FIXME("(%p,%s,0x%08x,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
249
	return E_NOTIMPL;
Alexandre Julliard's avatar
Alexandre Julliard committed
250
}
251 252 253 254 255 256 257 258 259

/******************************************************************************
 * SetErrorInfo [OLE2DISP.110]
 */
HRESULT WINAPI SetErrorInfo16(ULONG dwReserved, IErrorInfo *perrinfo)
{
        FIXME("stub: (%d, %p)\n", dwReserved, perrinfo);
        return E_INVALIDARG;
}