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