source: trunk/src/oleaut32/ole2disp.c

Last change on this file was 9400, checked in by sandervl, 23 years ago

Wine resync

File size: 13.4 KB
RevLine 
[4837]1/*
[6711]2 * OLE2DISP library
[4837]3 *
[6711]4 * Copyright 1995 Martin von Loewis
[8450]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
[4837]19 */
[8450]20
21#include "config.h"
22
[4837]23#include <string.h>
24
[8450]25#include "wine/windef16.h"
26#include "ole2.h"
27#include "oleauto.h"
[4837]28#include "windef.h"
29#include "winbase.h"
[8450]30#include "winerror.h"
[4837]31#include "wingdi.h"
32#include "winuser.h"
[8450]33
34#include "ole2disp.h"
[4837]35#include "olectl.h"
36
[8450]37#include "wine/debug.h"
[4837]38
[8450]39WINE_DEFAULT_DEBUG_CHANNEL(ole);
40
[4837]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/******************************************************************************
[6711]46 * BSTR_AllocBytes [Internal]
[4837]47 */
48static BSTR16 BSTR_AllocBytes(int n)
49{
[8450]50 void *ptr = HeapAlloc( GetProcessHeap(), 0, n );
51 return (BSTR16)MapLS(ptr);
[4837]52}
53
54/******************************************************************************
55 * BSTR_Free [INTERNAL]
56 */
57static void BSTR_Free(BSTR16 in)
58{
[8450]59 void *ptr = MapSL( (SEGPTR)in );
60 UnMapLS( (SEGPTR)in );
61 HeapFree( GetProcessHeap(), 0, ptr );
[4837]62}
63
64/******************************************************************************
65 * BSTR_GetAddr [INTERNAL]
66 */
67static void* BSTR_GetAddr(BSTR16 in)
68{
69 return in ? MapSL((SEGPTR)in) : 0;
70}
71
72/******************************************************************************
[8450]73 * SysAllocString [OLE2DISP.2]
[4837]74 */
75BSTR16 WINAPI SysAllocString16(LPCOLESTR16 in)
76{
[6711]77 BSTR16 out;
[9400]78
[6711]79 if (!in) return 0;
[9400]80
[6711]81 out = BSTR_AllocBytes(strlen(in)+1);
[8450]82 if (!out) return 0;
[6711]83 strcpy(BSTR_GetAddr(out),in);
84 return out;
[4837]85}
86
87/******************************************************************************
[6711]88 * SysAllocString [OLEAUT32.2]
[8450]89 *
90 * MSDN (October 2001) states that this returns a NULL value if the argument
91 * is a zero-length string. This does not appear to be true; certainly it
92 * returns a value under Win98 (Oleaut32.dll Ver 2.40.4515.0)
[4837]93 */
94BSTR WINAPI SysAllocString(LPCOLESTR in)
95{
96 if (!in) return 0;
[9400]97
[4837]98 /* Delegate this to the SysAllocStringLen32 method. */
99 return SysAllocStringLen(in, lstrlenW(in));
100}
101
102/******************************************************************************
[8450]103 * SysReallocString [OLE2DISP.3]
[4837]104 */
105INT16 WINAPI SysReAllocString16(LPBSTR16 old,LPCOLESTR16 in)
106{
[6711]107 BSTR16 new=SysAllocString16(in);
108 BSTR_Free(*old);
109 *old=new;
110 return 1;
[4837]111}
112
113/******************************************************************************
[6711]114 * SysReAllocString [OLEAUT32.3]
[4837]115 */
116INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR in)
117{
118 /*
119 * Sanity check
120 */
[9400]121 if (old==NULL)
[4837]122 return 0;
123
124 /*
125 * Make sure we free the old string.
126 */
[9400]127 if (*old!=NULL)
[4837]128 SysFreeString(*old);
129
130 /*
131 * Allocate the new string
132 */
133 *old = SysAllocString(in);
134
135 return 1;
136}
137
138/******************************************************************************
[8450]139 * SysAllocStringLen [OLE2DISP.4]
[4837]140 */
141BSTR16 WINAPI SysAllocStringLen16(const char *in, int len)
142{
[6711]143 BSTR16 out=BSTR_AllocBytes(len+1);
[4837]144
[6711]145 if (!out)
146 return 0;
[4837]147
148 /*
149 * Copy the information in the buffer.
150 * Since it is valid to pass a NULL pointer here, we'll initialize the
151 * buffer to nul if it is the case.
152 */
153 if (in != 0)
[6711]154 strcpy(BSTR_GetAddr(out),in);
[4837]155 else
156 memset(BSTR_GetAddr(out), 0, len+1);
157
[6711]158 return out;
[4837]159}
160
161/******************************************************************************
162 * SysAllocStringLen [OLEAUT32.4]
163 *
164 * In "Inside OLE, second edition" by Kraig Brockshmidt. In the Automation
165 * section, he describes the DWORD value placed *before* the BSTR data type.
166 * he describes it as a "DWORD count of characters". By experimenting with
167 * a windows application, this count seems to be a DWORD count of bytes in
[9400]168 * the string. Meaning that the count is double the number of wide
[4837]169 * characters in the string.
170 */
171BSTR WINAPI SysAllocStringLen(const OLECHAR *in, unsigned int len)
172{
173 DWORD bufferSize;
174 DWORD* newBuffer;
175 WCHAR* stringBuffer;
176
177 /*
178 * Find the length of the buffer passed-in in bytes.
179 */
180 bufferSize = len * sizeof (WCHAR);
181
182 /*
183 * Allocate a new buffer to hold the string.
184 * dont't forget to keep an empty spot at the beginning of the
185 * buffer for the character count and an extra character at the
186 * end for the NULL.
187 */
188 newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
189 0,
190 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
191
192 /*
193 * If the memory allocation failed, return a null pointer.
194 */
195 if (newBuffer==0)
196 return 0;
197
198 /*
199 * Copy the length of the string in the placeholder.
200 */
201 *newBuffer = bufferSize;
202
203 /*
204 * Skip the byte count.
205 */
206 newBuffer++;
207
208 /*
209 * Copy the information in the buffer.
210 * Since it is valid to pass a NULL pointer here, we'll initialize the
211 * buffer to nul if it is the case.
212 */
213 if (in != 0)
214 memcpy(newBuffer, in, bufferSize);
215 else
216 memset(newBuffer, 0, bufferSize);
217
218 /*
219 * Make sure that there is a nul character at the end of the
220 * string.
221 */
222 stringBuffer = (WCHAR*)newBuffer;
223 stringBuffer[len] = L'\0';
224
225 return (LPWSTR)stringBuffer;
226}
227
228/******************************************************************************
[8450]229 * SysReAllocStringLen [OLE2DISP.5]
[4837]230 */
231int WINAPI SysReAllocStringLen16(BSTR16 *old,const char *in,int len)
232{
[6711]233 BSTR16 new=SysAllocStringLen16(in,len);
234 BSTR_Free(*old);
235 *old=new;
236 return 1;
[4837]237}
238
[9400]239
[4837]240/******************************************************************************
241 * SysReAllocStringLen [OLEAUT32.5]
242 */
243int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* in, unsigned int len)
244{
245 /*
246 * Sanity check
247 */
[9400]248 if (old==NULL)
[4837]249 return 0;
250
251 /*
252 * Make sure we free the old string.
253 */
[9400]254 if (*old!=NULL)
[4837]255 SysFreeString(*old);
256
257 /*
258 * Allocate the new string
259 */
260 *old = SysAllocStringLen(in, len);
261
262 return 1;
263}
264
265/******************************************************************************
[8450]266 * SysFreeString [OLE2DISP.6]
[4837]267 */
268void WINAPI SysFreeString16(BSTR16 in)
269{
[6711]270 BSTR_Free(in);
[4837]271}
272
273/******************************************************************************
[6711]274 * SysFreeString [OLEAUT32.6]
[4837]275 */
276void WINAPI SysFreeString(BSTR in)
277{
278 DWORD* bufferPointer;
[9400]279
[4837]280 /* NULL is a valid parameter */
281 if(!in) return;
282
283 /*
284 * We have to be careful when we free a BSTR pointer, it points to
285 * the beginning of the string but it skips the byte count contained
286 * before the string.
287 */
288 bufferPointer = (DWORD*)in;
289
290 bufferPointer--;
291
292 /*
[8450]293 * Free the memory from its "real" origin.
[4837]294 */
295 HeapFree(GetProcessHeap(), 0, bufferPointer);
296}
297
298/******************************************************************************
[8450]299 * SysStringLen [OLE2DISP.7]
[4837]300 */
301int WINAPI SysStringLen16(BSTR16 str)
302{
[6711]303 return strlen(BSTR_GetAddr(str));
[4837]304}
305
306/******************************************************************************
307 * SysStringLen [OLEAUT32.7]
308 *
309 * The Windows documentation states that the length returned by this function
310 * is not necessarely the same as the length returned by the _lstrlenW method.
311 * It is the same number that was passed in as the "len" parameter if the
312 * string was allocated with a SysAllocStringLen method call.
313 */
314int WINAPI SysStringLen(BSTR str)
315{
316 DWORD* bufferPointer;
317
318 if (!str) return 0;
319 /*
[9400]320 * The length of the string (in bytes) is contained in a DWORD placed
[4837]321 * just before the BSTR pointer
322 */
323 bufferPointer = (DWORD*)str;
324
325 bufferPointer--;
326
327 return (int)(*bufferPointer/sizeof(WCHAR));
328}
329
330/******************************************************************************
331 * SysStringByteLen [OLEAUT32.149]
332 *
333 * The Windows documentation states that the length returned by this function
334 * is not necessarely the same as the length returned by the _lstrlenW method.
335 * It is the same number that was passed in as the "len" parameter if the
336 * string was allocated with a SysAllocStringLen method call.
337 */
338int WINAPI SysStringByteLen(BSTR str)
339{
340 DWORD* bufferPointer;
341
342 if (!str) return 0;
343 /*
[9400]344 * The length of the string (in bytes) is contained in a DWORD placed
[4837]345 * just before the BSTR pointer
346 */
347 bufferPointer = (DWORD*)str;
348
349 bufferPointer--;
350
351 return (int)(*bufferPointer);
352}
353
354/******************************************************************************
[8450]355 * CreateDispTypeInfo [OLEAUT32.31]
[4837]356 */
[8450]357HRESULT WINAPI CreateDispTypeInfo(
[6711]358 INTERFACEDATA *pidata,
359 LCID lcid,
360 ITypeInfo **pptinfo)
[4837]361{
[6711]362 FIXME("(%p,%ld,%p),stub\n",pidata,lcid,pptinfo);
363 return 0;
[4837]364}
365
366/******************************************************************************
367 * CreateDispTypeInfo [OLE2DISP.31]
368 */
[8450]369HRESULT WINAPI CreateDispTypeInfo16(
[6711]370 INTERFACEDATA *pidata,
371 LCID lcid,
372 ITypeInfo **pptinfo)
[4837]373{
[6711]374 FIXME("(%p,%ld,%p),stub\n",pidata,lcid,pptinfo);
[8450]375 return E_NOTIMPL;
[4837]376}
377
378/******************************************************************************
[8450]379 * CreateStdDispatch [OLE2DISP.32]
[4837]380 */
381HRESULT WINAPI CreateStdDispatch16(
382 IUnknown* punkOuter,
383 void* pvThis,
[6711]384 ITypeInfo* ptinfo,
385 IUnknown** ppunkStdDisp)
[4837]386{
[6711]387 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
[4837]388 ppunkStdDisp);
[6711]389 return 0;
[4837]390}
391
392/******************************************************************************
[8450]393 * CreateStdDispatch [OLEAUT32.32]
[4837]394 */
395HRESULT WINAPI CreateStdDispatch(
396 IUnknown* punkOuter,
397 void* pvThis,
[6711]398 ITypeInfo* ptinfo,
399 IUnknown** ppunkStdDisp)
[4837]400{
[6711]401 FIXME("(%p,%p,%p,%p),stub\n",punkOuter, pvThis, ptinfo,
[4837]402 ppunkStdDisp);
[8450]403 return E_NOTIMPL;
[4837]404}
405
406/******************************************************************************
407 * RegisterActiveObject [OLE2DISP.35]
408 */
409HRESULT WINAPI RegisterActiveObject16(
[6711]410 IUnknown *punk, REFCLSID rclsid, DWORD dwFlags, unsigned long *pdwRegister
[4837]411) {
[6711]412 FIXME("(%p,%s,0x%08lx,%p):stub\n",punk,debugstr_guid(rclsid),dwFlags,pdwRegister);
[8450]413 return E_NOTIMPL;
[4837]414}
415
416/******************************************************************************
[6711]417 * OleTranslateColor [OLEAUT32.421]
[4837]418 *
419 * Converts an OLE_COLOR to a COLORREF.
420 * See the documentation for conversion rules.
[9400]421 * pColorRef can be NULL. In that case the user only wants to test the
[4837]422 * conversion.
423 */
424HRESULT WINAPI OleTranslateColor(
425 OLE_COLOR clr,
426 HPALETTE hpal,
427 COLORREF* pColorRef)
428{
429 COLORREF colorref;
430 BYTE b = HIBYTE(HIWORD(clr));
431
[9400]432 TRACE("(%08lx, %p, %p):stub\n", clr, hpal, pColorRef);
[4837]433
434 /*
435 * In case pColorRef is NULL, provide our own to simplify the code.
436 */
437 if (pColorRef == NULL)
438 pColorRef = &colorref;
439
440 switch (b)
441 {
442 case 0x00:
443 {
444 if (hpal != 0)
445 *pColorRef = PALETTERGB(GetRValue(clr),
446 GetGValue(clr),
447 GetBValue(clr));
448 else
449 *pColorRef = clr;
450
451 break;
452 }
453
454 case 0x01:
455 {
456 if (hpal != 0)
457 {
458 PALETTEENTRY pe;
459 /*
460 * Validate the palette index.
461 */
462 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
463 return E_INVALIDARG;
464 }
465
466 *pColorRef = clr;
467
468 break;
469 }
470
471 case 0x02:
472 *pColorRef = clr;
473 break;
474
475 case 0x80:
476 {
477 int index = LOBYTE(LOWORD(clr));
478
479 /*
480 * Validate GetSysColor index.
481 */
482 if ((index < COLOR_SCROLLBAR) || (index > COLOR_GRADIENTINACTIVECAPTION))
483 return E_INVALIDARG;
484
485 *pColorRef = GetSysColor(index);
486
487 break;
488 }
489
490 default:
491 return E_INVALIDARG;
492 }
493
494 return S_OK;
495}
496
497/******************************************************************************
498 * SysAllocStringByteLen [OLEAUT32.150]
499 *
500 */
501BSTR WINAPI SysAllocStringByteLen(LPCSTR in, UINT len)
502{
503 DWORD* newBuffer;
504 char* stringBuffer;
505
506 /*
507 * Allocate a new buffer to hold the string.
[8450]508 * dont't forget to keep an empty spot at the beginning of the
[4837]509 * buffer for the character count and an extra character at the
510 * end for the NULL.
511 */
512 newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
513 0,
514 len + sizeof(WCHAR) + sizeof(DWORD));
515
516 /*
517 * If the memory allocation failed, return a null pointer.
518 */
519 if (newBuffer==0)
520 return 0;
521
522 /*
523 * Copy the length of the string in the placeholder.
524 */
525 *newBuffer = len;
526
527 /*
528 * Skip the byte count.
529 */
530 newBuffer++;
531
532 /*
533 * Copy the information in the buffer.
534 * Since it is valid to pass a NULL pointer here, we'll initialize the
535 * buffer to nul if it is the case.
536 */
537 if (in != 0)
538 memcpy(newBuffer, in, len);
539
540 /*
541 * Make sure that there is a nul character at the end of the
542 * string.
543 */
544 stringBuffer = (char *)newBuffer;
545 stringBuffer[len] = 0;
546 stringBuffer[len+1] = 0;
547
548 return (LPWSTR)stringBuffer;
549}
550
551
Note: See TracBrowser for help on using the repository browser.