Fixed some deadlocks.
[wine] / dlls / quartz / main.c
1 /*
2  * Exported APIs.
3  *
4  * hidenori@a2.ctktv.ne.jp
5  */
6
7 #include "config.h"
8
9 #include "windef.h"
10 #include "winerror.h"
11 #include "winbase.h"
12 #include "wingdi.h"
13 #include "winuser.h"
14 #include "winnls.h"
15 #include "mmsystem.h"
16 #include "ole2.h"
17 #include "strmif.h"
18 #include "control.h"
19 #include "uuids.h"
20 #include "errors.h"
21
22 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(quartz);
24
25 #include "initguid.h"
26
27 #include "quartz_private.h"
28 #include "fgraph.h"
29 #include "sysclock.h"
30 #include "memalloc.h"
31 #include "devenum.h"
32 #include "fmap.h"
33 #include "seekpass.h"
34 #include "audren.h"
35 #include "vidren.h"
36 #include "parser.h"
37 #include "asyncsrc.h"
38 #include "xform.h"
39
40
41 typedef struct QUARTZ_CLASSENTRY
42 {
43         const CLSID*    pclsid;
44         QUARTZ_pCreateIUnknown  pCreateIUnk;
45 } QUARTZ_CLASSENTRY;
46
47
48 static HRESULT WINAPI
49 IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
50 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
51 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
52 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
53 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
54
55 static ICOM_VTABLE(IClassFactory) iclassfact =
56 {
57         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
58         IClassFactory_fnQueryInterface,
59         IClassFactory_fnAddRef,
60         IClassFactory_fnRelease,
61         IClassFactory_fnCreateInstance,
62         IClassFactory_fnLockServer
63 };
64
65 typedef struct
66 {
67         /* IUnknown fields */
68         ICOM_VFIELD(IClassFactory);
69         LONG    ref;
70         /* IClassFactory fields */
71         const QUARTZ_CLASSENTRY* pEntry;
72 } IClassFactoryImpl;
73
74 static const QUARTZ_CLASSENTRY QUARTZ_ClassList[] =
75 {
76         { &CLSID_FilterGraph, &QUARTZ_CreateFilterGraph },
77         { &CLSID_SystemClock, &QUARTZ_CreateSystemClock },
78         { &CLSID_MemoryAllocator, &QUARTZ_CreateMemoryAllocator },
79         { &CLSID_SystemDeviceEnum, &QUARTZ_CreateSystemDeviceEnum },
80         { &CLSID_FilterMapper, &QUARTZ_CreateFilterMapper },
81         { &CLSID_FilterMapper2, &QUARTZ_CreateFilterMapper2 },
82         { &CLSID_SeekingPassThru, &QUARTZ_CreateSeekingPassThru },
83         { &CLSID_AudioRender, &QUARTZ_CreateAudioRenderer },
84         { &CLSID_VideoRenderer, &QUARTZ_CreateVideoRenderer },
85         { &CLSID_quartzWaveParser, &QUARTZ_CreateWaveParser },
86         { &CLSID_AviSplitter, &QUARTZ_CreateAVISplitter },
87         { &CLSID_AsyncReader, &QUARTZ_CreateAsyncReader },
88         { &CLSID_URLReader, &QUARTZ_CreateURLReader },
89         { &CLSID_AVIDec, &QUARTZ_CreateAVIDec },
90         { &CLSID_Colour, &QUARTZ_CreateColour },
91         { NULL, NULL },
92 };
93
94 /* per-process variables */
95 static CRITICAL_SECTION csHeap;
96 static DWORD dwClassObjRef;
97 static HANDLE hDLLHeap;
98
99 void* QUARTZ_AllocObj( DWORD dwSize )
100 {
101         void*   pv;
102
103         EnterCriticalSection( &csHeap );
104         dwClassObjRef ++;
105         pv = HeapAlloc( hDLLHeap, 0, dwSize );
106         if ( pv == NULL )
107                 dwClassObjRef --;
108         LeaveCriticalSection( &csHeap );
109
110         return pv;
111 }
112
113 void QUARTZ_FreeObj( void* pobj )
114 {
115         EnterCriticalSection( &csHeap );
116         HeapFree( hDLLHeap, 0, pobj );
117         dwClassObjRef --;
118         LeaveCriticalSection( &csHeap );
119 }
120
121 void* QUARTZ_AllocMem( DWORD dwSize )
122 {
123         return HeapAlloc( hDLLHeap, 0, dwSize );
124 }
125
126 void QUARTZ_FreeMem( void* pMem )
127 {
128         HeapFree( hDLLHeap, 0, pMem );
129 }
130
131 void* QUARTZ_ReallocMem( void* pMem, DWORD dwSize )
132 {
133         if ( pMem == NULL )
134                 return QUARTZ_AllocMem( dwSize );
135
136         return HeapReAlloc( hDLLHeap, 0, pMem, dwSize );
137 }
138
139 static
140 LPWSTR QUARTZ_strncpyAtoW( LPWSTR lpwstr, LPCSTR lpstr, INT wbuflen )
141 {
142         INT     len;
143
144         len = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, lpwstr, wbuflen );
145         if ( len == 0 )
146                 *lpwstr = 0;
147         return lpwstr;
148 }
149
150
151 /************************************************************************/
152
153 static HRESULT WINAPI
154 IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
155 {
156         ICOM_THIS(IClassFactoryImpl,iface);
157
158         TRACE("(%p)->(%p,%p)\n",This,riid,ppobj);
159         if ( ( IsEqualGUID( &IID_IUnknown, riid ) ) ||
160              ( IsEqualGUID( &IID_IClassFactory, riid ) ) )
161         {
162                 *ppobj = iface;
163                 IClassFactory_AddRef(iface);
164                 return S_OK;
165         }
166
167         return E_NOINTERFACE;
168 }
169
170 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
171 {
172         ICOM_THIS(IClassFactoryImpl,iface);
173
174         TRACE("(%p)->()\n",This);
175
176         return InterlockedExchangeAdd(&(This->ref),1) + 1;
177 }
178
179 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
180 {
181         ICOM_THIS(IClassFactoryImpl,iface);
182         LONG    ref;
183
184         TRACE("(%p)->()\n",This);
185         ref = InterlockedExchangeAdd(&(This->ref),-1) - 1;
186         if ( ref > 0 )
187                 return (ULONG)ref;
188
189         QUARTZ_FreeObj(This);
190         return 0;
191 }
192
193 static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj)
194 {
195         ICOM_THIS(IClassFactoryImpl,iface);
196         HRESULT hr;
197         IUnknown*       punk;
198
199         TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
200
201         if ( ppobj == NULL )
202                 return E_POINTER;
203         if ( pOuter != NULL && !IsEqualGUID( riid, &IID_IUnknown ) )
204                 return CLASS_E_NOAGGREGATION;
205
206         *ppobj = NULL;
207
208         hr = (*This->pEntry->pCreateIUnk)(pOuter,(void**)&punk);
209         if ( hr != S_OK )
210                 return hr;
211
212         hr = IUnknown_QueryInterface(punk,riid,ppobj);
213         IUnknown_Release(punk);
214
215         return hr;
216 }
217
218 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
219 {
220         ICOM_THIS(IClassFactoryImpl,iface);
221         HRESULT hr;
222
223         TRACE("(%p)->(%d)\n",This,dolock);
224         if (dolock)
225                 hr = IClassFactory_AddRef(iface);
226         else
227                 hr = IClassFactory_Release(iface);
228
229         return hr;
230 }
231
232
233
234 static HRESULT IClassFactory_Alloc( const CLSID* pclsid, void** ppobj )
235 {
236         const QUARTZ_CLASSENTRY*        pEntry;
237         IClassFactoryImpl*      pImpl;
238
239         TRACE( "(%s,%p)\n", debugstr_guid(pclsid), ppobj );
240
241         pEntry = QUARTZ_ClassList;
242         while ( pEntry->pclsid != NULL )
243         {
244                 if ( IsEqualGUID( pclsid, pEntry->pclsid ) )
245                         goto found;
246                 pEntry ++;
247         }
248
249         return CLASS_E_CLASSNOTAVAILABLE;
250 found:
251         pImpl = (IClassFactoryImpl*)QUARTZ_AllocObj( sizeof(IClassFactoryImpl) );
252         if ( pImpl == NULL )
253                 return E_OUTOFMEMORY;
254
255         TRACE( "allocated successfully.\n" );
256
257         ICOM_VTBL(pImpl) = &iclassfact;
258         pImpl->ref = 1;
259         pImpl->pEntry = pEntry;
260
261         *ppobj = (void*)pImpl;
262         return S_OK;
263 }
264
265
266 /***********************************************************************
267  *              QUARTZ_InitProcess (internal)
268  */
269 static BOOL QUARTZ_InitProcess( void )
270 {
271         TRACE("()\n");
272
273         dwClassObjRef = 0;
274         hDLLHeap = (HANDLE)NULL;
275         InitializeCriticalSection( &csHeap );
276
277         hDLLHeap = HeapCreate( 0, 0x10000, 0 );
278         if ( hDLLHeap == (HANDLE)NULL )
279                 return FALSE;
280
281         return TRUE;
282 }
283
284 /***********************************************************************
285  *              QUARTZ_UninitProcess (internal)
286  */
287 static void QUARTZ_UninitProcess( void )
288 {
289         TRACE("()\n");
290
291         if ( dwClassObjRef != 0 )
292                 ERR( "you must release some objects allocated from quartz.\n" );
293         if ( hDLLHeap != (HANDLE)NULL )
294         {
295                 HeapDestroy( hDLLHeap );
296                 hDLLHeap = (HANDLE)NULL;
297         }
298         DeleteCriticalSection( &csHeap );
299 }
300
301 /***********************************************************************
302  *              QUARTZ_DllMain
303  */
304 BOOL WINAPI QUARTZ_DllMain(
305         HINSTANCE hInstDLL,
306         DWORD fdwReason,
307         LPVOID lpvReserved )
308 {
309         TRACE("(%08x,%08lx,%p)\n",hInstDLL,fdwReason,lpvReserved);
310
311         switch ( fdwReason )
312         {
313         case DLL_PROCESS_ATTACH:
314                 if ( !QUARTZ_InitProcess() )
315                         return FALSE;
316                 break;
317         case DLL_PROCESS_DETACH:
318                 QUARTZ_UninitProcess();
319                 break;
320         case DLL_THREAD_ATTACH:
321                 break;
322         case DLL_THREAD_DETACH:
323                 break;
324         }
325
326         return TRUE;
327 }
328
329
330 /***********************************************************************
331  *              DllCanUnloadNow (QUARTZ.@)
332  *
333  * RETURNS
334  *    Success: S_OK
335  *    Failure: S_FALSE
336  */
337 HRESULT WINAPI QUARTZ_DllCanUnloadNow(void)
338 {
339         HRESULT hr;
340
341         EnterCriticalSection( &csHeap );
342         hr = ( dwClassObjRef == 0 ) ? S_OK : S_FALSE;
343         LeaveCriticalSection( &csHeap );
344
345         return hr;
346 }
347
348 /***********************************************************************
349  *              DllGetClassObject (QUARTZ.@)
350  */
351 HRESULT WINAPI QUARTZ_DllGetClassObject(
352                 const CLSID* pclsid,const IID* piid,void** ppv)
353 {
354         *ppv = NULL;
355         if ( IsEqualCLSID( &IID_IUnknown, piid ) ||
356              IsEqualCLSID( &IID_IClassFactory, piid ) )
357         {
358                 return IClassFactory_Alloc( pclsid, ppv );
359         }
360
361         return CLASS_E_CLASSNOTAVAILABLE;
362 }
363
364 /***********************************************************************
365  *              DllRegisterServer (QUARTZ.@)
366  */
367
368 HRESULT WINAPI QUARTZ_DllRegisterServer( void )
369 {
370         FIXME( "(): stub\n" );
371         return E_FAIL;
372 }
373
374 /***********************************************************************
375  *              DllUnregisterServer (QUARTZ.@)
376  */
377
378 HRESULT WINAPI QUARTZ_DllUnregisterServer( void )
379 {
380         FIXME( "(): stub\n" );
381         return E_FAIL;
382 }
383
384 /**************************************************************************/
385 /**************************************************************************/
386
387 /* FIXME - all string should be defined in the resource of quartz. */
388
389 static LPCSTR hresult_to_string( HRESULT hr )
390 {
391         switch ( hr )
392         {
393         #define ENTRY(x)        case x: return (const char*)#x
394         /* some known codes */
395         ENTRY(S_OK);
396         ENTRY(S_FALSE);
397         ENTRY(E_FAIL);
398         ENTRY(E_POINTER);
399         ENTRY(E_NOTIMPL);
400         ENTRY(E_NOINTERFACE);
401         ENTRY(E_OUTOFMEMORY);
402         ENTRY(CLASS_E_CLASSNOTAVAILABLE);
403         ENTRY(CLASS_E_NOAGGREGATION);
404
405         /* vfwmsgs.h */
406         ENTRY(VFW_S_NO_MORE_ITEMS);
407         ENTRY(VFW_E_BAD_KEY);
408         ENTRY(VFW_E_INVALIDMEDIATYPE);
409         ENTRY(VFW_E_INVALIDSUBTYPE);
410         ENTRY(VFW_E_NEED_OWNER);
411         ENTRY(VFW_E_ENUM_OUT_OF_SYNC);
412         ENTRY(VFW_E_ALREADY_CONNECTED);
413         ENTRY(VFW_E_FILTER_ACTIVE);
414         ENTRY(VFW_E_NO_TYPES);
415         ENTRY(VFW_E_NO_ACCEPTABLE_TYPES);
416         ENTRY(VFW_E_INVALID_DIRECTION);
417         ENTRY(VFW_E_NOT_CONNECTED);
418         ENTRY(VFW_E_NO_ALLOCATOR);
419         ENTRY(VFW_E_RUNTIME_ERROR);
420         ENTRY(VFW_E_BUFFER_NOTSET);
421         ENTRY(VFW_E_BUFFER_OVERFLOW);
422         ENTRY(VFW_E_BADALIGN);
423         ENTRY(VFW_E_ALREADY_COMMITTED);
424         ENTRY(VFW_E_BUFFERS_OUTSTANDING);
425         ENTRY(VFW_E_NOT_COMMITTED);
426         ENTRY(VFW_E_SIZENOTSET);
427         ENTRY(VFW_E_NO_CLOCK);
428         ENTRY(VFW_E_NO_SINK);
429         ENTRY(VFW_E_NO_INTERFACE);
430         ENTRY(VFW_E_NOT_FOUND);
431         ENTRY(VFW_E_CANNOT_CONNECT);
432         ENTRY(VFW_E_CANNOT_RENDER);
433         ENTRY(VFW_E_CHANGING_FORMAT);
434         ENTRY(VFW_E_NO_COLOR_KEY_SET);
435         ENTRY(VFW_E_NOT_OVERLAY_CONNECTION);
436         ENTRY(VFW_E_NOT_SAMPLE_CONNECTION);
437         ENTRY(VFW_E_PALETTE_SET);
438         ENTRY(VFW_E_COLOR_KEY_SET);
439         ENTRY(VFW_E_NO_COLOR_KEY_FOUND);
440         ENTRY(VFW_E_NO_PALETTE_AVAILABLE);
441         ENTRY(VFW_E_NO_DISPLAY_PALETTE);
442         ENTRY(VFW_E_TOO_MANY_COLORS);
443         ENTRY(VFW_E_STATE_CHANGED);
444         ENTRY(VFW_E_NOT_STOPPED);
445         ENTRY(VFW_E_NOT_PAUSED);
446         ENTRY(VFW_E_NOT_RUNNING);
447         ENTRY(VFW_E_WRONG_STATE);
448         ENTRY(VFW_E_START_TIME_AFTER_END);
449         ENTRY(VFW_E_INVALID_RECT);
450         ENTRY(VFW_E_TYPE_NOT_ACCEPTED);
451         ENTRY(VFW_E_SAMPLE_REJECTED);
452         ENTRY(VFW_E_SAMPLE_REJECTED_EOS);
453         ENTRY(VFW_S_DUPLICATE_NAME);
454         ENTRY(VFW_E_DUPLICATE_NAME);
455         ENTRY(VFW_E_TIMEOUT);
456         ENTRY(VFW_E_INVALID_FILE_FORMAT);
457         ENTRY(VFW_E_ENUM_OUT_OF_RANGE);
458         ENTRY(VFW_E_CIRCULAR_GRAPH);
459         ENTRY(VFW_E_NOT_ALLOWED_TO_SAVE);
460         ENTRY(VFW_E_TIME_ALREADY_PASSED);
461         ENTRY(VFW_E_ALREADY_CANCELLED);
462         ENTRY(VFW_E_CORRUPT_GRAPH_FILE);
463         ENTRY(VFW_E_ADVISE_ALREADY_SET);
464         ENTRY(VFW_S_STATE_INTERMEDIATE);
465         ENTRY(VFW_E_NO_MODEX_AVAILABLE);
466         ENTRY(VFW_E_NO_ADVISE_SET);
467         ENTRY(VFW_E_NO_FULLSCREEN);
468         ENTRY(VFW_E_IN_FULLSCREEN_MODE);
469         ENTRY(VFW_E_UNKNOWN_FILE_TYPE);
470         ENTRY(VFW_E_CANNOT_LOAD_SOURCE_FILTER);
471         ENTRY(VFW_S_PARTIAL_RENDER);
472         ENTRY(VFW_E_FILE_TOO_SHORT);
473         ENTRY(VFW_E_INVALID_FILE_VERSION);
474         ENTRY(VFW_S_SOME_DATA_IGNORED);
475         ENTRY(VFW_S_CONNECTIONS_DEFERRED);
476         ENTRY(VFW_E_INVALID_CLSID);
477         ENTRY(VFW_E_INVALID_MEDIA_TYPE);
478         ENTRY(VFW_E_SAMPLE_TIME_NOT_SET);
479         ENTRY(VFW_S_RESOURCE_NOT_NEEDED);
480         ENTRY(VFW_E_MEDIA_TIME_NOT_SET);
481         ENTRY(VFW_E_NO_TIME_FORMAT_SET);
482         ENTRY(VFW_E_MONO_AUDIO_HW);
483         ENTRY(VFW_S_MEDIA_TYPE_IGNORED);
484         ENTRY(VFW_E_NO_DECOMPRESSOR);
485         ENTRY(VFW_E_NO_AUDIO_HARDWARE);
486         ENTRY(VFW_S_VIDEO_NOT_RENDERED);
487         ENTRY(VFW_S_AUDIO_NOT_RENDERED);
488         ENTRY(VFW_E_RPZA);
489         ENTRY(VFW_S_RPZA);
490         ENTRY(VFW_E_PROCESSOR_NOT_SUITABLE);
491         ENTRY(VFW_E_UNSUPPORTED_AUDIO);
492         ENTRY(VFW_E_UNSUPPORTED_VIDEO);
493         ENTRY(VFW_E_MPEG_NOT_CONSTRAINED);
494         ENTRY(VFW_E_NOT_IN_GRAPH);
495         ENTRY(VFW_S_ESTIMATED);
496         ENTRY(VFW_E_NO_TIME_FORMAT);
497         ENTRY(VFW_E_READ_ONLY);
498         ENTRY(VFW_S_RESERVED);
499         ENTRY(VFW_E_BUFFER_UNDERFLOW);
500         ENTRY(VFW_E_UNSUPPORTED_STREAM);
501         ENTRY(VFW_E_NO_TRANSPORT);
502         ENTRY(VFW_S_STREAM_OFF);
503         ENTRY(VFW_S_CANT_CUE);
504         ENTRY(VFW_E_BAD_VIDEOCD);
505         ENTRY(VFW_S_NO_STOP_TIME);
506         ENTRY(VFW_E_OUT_OF_VIDEO_MEMORY);
507         ENTRY(VFW_E_VP_NEGOTIATION_FAILED);
508         ENTRY(VFW_E_DDRAW_CAPS_NOT_SUITABLE);
509         ENTRY(VFW_E_NO_VP_HARDWARE);
510         ENTRY(VFW_E_NO_CAPTURE_HARDWARE);
511         ENTRY(VFW_E_DVD_OPERATION_INHIBITED);
512         ENTRY(VFW_E_DVD_INVALIDDOMAIN);
513         ENTRY(VFW_E_DVD_NO_BUTTON);
514         ENTRY(VFW_E_DVD_GRAPHNOTREADY);
515         ENTRY(VFW_E_DVD_RENDERFAIL);
516         ENTRY(VFW_E_DVD_DECNOTENOUGH);
517         ENTRY(VFW_E_DDRAW_VERSION_NOT_SUITABLE);
518         ENTRY(VFW_E_COPYPROT_FAILED);
519         ENTRY(VFW_S_NOPREVIEWPIN);
520         ENTRY(VFW_E_TIME_EXPIRED);
521         ENTRY(VFW_S_DVD_NON_ONE_SEQUENTIAL);
522         ENTRY(VFW_E_DVD_WRONG_SPEED);
523         ENTRY(VFW_E_DVD_MENU_DOES_NOT_EXIST);
524         ENTRY(VFW_E_DVD_CMD_CANCELLED);
525         ENTRY(VFW_E_DVD_STATE_WRONG_VERSION);
526         ENTRY(VFW_E_DVD_STATE_CORRUPT);
527         ENTRY(VFW_E_DVD_STATE_WRONG_DISC);
528         ENTRY(VFW_E_DVD_INCOMPATIBLE_REGION);
529         ENTRY(VFW_E_DVD_NO_ATTRIBUTES);
530         ENTRY(VFW_E_DVD_NO_GOUP_PGC);
531         ENTRY(VFW_E_DVD_LOW_PARENTAL_LEVEL);
532         ENTRY(VFW_E_DVD_NOT_IN_KARAOKE_MODE);
533         ENTRY(VFW_S_DVD_CHANNEL_CONTENTS_NOT_AVAILABLE);
534         ENTRY(VFW_S_DVD_NOT_ACCURATE);
535         ENTRY(VFW_E_FRAME_STEP_UNSUPPORTED);
536         ENTRY(VFW_E_DVD_STREAM_DISABLED);
537         ENTRY(VFW_E_DVD_TITLE_UNKNOWN);
538         ENTRY(VFW_E_DVD_INVALID_DISC);
539         ENTRY(VFW_E_DVD_NO_RESUME_INFORMATION);
540         ENTRY(VFW_E_PIN_ALREADY_BLOCKED_ON_THIS_THREAD);
541         ENTRY(VFW_E_PIN_ALREADY_BLOCKED);
542         ENTRY(VFW_E_CERTIFICATION_FAILURE);
543         #undef  ENTRY
544         }
545
546         return NULL;
547 }
548
549 /***********************************************************************
550  *      AMGetErrorTextA (quartz.@)
551  */
552 DWORD WINAPI AMGetErrorTextA(HRESULT hr, LPSTR pszbuf, DWORD dwBufLen)
553 {
554         LPCSTR  lpszRes;
555         DWORD len;
556
557         lpszRes = hresult_to_string( hr );
558         if ( lpszRes == NULL )
559                 return 0;
560         len = (DWORD)(strlen(lpszRes)+1);
561         if ( len > dwBufLen )
562                 return 0;
563
564         memcpy( pszbuf, lpszRes, len );
565         return len;
566 }
567
568 /***********************************************************************
569  *      AMGetErrorTextW (quartz.@)
570  */
571 DWORD WINAPI AMGetErrorTextW(HRESULT hr, LPWSTR pwszbuf, DWORD dwBufLen)
572 {
573         CHAR    szBuf[MAX_ERROR_TEXT_LEN+1];
574         DWORD   dwLen;
575
576         dwLen = AMGetErrorTextA(hr,szBuf,MAX_ERROR_TEXT_LEN);
577         if ( dwLen == 0 )
578                 return 0;
579         szBuf[dwLen] = 0;
580
581         QUARTZ_strncpyAtoW( pwszbuf, szBuf, dwBufLen );
582
583         return lstrlenW( pwszbuf );
584 }