]> git.sesse.net Git - vlc/blob - projects/activex/vlccontrol.cpp
a7634eb4a3b03e7a96f8dde22aa7ff4a838e3fb7
[vlc] / projects / activex / vlccontrol.cpp
1 /*****************************************************************************
2  * vlccontrol.cpp: ActiveX control for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  *
6  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
7  *          Jean-Paul Saman <jpsaman@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "plugin.h"
25 #include "vlccontrol.h"
26
27 #include "utils.h"
28
29 using namespace std;
30
31 VLCControl::~VLCControl()
32 {
33     if( _p_typeinfo )
34         _p_typeinfo->Release();
35 };
36
37 HRESULT VLCControl::getTypeInfo(void)
38 {
39     HRESULT hr = NOERROR;
40     if( NULL == _p_typeinfo )
41     {
42         ITypeLib *p_typelib;
43
44         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
45         if( SUCCEEDED(hr) )
46         {
47             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl, &_p_typeinfo);
48             if( FAILED(hr) )
49             {
50                 _p_typeinfo = NULL;
51             }
52             p_typelib->Release();
53         }
54     }
55     return hr;
56 };
57
58 STDMETHODIMP VLCControl::GetTypeInfoCount(UINT* pctInfo)
59 {
60     if( NULL == pctInfo )
61         return E_INVALIDARG;
62
63     if( SUCCEEDED(getTypeInfo()) )
64         *pctInfo = 1;
65     else
66         *pctInfo = 0;
67
68     return NOERROR;
69 };
70
71 STDMETHODIMP VLCControl::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
72 {
73     if( NULL == ppTInfo )
74         return E_INVALIDARG;
75
76     if( SUCCEEDED(getTypeInfo()) )
77     {
78         _p_typeinfo->AddRef();
79         *ppTInfo = _p_typeinfo;
80         return NOERROR;
81     }
82     *ppTInfo = NULL;
83     return E_NOTIMPL;
84 };
85
86 STDMETHODIMP VLCControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
87         UINT cNames, LCID lcid, DISPID* rgDispID)
88 {
89     if( SUCCEEDED(getTypeInfo()) )
90     {
91         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
92     }
93     return E_NOTIMPL;
94 };
95
96 STDMETHODIMP VLCControl::Invoke(DISPID dispIdMember, REFIID riid,
97         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
98         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
99 {
100     if( SUCCEEDED(getTypeInfo()) )
101     {
102         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
103                 pVarResult, pExcepInfo, puArgErr);
104     }
105     return E_NOTIMPL;
106 };
107
108 STDMETHODIMP VLCControl::get_Visible(VARIANT_BOOL *isVisible)
109 {
110     if( NULL == isVisible )
111         return E_POINTER;
112
113     *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
114
115     return NOERROR;
116 };
117
118 STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible)
119 {
120     _p_instance->setVisible(isVisible != VARIANT_FALSE);
121
122     return NOERROR;
123 };
124
125 STDMETHODIMP VLCControl::play(void)
126 {
127     libvlc_exception_t ex;
128     libvlc_exception_init(&ex);
129
130     _p_instance->playlist_play(&ex);
131     HRESULT result = exception_bridge(&ex);
132     if( SUCCEEDED(result) )
133         _p_instance->fireOnPlayEvent();
134     return result;
135 };
136
137 STDMETHODIMP VLCControl::pause(void)
138 {
139     libvlc_media_player_t* p_md;
140     HRESULT result = _p_instance->getMD(&p_md);
141     if( SUCCEEDED(result) )
142     {
143         libvlc_exception_t ex;
144         libvlc_exception_init(&ex);
145
146         libvlc_media_player_pause(p_md, &ex);
147         result = exception_bridge(&ex);
148         if( SUCCEEDED(result) )
149             _p_instance->fireOnPauseEvent();
150     }
151     return result;
152 };
153
154 STDMETHODIMP VLCControl::stop(void)
155 {
156     libvlc_media_player_t *p_md;
157     HRESULT result = _p_instance->getMD(&p_md);
158     if( SUCCEEDED(result) )
159     {
160         libvlc_exception_t ex;
161         libvlc_exception_init(&ex);
162
163         libvlc_media_player_stop(p_md);
164         result = exception_bridge(&ex);
165         if( SUCCEEDED(result) )
166             _p_instance->fireOnStopEvent();
167     }
168     return result;
169 };
170
171 STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
172 {
173     if( NULL == isPlaying )
174         return E_POINTER;
175
176     libvlc_media_player_t *p_md;
177     HRESULT result = _p_instance->getMD(&p_md);
178     if( SUCCEEDED(result) )
179     {
180         *isPlaying = libvlc_media_player_is_playing(p_md) ?
181                      VARIANT_TRUE : VARIANT_FALSE;
182     } else *isPlaying = VARIANT_FALSE;
183     return result;
184 };
185
186 STDMETHODIMP VLCControl::get_Position(float *position)
187 {
188     if( NULL == position )
189         return E_POINTER;
190     *position = 0.0f;
191
192     libvlc_media_player_t *p_md;
193     HRESULT result = _p_instance->getMD(&p_md);
194     if( SUCCEEDED(result) )
195     {
196         libvlc_exception_t ex;
197         libvlc_exception_init(&ex);
198
199         *position = libvlc_media_player_get_position(p_md, &ex);
200         result = exception_bridge(&ex);
201     }
202     return result;
203 };
204
205 STDMETHODIMP VLCControl::put_Position(float position)
206 {
207     libvlc_media_player_t *p_md;
208     HRESULT result = _p_instance->getMD(&p_md);
209     if( SUCCEEDED(result) )
210     {
211         libvlc_exception_t ex;
212         libvlc_exception_init(&ex);
213
214         libvlc_media_player_set_position(p_md, position, &ex);
215         result = exception_bridge(&ex);
216     }
217     return result;
218 };
219
220 STDMETHODIMP VLCControl::get_Time(int *seconds)
221 {
222     if( NULL == seconds )
223         return E_POINTER;
224
225     *seconds = 0;
226     libvlc_media_player_t *p_md;
227     HRESULT result = _p_instance->getMD(&p_md);
228     if( SUCCEEDED(result) )
229     {
230         libvlc_exception_t ex;
231         libvlc_exception_init(&ex);
232
233         *seconds = libvlc_media_player_get_time(p_md, &ex);
234         result = exception_bridge(&ex);
235     }
236     return result;
237 };
238
239 STDMETHODIMP VLCControl::put_Time(int seconds)
240 {
241     /* setTime function of the plugin sets the time. */
242     _p_instance->setTime(seconds);
243     return NOERROR;
244 };
245
246 STDMETHODIMP VLCControl::shuttle(int seconds)
247 {
248     libvlc_media_player_t *p_md;
249     HRESULT result = _p_instance->getMD(&p_md);
250     if( SUCCEEDED(result) )
251     {
252         libvlc_exception_t ex;
253         libvlc_exception_init(&ex);
254
255         if( seconds < 0 ) seconds = 0;
256         libvlc_media_player_set_time(p_md, (int64_t)seconds, &ex);
257         result = exception_bridge(&ex);
258     }
259     return result;
260
261 };
262
263 STDMETHODIMP VLCControl::fullscreen(void)
264 {
265     libvlc_media_player_t *p_md;
266     HRESULT result = _p_instance->getMD(&p_md);
267     if( SUCCEEDED(result) )
268     {
269         if( libvlc_media_player_is_playing(p_md) )
270         {
271             libvlc_toggle_fullscreen(p_md, NULL);
272         }
273     }
274     return result;
275 };
276
277 STDMETHODIMP VLCControl::get_Length(int *seconds)
278 {
279     if( NULL == seconds )
280         return E_POINTER;
281     *seconds = 0;
282
283     libvlc_media_player_t *p_md;
284     HRESULT result = _p_instance->getMD(&p_md);
285     if( SUCCEEDED(result) )
286     {
287         libvlc_exception_t ex;
288         libvlc_exception_init(&ex);
289
290         *seconds = (double)libvlc_media_player_get_length(p_md, &ex);
291         result = exception_bridge(&ex);
292     }
293     return result;
294
295 };
296
297 STDMETHODIMP VLCControl::playFaster(void)
298 {
299     int32_t rate = 2;
300
301     libvlc_media_player_t *p_md;
302     HRESULT result = _p_instance->getMD(&p_md);
303
304     if( SUCCEEDED(result) )
305     {
306         libvlc_exception_t ex;
307         libvlc_exception_init(&ex);
308
309         libvlc_media_player_set_rate(p_md, rate, &ex);
310         result = exception_bridge(&ex);
311     }
312     return result;
313 };
314
315 STDMETHODIMP VLCControl::playSlower(void)
316 {
317     float rate = 0.5;
318
319     libvlc_media_player_t *p_md;
320     HRESULT result = _p_instance->getMD(&p_md);
321     if( SUCCEEDED(result) )
322     {
323         libvlc_exception_t ex;
324         libvlc_exception_init(&ex);
325
326         libvlc_media_player_set_rate(p_md, rate, &ex);
327         result = exception_bridge(&ex);
328     }
329     return result;
330 };
331
332 STDMETHODIMP VLCControl::get_Volume(int *volume)
333 {
334     if( NULL == volume )
335         return E_POINTER;
336
337     *volume  = _p_instance->getVolume();
338     return NOERROR;
339 };
340
341 STDMETHODIMP VLCControl::put_Volume(int volume)
342 {
343     _p_instance->setVolume(volume);
344     return NOERROR;
345 };
346
347 STDMETHODIMP VLCControl::toggleMute(void)
348 {
349     libvlc_instance_t* p_libvlc;
350     HRESULT result = _p_instance->getVLC(&p_libvlc);
351     if( SUCCEEDED(result) )
352         libvlc_audio_toggle_mute(p_libvlc);
353     return result;
354 };
355
356 STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
357 {
358     libvlc_instance_t* p_libvlc;
359     HRESULT result = _p_instance->getVLC(&p_libvlc);
360     if( SUCCEEDED(result) )
361     {
362         _p_instance->setErrorInfo(IID_IVLCControl,
363             "setVariable() is an unsafe interface to use. "
364             "It has been removed because of security implications." );
365     }
366     return E_FAIL;
367 };
368
369 STDMETHODIMP VLCControl::getVariable(BSTR name, VARIANT *value)
370 {
371     libvlc_instance_t* p_libvlc;
372     HRESULT result = _p_instance->getVLC(&p_libvlc);
373     if( SUCCEEDED(result) )
374     {
375         _p_instance->setErrorInfo(IID_IVLCControl,
376             "getVariable() is an unsafe interface to use. "
377             "It has been removed because of security implications." );
378     }
379     return E_FAIL;
380 };
381
382 void VLCControl::FreeTargetOptions(char **cOptions, int cOptionCount)
383 {
384     // clean up
385     if( NULL != cOptions )
386     {
387         for( int pos=0; pos<cOptionCount; ++pos )
388         {
389             char *cOption = cOptions[pos];
390             if( NULL != cOption )
391                 CoTaskMemFree(cOption);
392             else
393                 break;
394         }
395         CoTaskMemFree(cOptions);
396     }
397 };
398
399 static HRESULT parseStringOptions(int codePage, BSTR bstr, char*** cOptions, int *cOptionCount)
400 {
401     HRESULT hr = E_INVALIDARG;
402     if( SysStringLen(bstr) > 0 )
403     {
404         hr = E_OUTOFMEMORY;
405         char *s = CStrFromBSTR(codePage, bstr);
406         char *val = s;
407         if( val )
408         {
409             long capacity = 16;
410             char **options = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
411             if( options )
412             {
413                 int nOptions = 0;
414
415                 char *end = val + strlen(val);
416                 while( val < end )
417                 {
418                     // skip leading blanks
419                     while( (val < end)
420                         && ((*val == ' ' ) || (*val == '\t')) )
421                         ++val;
422
423                     char *start = val;
424                     // skip till we get a blank character
425                     while( (val < end)
426                         && (*val != ' ' )
427                         && (*val != '\t') )
428                     {
429                         char c = *(val++);
430                         if( ('\'' == c) || ('"' == c) )
431                         {
432                             // skip till end of string
433                             while( (val < end) && (*(val++) != c ) );
434                         }
435                     }
436
437                     if( val > start )
438                     {
439                         if( nOptions == capacity )
440                         {
441                             capacity += 16;
442                             char **moreOptions = (char **)CoTaskMemRealloc(options, capacity*sizeof(char*));
443                             if( ! moreOptions )
444                             {
445                                 /* failed to allocate more memory */
446                                 CoTaskMemFree(s);
447                                 /* return what we got so far */
448                                 *cOptionCount = nOptions;
449                                 *cOptions = options;
450                                 return NOERROR;
451                             }
452                             options = moreOptions;
453                         }
454                         *(val++) = '\0';
455                         options[nOptions] = (char *)CoTaskMemAlloc(val-start);
456                         if( options[nOptions] )
457                         {
458                             memcpy(options[nOptions], start, val-start);
459                             ++nOptions;
460                         }
461                         else
462                         {
463                             /* failed to allocate memory */
464                             CoTaskMemFree(s);
465                             /* return what we got so far */
466                             *cOptionCount = nOptions;
467                             *cOptions = options;
468                             return NOERROR;
469                         }
470                     }
471                     else
472                         // must be end of string
473                         break;
474                 }
475                 *cOptionCount = nOptions;
476                 *cOptions = options;
477                 hr = NOERROR;
478             }
479             CoTaskMemFree(s);
480         }
481     }
482     return hr;
483 }
484
485 HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
486 {
487     HRESULT hr = E_INVALIDARG;
488     if( VT_ERROR == V_VT(options) )
489     {
490         if( DISP_E_PARAMNOTFOUND == V_ERROR(options) )
491         {
492             // optional parameter not set
493             *cOptions = NULL;
494             *cOptionCount = 0;
495             return NOERROR;
496         }
497     }
498     else if( (VT_EMPTY == V_VT(options)) || (VT_NULL == V_VT(options)) )
499     {
500         // null parameter
501         *cOptions = NULL;
502         *cOptionCount = 0;
503         return NOERROR;
504     }
505     else if( VT_DISPATCH == V_VT(options) )
506     {
507         // if object is a collection, retrieve enumerator
508         VARIANT colEnum;
509         V_VT(&colEnum) = VT_UNKNOWN;
510         hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
511         if( SUCCEEDED(hr) )
512         {
513             IEnumVARIANT *enumVar;
514             hr = V_UNKNOWN(&colEnum)->QueryInterface(IID_IEnumVARIANT, (LPVOID *)&enumVar);
515             if( SUCCEEDED(hr) )
516             {
517                 long pos = 0;
518                 long capacity = 16;
519                 VARIANT option;
520
521                 *cOptions = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
522                 if( NULL != *cOptions )
523                 {
524                     ZeroMemory(*cOptions, sizeof(char *)*capacity);
525                     while( SUCCEEDED(hr) && (S_OK == enumVar->Next(1, &option, NULL)) )
526                     {
527                         if( VT_BSTR == V_VT(&option) )
528                         {
529                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
530                             (*cOptions)[pos] = cOption;
531                             if( NULL != cOption )
532                             {
533                                 ++pos;
534                                 if( pos == capacity )
535                                 {
536                                     char **moreOptions = (char **)CoTaskMemRealloc(*cOptions, (capacity+16)*sizeof(char *));
537                                     if( NULL != moreOptions )
538                                     {
539                                         ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
540                                         capacity += 16;
541                                         *cOptions = moreOptions;
542                                     }
543                                     else
544                                         hr = E_OUTOFMEMORY;
545                                 }
546                             }
547                             else
548                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
549                                     E_OUTOFMEMORY : E_INVALIDARG;
550                         }
551                         else
552                             hr = E_INVALIDARG;
553
554                         VariantClear(&option);
555                     }
556                     *cOptionCount = pos;
557                     if( FAILED(hr) )
558                     {
559                         // free already processed elements
560                         FreeTargetOptions(*cOptions, *cOptionCount);
561                     }
562                 }
563                 else
564                     hr = E_OUTOFMEMORY;
565
566                 enumVar->Release();
567             }
568         }
569         else
570         {
571             // coerce object into a string and parse it
572             VARIANT v_name;
573             VariantInit(&v_name);
574             hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
575             if( SUCCEEDED(hr) )
576             {
577                 hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
578                 VariantClear(&v_name);
579             }
580         }
581     }
582     else if( V_ISARRAY(options) )
583     {
584         // array parameter
585         SAFEARRAY *array = V_ISBYREF(options) ? *V_ARRAYREF(options) : V_ARRAY(options);
586
587         if( SafeArrayGetDim(array) != 1 )
588             return E_INVALIDARG;
589
590         long lBound = 0;
591         long uBound = 0;
592         SafeArrayGetLBound(array, 1, &lBound);
593         SafeArrayGetUBound(array, 1, &uBound);
594
595         // have we got any options
596         if( uBound >= lBound )
597         {
598             VARTYPE vType;
599             hr = SafeArrayGetVartype(array, &vType);
600             if( FAILED(hr) )
601                 return hr;
602
603             long pos;
604
605             // marshall options into an array of C strings
606             if( VT_VARIANT == vType )
607             {
608                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
609                 if( NULL == *cOptions )
610                     return E_OUTOFMEMORY;
611
612                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
613                 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
614                 {
615                     VARIANT option;
616                     hr = SafeArrayGetElement(array, &pos, &option);
617                     if( SUCCEEDED(hr) )
618                     {
619                         if( VT_BSTR == V_VT(&option) )
620                         {
621                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
622                             (*cOptions)[pos-lBound] = cOption;
623                             if( NULL == cOption )
624                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
625                                     E_OUTOFMEMORY : E_INVALIDARG;
626                         }
627                         else
628                             hr = E_INVALIDARG;
629                         VariantClear(&option);
630                     }
631                 }
632             }
633             else if( VT_BSTR == vType )
634             {
635                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
636                 if( NULL == *cOptions )
637                     return E_OUTOFMEMORY;
638
639                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
640                 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
641                 {
642                     BSTR option;
643                     hr = SafeArrayGetElement(array, &pos, &option);
644                     if( SUCCEEDED(hr) )
645                     {
646                         char *cOption = CStrFromBSTR(codePage, option);
647
648                         (*cOptions)[pos-lBound] = cOption;
649                         if( NULL == cOption )
650                             hr = ( SysStringLen(option) > 0 ) ?
651                                 E_OUTOFMEMORY : E_INVALIDARG;
652                         SysFreeString(option);
653                     }
654                 }
655             }
656             else
657             {
658                 // unsupported type
659                 return E_INVALIDARG;
660             }
661
662             *cOptionCount = pos-lBound;
663             if( FAILED(hr) )
664             {
665                 // free already processed elements
666                 FreeTargetOptions(*cOptions, *cOptionCount);
667             }
668         }
669         else
670         {
671             // empty array
672             *cOptions = NULL;
673             *cOptionCount = 0;
674             return NOERROR;
675         }
676     }
677     else if( VT_UNKNOWN == V_VT(options) )
678     {
679         // coerce object into a string and parse it
680         VARIANT v_name;
681         VariantInit(&v_name);
682         hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
683         if( SUCCEEDED(hr) )
684         {
685             hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
686             VariantClear(&v_name);
687         }
688     }
689     else if( VT_BSTR == V_VT(options) )
690     {
691         hr = parseStringOptions(codePage, V_BSTR(options), cOptions, cOptionCount);
692     }
693     return hr;
694 };
695
696 /*
697 ** use VARIANT rather than a SAFEARRAY as argument type
698 ** for compatibility with some scripting language (JScript)
699 */
700
701 STDMETHODIMP VLCControl::addTarget(BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
702 {
703     if( 0 == SysStringLen(uri) )
704         return E_INVALIDARG;
705
706     libvlc_instance_t *p_libvlc;
707     HRESULT hr = _p_instance->getVLC(&p_libvlc);
708     if( SUCCEEDED(hr) )
709     {
710         char *cUri = CStrFromBSTR(CP_UTF8, uri);
711         if( NULL == cUri )
712             return E_OUTOFMEMORY;
713
714         int cOptionsCount;
715         char **cOptions;
716
717         if( FAILED(CreateTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
718             return E_INVALIDARG;
719
720         libvlc_exception_t ex;
721         libvlc_exception_init(&ex);
722
723         position = _p_instance->playlist_add_extended_untrusted(cUri,
724                        cOptionsCount, const_cast<const char**>(cOptions), &ex);
725
726         FreeTargetOptions(cOptions, cOptionsCount);
727         CoTaskMemFree(cUri);
728
729         hr = exception_bridge(&ex);
730         if( SUCCEEDED(hr) )
731         {
732             if( mode & VLCPlayListAppendAndGo )
733                 _p_instance->fireOnPlayEvent();
734         }
735         else
736         {
737             if( mode & VLCPlayListAppendAndGo )
738                 _p_instance->fireOnStopEvent();
739         }
740     }
741     return hr;
742 };
743
744 STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
745 {
746     if( NULL == index )
747         return E_POINTER;
748
749     *index = 0;
750     libvlc_instance_t *p_libvlc;
751     HRESULT result = _p_instance->getVLC(&p_libvlc);
752     if( SUCCEEDED(result) )
753     {
754         libvlc_exception_t ex;
755         libvlc_exception_init(&ex);
756
757         *index = _p_instance->playlist_get_current_index(&ex);
758         result = exception_bridge(&ex);
759     }
760     return result;
761 };
762
763 STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
764 {
765     if( NULL == count )
766         return E_POINTER;
767
768     libvlc_exception_t ex;
769     libvlc_exception_init(&ex);
770
771     *count = _p_instance->playlist_count(&ex);
772     return exception_bridge(&ex);
773 };
774
775 STDMETHODIMP VLCControl::playlistNext(void)
776 {
777     libvlc_instance_t* p_libvlc;
778     HRESULT result = _p_instance->getVLC(&p_libvlc);
779     if( SUCCEEDED(result) )
780     {
781         libvlc_exception_t ex;
782         libvlc_exception_init(&ex);
783
784         _p_instance->playlist_next(&ex);
785         result = exception_bridge(&ex);
786     }
787     return result;
788 };
789
790 STDMETHODIMP VLCControl::playlistPrev(void)
791 {
792     libvlc_instance_t* p_libvlc;
793     HRESULT result = _p_instance->getVLC(&p_libvlc);
794     if( SUCCEEDED(result) )
795     {
796         libvlc_exception_t ex;
797         libvlc_exception_init(&ex);
798
799         _p_instance->playlist_prev(&ex);
800         result = exception_bridge(&ex);
801     }
802     return result;
803 };
804
805 STDMETHODIMP VLCControl::playlistClear(void)
806 {
807     libvlc_instance_t* p_libvlc;
808     HRESULT result = _p_instance->getVLC(&p_libvlc);
809     if( SUCCEEDED(result) )
810     {
811         libvlc_exception_t ex;
812         libvlc_exception_init(&ex);
813
814         _p_instance->playlist_clear(&ex);
815         result = exception_bridge(&ex);
816     }
817     return result;
818 };
819
820 STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
821 {
822     if( NULL == version )
823         return E_POINTER;
824
825     const char *versionStr = libvlc_get_version();
826     if( NULL != versionStr )
827     {
828         *version = BSTRFromCStr(CP_UTF8, versionStr);
829         return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
830     }
831     *version = NULL;
832     return E_FAIL;
833 };
834
835 STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
836 {
837     if( NULL == mrl )
838         return E_POINTER;
839
840     *mrl = SysAllocStringLen(_p_instance->getMRL(),
841                 SysStringLen(_p_instance->getMRL()));
842     return NOERROR;
843 };
844
845 STDMETHODIMP VLCControl::put_MRL(BSTR mrl)
846 {
847     _p_instance->setMRL(mrl);
848
849     return S_OK;
850 };
851
852 STDMETHODIMP VLCControl::get_AutoPlay(VARIANT_BOOL *autoplay)
853 {
854     if( NULL == autoplay )
855         return E_POINTER;
856
857     *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
858     return S_OK;
859 };
860
861 STDMETHODIMP VLCControl::put_AutoPlay(VARIANT_BOOL autoplay)
862 {
863     _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
864     return S_OK;
865 };
866
867 STDMETHODIMP VLCControl::get_AutoLoop(VARIANT_BOOL *autoloop)
868 {
869     if( NULL == autoloop )
870         return E_POINTER;
871
872     *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
873     return S_OK;
874 };
875
876 STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
877 {
878     _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
879     return S_OK;
880 };