ole2disp.c 6.16 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 "wine/windef16.h"
27
#include "windef.h"
28
#include "winbase.h"
29 30
#include "wingdi.h"
#include "winuser.h"
31 32
#include "ole2.h"
#include "oleauto.h"
33 34 35 36
#include "winerror.h"

#include "ole2disp.h"

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

39
WINE_DEFAULT_DEBUG_CHANNEL(ole);
40

Alexandre Julliard's avatar
Alexandre Julliard committed
41 42 43 44
/* 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 */

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

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

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

72
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
73
 *		SysAllocString	[OLE2DISP.2]
Jon Griffiths's avatar
Jon Griffiths committed
74 75 76 77 78 79 80 81 82
 *
 * 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
83
 */
Jon Griffiths's avatar
Jon Griffiths committed
84
BSTR16 WINAPI SysAllocString16(LPCOLESTR16 oleStr)
Alexandre Julliard's avatar
Alexandre Julliard committed
85
{
86
	BSTR16 out;
87

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

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

96
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
97
 *		SysReallocString	[OLE2DISP.3]
Jon Griffiths's avatar
Jon Griffiths committed
98 99 100 101 102 103 104 105 106 107 108 109 110
 *
 * 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
111
 */
Jon Griffiths's avatar
Jon Griffiths committed
112
INT16 WINAPI SysReAllocString16(LPBSTR16 pbstr,LPCOLESTR16 oleStr)
Alexandre Julliard's avatar
Alexandre Julliard committed
113
{
Jon Griffiths's avatar
Jon Griffiths committed
114 115 116
	BSTR16 new=SysAllocString16(oleStr);
	BSTR_Free(*pbstr);
	*pbstr=new;
Alexandre Julliard's avatar
Alexandre Julliard committed
117 118 119
	return 1;
}

120
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
121
 *		SysAllocStringLen	[OLE2DISP.4]
Jon Griffiths's avatar
Jon Griffiths committed
122 123 124 125 126 127 128 129 130 131 132 133 134
 *
 * 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
135
 */
Jon Griffiths's avatar
Jon Griffiths committed
136
BSTR16 WINAPI SysAllocStringLen16(const char *oleStr, int len)
Alexandre Julliard's avatar
Alexandre Julliard committed
137
{
Alexandre Julliard's avatar
Alexandre Julliard committed
138
	BSTR16 out=BSTR_AllocBytes(len+1);
139 140 141 142 143 144 145 146 147

	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
148 149
    if (oleStr != 0)
	strcpy(BSTR_GetAddr(out),oleStr);
150 151 152
    else
      memset(BSTR_GetAddr(out), 0, len+1);

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

156
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
157
 *		SysReAllocStringLen	[OLE2DISP.5]
Jon Griffiths's avatar
Jon Griffiths committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
 *
 * 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
173
 */
174
int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
Alexandre Julliard's avatar
Alexandre Julliard committed
175
{
Jon Griffiths's avatar
Jon Griffiths committed
176
	/* FIXME: Check input length */
Alexandre Julliard's avatar
Alexandre Julliard committed
177
	BSTR16 new=SysAllocStringLen16(in,len);
Alexandre Julliard's avatar
Alexandre Julliard committed
178 179 180 181 182
	BSTR_Free(*old);
	*old=new;
	return 1;
}

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

199
/******************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
200
 *		SysStringLen	[OLE2DISP.7]
Jon Griffiths's avatar
Jon Griffiths committed
201 202 203 204 205 206 207 208
 *
 * 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
209
 */
Alexandre Julliard's avatar
Alexandre Julliard committed
210
int WINAPI SysStringLen16(BSTR16 str)
Alexandre Julliard's avatar
Alexandre Julliard committed
211 212 213
{
	return strlen(BSTR_GetAddr(str));
}
Alexandre Julliard's avatar
Alexandre Julliard committed
214

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

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

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