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