4 * Copyright 1999, 2000 Marcus Meissner
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.
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.
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
32 #include "wine/obj_olefont.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(ole);
40 /* The OLE Automation ProxyStub Interface Class (aka Typelib Marshaler) */
41 extern const GUID CLSID_PSOAInterface;
43 /* IDispatch marshaler */
44 extern const GUID CLSID_PSDispatch;
46 /******************************************************************************
47 * SysStringLen [OLEAUT32.7]
49 * The Windows documentation states that the length returned by this function
50 * is not necessarely the same as the length returned by the _lstrlenW method.
51 * It is the same number that was passed in as the "len" parameter if the
52 * string was allocated with a SysAllocStringLen method call.
54 int WINAPI SysStringLen(BSTR str)
60 * The length of the string (in bytes) is contained in a DWORD placed
61 * just before the BSTR pointer
63 bufferPointer = (DWORD*)str;
67 return (int)(*bufferPointer/sizeof(WCHAR));
70 /******************************************************************************
71 * SysStringByteLen [OLEAUT32.149]
73 * The Windows documentation states that the length returned by this function
74 * is not necessarely the same as the length returned by the _lstrlenW method.
75 * It is the same number that was passed in as the "len" parameter if the
76 * string was allocated with a SysAllocStringLen method call.
78 int WINAPI SysStringByteLen(BSTR str)
84 * The length of the string (in bytes) is contained in a DWORD placed
85 * just before the BSTR pointer
87 bufferPointer = (DWORD*)str;
91 return (int)(*bufferPointer);
94 /******************************************************************************
95 * SysAllocString [OLEAUT32.2]
97 * MSDN (October 2001) states that this returns a NULL value if the argument
98 * is a zero-length string. This does not appear to be true; certainly it
99 * returns a value under Win98 (Oleaut32.dll Ver 2.40.4515.0)
101 BSTR WINAPI SysAllocString(LPCOLESTR in)
105 /* Delegate this to the SysAllocStringLen32 method. */
106 return SysAllocStringLen(in, lstrlenW(in));
109 /******************************************************************************
110 * SysFreeString [OLEAUT32.6]
112 void WINAPI SysFreeString(BSTR in)
114 DWORD* bufferPointer;
116 /* NULL is a valid parameter */
120 * We have to be careful when we free a BSTR pointer, it points to
121 * the beginning of the string but it skips the byte count contained
124 bufferPointer = (DWORD*)in;
129 * Free the memory from its "real" origin.
131 HeapFree(GetProcessHeap(), 0, bufferPointer);
134 /******************************************************************************
135 * SysAllocStringLen [OLEAUT32.4]
137 * In "Inside OLE, second edition" by Kraig Brockshmidt. In the Automation
138 * section, he describes the DWORD value placed *before* the BSTR data type.
139 * he describes it as a "DWORD count of characters". By experimenting with
140 * a windows application, this count seems to be a DWORD count of bytes in
141 * the string. Meaning that the count is double the number of wide
142 * characters in the string.
144 BSTR WINAPI SysAllocStringLen(const OLECHAR *in, unsigned int len)
151 * Find the length of the buffer passed-in in bytes.
153 bufferSize = len * sizeof (WCHAR);
156 * Allocate a new buffer to hold the string.
157 * dont't forget to keep an empty spot at the beginning of the
158 * buffer for the character count and an extra character at the
161 newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
163 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
166 * If the memory allocation failed, return a null pointer.
172 * Copy the length of the string in the placeholder.
174 *newBuffer = bufferSize;
177 * Skip the byte count.
182 * Copy the information in the buffer.
183 * Since it is valid to pass a NULL pointer here, we'll initialize the
184 * buffer to nul if it is the case.
187 memcpy(newBuffer, in, bufferSize);
189 memset(newBuffer, 0, bufferSize);
192 * Make sure that there is a nul character at the end of the
195 stringBuffer = (WCHAR*)newBuffer;
196 stringBuffer[len] = L'\0';
198 return (LPWSTR)stringBuffer;
201 /******************************************************************************
202 * SysReAllocStringLen [OLEAUT32.5]
204 int WINAPI SysReAllocStringLen(BSTR* old, const OLECHAR* in, unsigned int len)
213 DWORD newbytelen = len*sizeof(WCHAR);
214 DWORD *ptr = HeapReAlloc(GetProcessHeap(),0,((DWORD*)*old)-1,newbytelen+sizeof(WCHAR)+sizeof(DWORD));
215 *old = (BSTR)(ptr+1);
218 memcpy(*old, in, newbytelen);
221 /* Subtle hidden feature: The old string data is still there
223 * Some Microsoft program needs it.
228 * Allocate the new string
230 *old = SysAllocStringLen(in, len);
236 /******************************************************************************
237 * SysAllocStringByteLen [OLEAUT32.150]
240 BSTR WINAPI SysAllocStringByteLen(LPCSTR in, UINT len)
246 * Allocate a new buffer to hold the string.
247 * dont't forget to keep an empty spot at the beginning of the
248 * buffer for the character count and an extra character at the
251 newBuffer = (DWORD*)HeapAlloc(GetProcessHeap(),
253 len + sizeof(WCHAR) + sizeof(DWORD));
256 * If the memory allocation failed, return a null pointer.
262 * Copy the length of the string in the placeholder.
267 * Skip the byte count.
272 * Copy the information in the buffer.
273 * Since it is valid to pass a NULL pointer here, we'll initialize the
274 * buffer to nul if it is the case.
277 memcpy(newBuffer, in, len);
280 * Make sure that there is a nul character at the end of the
283 stringBuffer = (char *)newBuffer;
284 stringBuffer[len] = 0;
285 stringBuffer[len+1] = 0;
287 return (LPWSTR)stringBuffer;
290 /******************************************************************************
291 * SysReAllocString [OLEAUT32.3]
293 INT WINAPI SysReAllocString(LPBSTR old,LPCOLESTR in)
302 * Make sure we free the old string.
308 * Allocate the new string
310 *old = SysAllocString(in);
315 static WCHAR _delimiter[2] = {'!',0}; /* default delimiter apparently */
316 static WCHAR *pdelimiter = &_delimiter[0];
318 /***********************************************************************
319 * RegisterActiveObject (OLEAUT32.33)
321 HRESULT WINAPI RegisterActiveObject(
322 LPUNKNOWN punk,REFCLSID rcid,DWORD dwFlags,LPDWORD pdwRegister
326 LPRUNNINGOBJECTTABLE runobtable;
329 StringFromGUID2(rcid,guidbuf,39);
330 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
333 ret = GetRunningObjectTable(0,&runobtable);
335 IMoniker_Release(moniker);
338 ret = IRunningObjectTable_Register(runobtable,dwFlags,punk,moniker,pdwRegister);
339 IRunningObjectTable_Release(runobtable);
340 IMoniker_Release(moniker);
344 /***********************************************************************
345 * RevokeActiveObject (OLEAUT32.34)
347 HRESULT WINAPI RevokeActiveObject(DWORD xregister,LPVOID reserved)
349 LPRUNNINGOBJECTTABLE runobtable;
352 ret = GetRunningObjectTable(0,&runobtable);
353 if (FAILED(ret)) return ret;
354 ret = IRunningObjectTable_Revoke(runobtable,xregister);
355 if (SUCCEEDED(ret)) ret = S_OK;
356 IRunningObjectTable_Release(runobtable);
360 /***********************************************************************
361 * GetActiveObject (OLEAUT32.35)
363 HRESULT WINAPI GetActiveObject(REFCLSID rcid,LPVOID preserved,LPUNKNOWN *ppunk)
367 LPRUNNINGOBJECTTABLE runobtable;
370 StringFromGUID2(rcid,guidbuf,39);
371 ret = CreateItemMoniker(pdelimiter,guidbuf,&moniker);
374 ret = GetRunningObjectTable(0,&runobtable);
376 IMoniker_Release(moniker);
379 ret = IRunningObjectTable_GetObject(runobtable,moniker,ppunk);
380 IRunningObjectTable_Release(runobtable);
381 IMoniker_Release(moniker);
386 /***********************************************************************
387 * OaBuildVersion [OLEAUT32.170]
389 * known OLEAUT32.DLL versions:
390 * OLE 2.1 NT 1993-95 10 3023
392 * Win32s 1.1e 20 4049
393 * OLE 2.20 W95/NT 1993-96 20 4112
394 * OLE 2.20 W95/NT 1993-96 20 4118
395 * OLE 2.20 W95/NT 1993-96 20 4122
396 * OLE 2.30 W95/NT 1993-98 30 4265
397 * OLE 2.40 NT?? 1993-98 40 4267
398 * OLE 2.40 W98 SE orig. file 1993-98 40 4275
399 * OLE 2.40 W2K orig. file 1993-XX 40 4514
401 * I just decided to use version 2.20 for Win3.1, 2.30 for Win95 & NT 3.51,
402 * and 2.40 for all newer OSs. The build number is maximum, i.e. 0xffff.
404 UINT WINAPI OaBuildVersion()
406 switch(GetVersion() & 0x8000ffff) /* mask off build number */
408 case 0x80000a03: /* WIN31 */
409 return MAKELONG(0xffff, 20);
410 case 0x00003303: /* NT351 */
411 return MAKELONG(0xffff, 30);
412 case 0x80000004: /* WIN95; I'd like to use the "standard" w95 minor
413 version here (30), but as we still use w95
414 as default winver (which is good IMHO), I better
415 play safe and use the latest value for w95 for now.
416 Change this as soon as default winver gets changed
417 to something more recent */
418 case 0x80000a04: /* WIN98 */
419 case 0x00000004: /* NT40 */
420 case 0x00000005: /* W2K */
421 return MAKELONG(0xffff, 40);
423 ERR("Version value not known yet. Please investigate it !\n");
428 /******************************************************************************
429 * OleTranslateColor [OLEAUT32.421]
431 * Converts an OLE_COLOR to a COLORREF.
432 * See the documentation for conversion rules.
433 * pColorRef can be NULL. In that case the user only wants to test the
436 HRESULT WINAPI OleTranslateColor(
442 BYTE b = HIBYTE(HIWORD(clr));
444 TRACE("(%08lx, %p, %p):stub\n", clr, hpal, pColorRef);
447 * In case pColorRef is NULL, provide our own to simplify the code.
449 if (pColorRef == NULL)
450 pColorRef = &colorref;
457 *pColorRef = PALETTERGB(GetRValue(clr),
472 * Validate the palette index.
474 if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
489 int index = LOBYTE(LOWORD(clr));
492 * Validate GetSysColor index.
494 if ((index < COLOR_SCROLLBAR) || (index > COLOR_GRADIENTINACTIVECAPTION))
497 *pColorRef = GetSysColor(index);
509 /***********************************************************************
510 * DllRegisterServer (OLEAUT32.320)
512 HRESULT WINAPI OLEAUT32_DllRegisterServer() {
517 /***********************************************************************
518 * DllUnregisterServer (OLEAUT32.321)
520 HRESULT WINAPI OLEAUT32_DllUnregisterServer() {
525 extern HRESULT OLEAUTPS_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv);
527 extern void _get_STDFONT_CF(LPVOID);
528 extern void _get_STDPIC_CF(LPVOID);
530 /***********************************************************************
531 * DllGetClassObject (OLEAUT32.1)
533 HRESULT WINAPI OLEAUT32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
536 if (IsEqualGUID(rclsid,&CLSID_StdFont)) {
537 if (IsEqualGUID(iid,&IID_IClassFactory)) {
538 _get_STDFONT_CF(ppv);
539 IClassFactory_AddRef((IClassFactory*)*ppv);
543 if (IsEqualGUID(rclsid,&CLSID_StdPicture)) {
544 if (IsEqualGUID(iid,&IID_IClassFactory)) {
546 IClassFactory_AddRef((IClassFactory*)*ppv);
550 if (IsEqualGUID(rclsid,&CLSID_PSDispatch)) {
551 return OLEAUTPS_DllGetClassObject(rclsid,iid,ppv);
553 if (IsEqualGUID(rclsid,&CLSID_PSOAInterface)) {
554 if (S_OK==TypeLibFac_DllGetClassObject(rclsid,iid,ppv))
558 FIXME("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
559 return CLASS_E_CLASSNOTAVAILABLE;
562 /***********************************************************************
563 * DllCanUnloadNow (OLEAUT32.410)
565 HRESULT WINAPI OLEAUT32_DllCanUnloadNow() {
566 FIXME("(), stub!\n");