]> git.sesse.net Git - vlc/blob - activex/vlccontrol.cpp
- added support for non OLE containers, such as Windows Script Host WScript.CreateObject.
[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 NOERROR;
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;
127     HRESULT result = _p_instance->getVLCObject(&i_vlc);
128     if( SUCCEEDED(result) )
129     {
130         VLC_Play(i_vlc);
131         _p_instance->fireOnPlayEvent();
132     }
133     return result;
134 };
135  
136 STDMETHODIMP VLCControl::pause(void)
137 {
138     int i_vlc;
139     HRESULT result = _p_instance->getVLCObject(&i_vlc);
140     if( SUCCEEDED(result) )
141     {
142         VLC_Pause(i_vlc);
143         _p_instance->fireOnPauseEvent();
144     }
145     return result;
146 };
147         
148 STDMETHODIMP VLCControl::stop(void)
149 {
150     int i_vlc;
151     HRESULT result = _p_instance->getVLCObject(&i_vlc);
152     if( SUCCEEDED(result) )
153     {
154         VLC_Stop(i_vlc);
155         _p_instance->fireOnStopEvent();
156     }
157     return result;
158 };
159         
160 STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
161 {
162     if( NULL == isPlaying )
163         return E_POINTER;
164
165     HRESULT result = NOERROR;
166     if( _p_instance->isRunning() )
167     {
168         int i_vlc;
169         result = _p_instance->getVLCObject(&i_vlc);
170         if( SUCCEEDED(result) )
171         {
172             *isPlaying = VLC_IsPlaying(i_vlc) ? VARIANT_TRUE : VARIANT_FALSE;
173             return NOERROR;
174         }
175     }
176     *isPlaying = VARIANT_FALSE;
177     return result;
178 };
179         
180 STDMETHODIMP VLCControl::get_Position(float *position)
181 {
182     if( NULL == position )
183         return E_POINTER;
184
185     HRESULT result = E_UNEXPECTED;
186     if( _p_instance->isRunning() )
187     {
188         int i_vlc;
189         HRESULT result = _p_instance->getVLCObject(&i_vlc);
190         if( SUCCEEDED(result) )
191         {
192             *position = VLC_PositionGet(i_vlc);
193             return NOERROR;
194         }
195     }
196     *position = 0.0f;
197     return result;
198 };
199         
200 STDMETHODIMP VLCControl::put_Position(float position)
201 {
202     HRESULT result = E_UNEXPECTED;
203     if( _p_instance->isRunning() )
204     {
205         int i_vlc;
206         HRESULT result = _p_instance->getVLCObject(&i_vlc);
207         if( SUCCEEDED(result) )
208         {
209             VLC_PositionSet(i_vlc, position);
210         }
211     }
212     return result;
213 };
214         
215 STDMETHODIMP VLCControl::get_Time(int *seconds)
216 {
217     if( NULL == seconds )
218         return E_POINTER;
219
220     HRESULT result = NOERROR;
221     if( _p_instance->isRunning() )
222     {
223         int i_vlc;
224         HRESULT result = _p_instance->getVLCObject(&i_vlc);
225         if( SUCCEEDED(result) )
226         {
227             *seconds = VLC_TimeGet(i_vlc);
228         }
229     }
230     else
231         *seconds = _p_instance->getTime();
232
233     return result;
234 };
235      
236 STDMETHODIMP VLCControl::put_Time(int seconds)
237 {
238     _p_instance->setTime(seconds);
239
240     return NOERROR;
241 };
242         
243 STDMETHODIMP VLCControl::shuttle(int seconds)
244 {
245     HRESULT result = E_UNEXPECTED;
246     if( _p_instance->isRunning() )
247     {
248         int i_vlc;
249         result = _p_instance->getVLCObject(&i_vlc);
250         if( SUCCEEDED(result) )
251         {
252             VLC_TimeSet(i_vlc, seconds, VLC_TRUE);
253         }
254     }
255     return result;
256 };
257         
258 STDMETHODIMP VLCControl::fullscreen(void)
259 {
260     HRESULT result = E_UNEXPECTED;
261     if( _p_instance->isRunning() )
262     {
263         int i_vlc;
264         result = _p_instance->getVLCObject(&i_vlc);
265         if( SUCCEEDED(result) )
266         {
267             VLC_FullScreen(i_vlc);
268         }
269     }
270     return result;
271 };
272         
273 STDMETHODIMP VLCControl::get_Length(int *seconds)
274 {
275     if( NULL == seconds )
276         return E_POINTER;
277
278     HRESULT result = NOERROR;
279     if( _p_instance->isRunning() )
280     {
281         int i_vlc;
282         result = _p_instance->getVLCObject(&i_vlc);
283         if( SUCCEEDED(result) )
284         {
285             *seconds = VLC_LengthGet(i_vlc);
286             return NOERROR;
287         }
288     }
289     *seconds = 0;
290     return result;
291 };
292         
293 STDMETHODIMP VLCControl::playFaster(void)
294 {
295     HRESULT result = E_UNEXPECTED;
296     if( _p_instance->isRunning() )
297     {
298         int i_vlc;
299         result = _p_instance->getVLCObject(&i_vlc);
300         if( SUCCEEDED(result) )
301         {
302             VLC_SpeedFaster(i_vlc);
303         }
304     }
305     return result;
306 };
307         
308 STDMETHODIMP VLCControl::playSlower(void)
309 {
310     HRESULT result = E_UNEXPECTED;
311     if( _p_instance->isRunning() )
312     {
313         int i_vlc;
314         result = _p_instance->getVLCObject(&i_vlc);
315         if( SUCCEEDED(result) )
316         {
317             VLC_SpeedSlower(i_vlc);
318         }
319     }
320     return result;
321 };
322         
323 STDMETHODIMP VLCControl::get_Volume(int *volume)
324 {
325     if( NULL == volume )
326         return E_POINTER;
327
328     *volume  = _p_instance->getVolume();
329     return NOERROR;
330 };
331         
332 STDMETHODIMP VLCControl::put_Volume(int volume)
333 {
334     _p_instance->setVolume(volume);
335     return NOERROR;
336 };
337         
338 STDMETHODIMP VLCControl::toggleMute(void)
339 {
340     int i_vlc;
341     HRESULT result = _p_instance->getVLCObject(&i_vlc);
342     if( SUCCEEDED(result) )
343     {
344         VLC_VolumeMute(i_vlc);
345     }
346     return result;
347 };
348
349 STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
350 {
351     if( 0 == SysStringLen(name) )
352         return E_INVALIDARG;
353
354     int i_vlc;
355     HRESULT hr = _p_instance->getVLCObject(&i_vlc);
356     if( SUCCEEDED(hr) )
357     {
358         int codePage = _p_instance->getCodePage();
359         char *psz_varname = CStrFromBSTR(codePage, name);
360         if( NULL == psz_varname )
361             return E_OUTOFMEMORY;
362
363         int i_type;
364         vlc_value_t val;
365         
366         if( VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type) )
367         {
368             VARIANT arg;
369             VariantInit(&arg);
370
371             switch( i_type )
372             {
373                 case VLC_VAR_BOOL:
374                     hr = VariantChangeType(&arg, &value, 0, VT_BOOL);
375                     if( SUCCEEDED(hr) )
376                         val.b_bool = (VARIANT_TRUE == V_BOOL(&arg)) ? VLC_TRUE : VLC_FALSE;
377                     break;
378
379                 case VLC_VAR_INTEGER:
380                 case VLC_VAR_HOTKEY:
381                     hr = VariantChangeType(&arg, &value, 0, VT_I4);
382                     if( SUCCEEDED(hr) )
383                         val.i_int = V_I4(&arg);
384                     break;
385
386                 case VLC_VAR_FLOAT:
387                     hr = VariantChangeType(&arg, &value, 0, VT_R4);
388                     if( SUCCEEDED(hr) )
389                         val.f_float = V_R4(&arg);
390                     break;
391
392                 case VLC_VAR_STRING:
393                 case VLC_VAR_MODULE:
394                 case VLC_VAR_FILE:
395                 case VLC_VAR_DIRECTORY:
396                 case VLC_VAR_VARIABLE:
397                     hr = VariantChangeType(&arg, &value, 0, VT_BSTR);
398                     if( SUCCEEDED(hr) )
399                     {
400                         i_type = VLC_VAR_STRING;
401                         val.psz_string = CStrFromBSTR(codePage, V_BSTR(&arg));
402                         VariantClear(&arg);
403                     }
404                     break;
405
406                 case VLC_VAR_TIME:
407                     // use a double value to represent time (base is expressed in seconds)
408                     hr = VariantChangeType(&arg, &value, 0, VT_R8);
409                     if( SUCCEEDED(hr) )
410                         val.i_time = (signed __int64)(V_R8(&arg)*1000000.0);
411                     break;
412
413                 default:
414                     hr = DISP_E_TYPEMISMATCH;
415             }
416         }
417         else {
418             // no defined type, use type in VARIANT
419             hr = NO_ERROR;
420             switch( V_VT(&value) )
421             {
422                 case VT_BOOL:
423                     val.b_bool = (VARIANT_TRUE == V_BOOL(&value)) ? VLC_TRUE : VLC_FALSE;
424                     i_type = VLC_VAR_BOOL;
425                     break;
426                 case VT_I4:
427                     val.i_int = V_I4(&value);
428                     i_type = VLC_VAR_INTEGER;
429                     break;
430                 case VT_R4:
431                     val.f_float = V_R4(&value);
432                     i_type = VLC_VAR_FLOAT;
433                     break;
434                 case VT_BSTR:
435                     val.psz_string = CStrFromBSTR(codePage, V_BSTR(&value));
436                     i_type = VLC_VAR_STRING;
437                     break;
438                 case VT_R8:
439                     // use a double value to represent time (base is expressed in seconds)
440                     val.i_time = (signed __int64)(V_R8(&value)*1000000.0);
441                     i_type = VLC_VAR_TIME;
442                     break;
443                 default:
444                     hr = DISP_E_TYPEMISMATCH;
445             }
446         }
447         if( SUCCEEDED(hr) )
448         {
449             hr = (VLC_SUCCESS == VLC_VariableSet(i_vlc, psz_varname, val)) ? NOERROR : E_FAIL;
450
451             if( (VLC_VAR_STRING == i_type) && (NULL != val.psz_string) )
452                 CoTaskMemFree(val.psz_string);
453         }
454         CoTaskMemFree(psz_varname);
455     }
456     return hr;
457 };
458
459 STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
460 {
461     if( NULL == value )
462         return E_POINTER;
463
464     VariantInit(value);
465
466     if( 0 == SysStringLen(name) )
467         return E_INVALIDARG;
468
469     int i_vlc;
470     HRESULT hr = _p_instance->getVLCObject(&i_vlc);
471     if( SUCCEEDED(hr) )
472     {
473         UINT codePage = _p_instance->getCodePage();
474         char *psz_varname = CStrFromBSTR(codePage, name);
475         if( NULL == psz_varname )
476             return E_OUTOFMEMORY;
477
478         hr = E_INVALIDARG;
479
480         vlc_value_t val;
481         int i_type;
482
483         if( (VLC_SUCCESS == VLC_VariableGet(i_vlc, psz_varname, &val))
484          && (VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type)) )
485         {
486             hr = NOERROR;
487             switch( i_type )
488             {
489                 case VLC_VAR_BOOL:
490                     V_VT(value) = VT_BOOL;
491                     V_BOOL(value) = val.b_bool ? VARIANT_TRUE : VARIANT_FALSE;
492                     break;
493
494                 case VLC_VAR_INTEGER:
495                 case VLC_VAR_HOTKEY:
496                     V_VT(value) = VT_I4;
497                     V_I4(value) = val.i_int;
498                     break;
499
500                 case VLC_VAR_FLOAT:
501                     V_VT(value) = VT_R4;
502                     V_R4(value) = val.f_float;
503                     break;
504
505                 case VLC_VAR_STRING:
506                 case VLC_VAR_MODULE:
507                 case VLC_VAR_FILE:
508                 case VLC_VAR_DIRECTORY:
509                 case VLC_VAR_VARIABLE:
510                     V_VT(value) = VT_BSTR;
511                     V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
512                     if( NULL != val.psz_string)
513                         free(val.psz_string);
514                     break;
515
516                 case VLC_VAR_TIME:
517                     // use a double value to represent time (base is expressed in seconds)
518                     V_VT(value) = VT_R8;
519                     V_R8(value) = ((double)val.i_time)/1000000.0;
520                     break;
521
522                 default:
523                     hr = DISP_E_TYPEMISMATCH;
524             }
525         }
526         CoTaskMemFree(psz_varname);
527         return hr;
528     }
529     return hr;
530 };
531
532 static void freeTargetOptions(char **cOptions, int cOptionCount)
533 {
534     // clean up 
535     if( NULL != cOptions )
536     {
537         for( int pos=0; pos<cOptionCount; ++pos )
538         {
539             char *cOption = cOptions[pos];
540             if( NULL != cOption )
541                 CoTaskMemFree(cOption);
542             else
543                 break;
544         }
545         CoTaskMemFree(cOptions);
546     }
547 };
548
549 static HRESULT createTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
550 {
551     HRESULT hr = E_INVALIDARG;
552     if( VT_ERROR == V_VT(options) )
553     {
554         if( DISP_E_PARAMNOTFOUND == V_ERROR(options) )
555         {
556             // optional parameter not set
557             *cOptions = NULL;
558             *cOptionCount = 0;
559             return NOERROR;
560         }
561     }
562     else if( (VT_EMPTY == V_VT(options)) || (VT_NULL == V_VT(options)) )
563     {
564         // null parameter
565         *cOptions = NULL;
566         *cOptionCount = 0;
567         return NOERROR;
568     }
569     else if( VT_DISPATCH == V_VT(options) )
570     {
571         // collection parameter
572         VARIANT colEnum;
573         V_VT(&colEnum) = VT_UNKNOWN;
574         hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
575         if( SUCCEEDED(hr) )
576         {
577             IEnumVARIANT *enumVar;
578             hr = V_UNKNOWN(&colEnum)->QueryInterface(IID_IEnumVARIANT, (LPVOID *)&enumVar);
579             if( SUCCEEDED(hr) )
580             {
581                 long pos = 0;
582                 long capacity = 16;
583                 VARIANT option;
584
585                 *cOptions = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
586                 if( NULL != *cOptions )
587                 {
588                     ZeroMemory(*cOptions, sizeof(char *)*capacity);
589                     while( SUCCEEDED(hr) && (S_OK == enumVar->Next(1, &option, NULL)) )
590                     {
591                         if( VT_BSTR == V_VT(&option) )
592                         {
593                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
594                             (*cOptions)[pos] = cOption;
595                             if( NULL != cOption )
596                             {
597                                 ++pos;
598                                 if( pos == capacity )
599                                 {
600                                     char **moreOptions = (char **)CoTaskMemRealloc(*cOptions, (capacity+16)*sizeof(char *));
601                                     if( NULL != moreOptions )
602                                     {
603                                         ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
604                                         capacity += 16;
605                                         *cOptions = moreOptions;
606                                     }
607                                     else
608                                         hr = E_OUTOFMEMORY;
609                                 }
610                             }
611                             else
612                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
613                                     E_OUTOFMEMORY : E_INVALIDARG;
614                         }
615                         else
616                             hr = E_INVALIDARG;
617
618                         VariantClear(&option);
619                     }
620                     *cOptionCount = pos;
621                     if( FAILED(hr) )
622                     {
623                         // free already processed elements
624                         freeTargetOptions(*cOptions, *cOptionCount);
625                     }
626                 }
627                 else
628                     hr = E_OUTOFMEMORY;
629
630                 enumVar->Release();
631             }
632         }
633     }
634     else if( V_ISARRAY(options) )
635     {
636         // array parameter
637         SAFEARRAY *array = V_ISBYREF(options) ? *V_ARRAYREF(options) : V_ARRAY(options);
638
639         if( SafeArrayGetDim(array) != 1 )
640             return E_INVALIDARG;
641
642         long lBound = 0;
643         long uBound = 0;
644         SafeArrayGetLBound(array, 1, &lBound);
645         SafeArrayGetUBound(array, 1, &uBound);
646
647         // have we got any options
648         if( uBound >= lBound )
649         {
650             VARTYPE vType;
651             hr = SafeArrayGetVartype(array, &vType);
652             if( FAILED(hr) )
653                 return hr;
654
655             long pos;
656
657             // marshall options into an array of C strings
658             if( VT_VARIANT == vType )
659             {
660                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
661                 if( NULL == *cOptions )
662                     return E_OUTOFMEMORY;
663
664                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
665                 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
666                 {
667                     VARIANT option;
668                     hr = SafeArrayGetElement(array, &pos, &option);
669                     if( SUCCEEDED(hr) )
670                     {
671                         if( VT_BSTR == V_VT(&option) ) 
672                         {
673                             char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
674                             (*cOptions)[pos-lBound] = cOption;
675                             if( NULL == cOption )
676                                 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
677                                     E_OUTOFMEMORY : E_INVALIDARG;
678                         }
679                         else
680                             hr = E_INVALIDARG;
681                         VariantClear(&option);
682                     }
683                 }
684             }
685             else if( VT_BSTR == vType )
686             {
687                 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
688                 if( NULL == *cOptions )
689                     return E_OUTOFMEMORY;
690
691                 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
692                 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
693                 {
694                     BSTR option;
695                     hr = SafeArrayGetElement(array, &pos, &option);
696                     if( SUCCEEDED(hr) )
697                     {
698                         char *cOption = CStrFromBSTR(codePage, option);
699
700                         (*cOptions)[pos-lBound] = cOption;
701                         if( NULL == cOption )
702                             hr = ( SysStringLen(option) > 0 ) ?
703                                 E_OUTOFMEMORY : E_INVALIDARG;
704                         SysFreeString(option);
705                     }
706                 }
707             }
708             else 
709             {
710                 // unsupported type
711                 return E_INVALIDARG;
712             }
713
714             *cOptionCount = pos-lBound;
715             if( FAILED(hr) )
716             {
717                 // free already processed elements
718                 freeTargetOptions(*cOptions, *cOptionCount);
719             }
720         }
721         else
722         {
723             // empty array
724             *cOptions = NULL;
725             *cOptionCount = 0;
726             return NOERROR;
727         }
728     }
729     return hr;
730 };
731
732 /*
733 ** use VARIANT rather than a SAFEARRAY as argument type
734 ** for compatibility with some scripting language (JScript)
735 */
736
737 STDMETHODIMP VLCControl::addTarget( BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
738 {
739     if( 0 == SysStringLen(uri) )
740         return E_INVALIDARG;
741
742     int i_vlc;
743     HRESULT hr = _p_instance->getVLCObject(&i_vlc);
744     if( SUCCEEDED(hr) )
745     {
746         char *cUri = CStrFromBSTR(CP_UTF8, uri);
747         if( NULL == cUri )
748             return E_OUTOFMEMORY;
749
750         int cOptionsCount;
751         char **cOptions;
752
753         if( FAILED(createTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
754             return E_INVALIDARG;
755
756         if( VLC_SUCCESS <= VLC_AddTarget(i_vlc, cUri, (const char **)cOptions, cOptionsCount, mode, position) )
757         {
758             hr = NOERROR;
759             if( mode & PLAYLIST_GO )
760                 _p_instance->fireOnPlayEvent();
761         }
762         else
763         {
764             hr = E_FAIL;
765             if( mode & PLAYLIST_GO )
766                 _p_instance->fireOnStopEvent();
767         }
768
769         freeTargetOptions(cOptions, cOptionsCount);
770         CoTaskMemFree(cUri);
771     }
772     return hr;
773 };
774         
775 STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
776 {
777     if( NULL == index )
778         return E_POINTER;
779
780     int i_vlc;
781     HRESULT result = _p_instance->getVLCObject(&i_vlc);
782     if( SUCCEEDED(result) )
783     {
784         *index = VLC_PlaylistIndex(i_vlc);
785         return NOERROR;
786     }
787     *index = 0;
788     return result;
789 };
790         
791 STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
792 {
793     int i_vlc;
794     HRESULT result = _p_instance->getVLCObject(&i_vlc);
795     if( SUCCEEDED(result) )
796     {
797         *count = VLC_PlaylistNumberOfItems(i_vlc);
798         return NOERROR;
799     }
800     *count = 0;
801     return result;
802 };
803         
804 STDMETHODIMP VLCControl::playlistNext(void)
805 {
806     int i_vlc;
807     HRESULT result = _p_instance->getVLCObject(&i_vlc);
808     if( SUCCEEDED(result) )
809     {
810         VLC_PlaylistNext(i_vlc);
811         return NOERROR;
812     }
813     return result;
814 };
815         
816 STDMETHODIMP VLCControl::playlistPrev(void)
817 {
818     int i_vlc;
819     HRESULT result = _p_instance->getVLCObject(&i_vlc);
820     if( SUCCEEDED(result) )
821     {
822         VLC_PlaylistPrev(i_vlc);
823         return NOERROR;
824     }
825     return result;
826 };
827         
828 STDMETHODIMP VLCControl::playlistClear(void)
829 {
830     int i_vlc;
831     HRESULT result = _p_instance->getVLCObject(&i_vlc);
832     if( SUCCEEDED(result) )
833     {
834         VLC_PlaylistClear(i_vlc);
835         return NOERROR;
836     }
837     return result;
838 };
839         
840 STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
841 {
842     if( NULL == version )
843         return E_POINTER;
844
845     const char *versionStr = VLC_Version();
846     if( NULL != versionStr )
847     {
848         *version = BSTRFromCStr(_p_instance->getCodePage(), versionStr);
849         
850         return NULL == *version ? E_OUTOFMEMORY : NOERROR;
851     }
852     *version = NULL;
853     return E_FAIL;
854 };
855  
856 STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
857 {
858     if( NULL == mrl )
859         return E_POINTER;
860
861     *mrl = SysAllocStringLen(_p_instance->getMRL(),
862                 SysStringLen(_p_instance->getMRL()));
863     return NOERROR;
864 };
865
866 STDMETHODIMP VLCControl::put_MRL(BSTR mrl)
867 {
868     _p_instance->setMRL(mrl);
869
870     return S_OK;
871 };
872
873 STDMETHODIMP VLCControl::get_AutoPlay(VARIANT_BOOL *autoplay)
874 {
875     if( NULL == autoplay )
876         return E_POINTER;
877
878     *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
879     return S_OK;
880 };
881
882 STDMETHODIMP VLCControl::put_AutoPlay(VARIANT_BOOL autoplay)
883 {
884     _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
885     return S_OK;
886 };
887
888 STDMETHODIMP VLCControl::get_AutoLoop(VARIANT_BOOL *autoloop)
889 {
890     if( NULL == autoloop )
891         return E_POINTER;
892
893     *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
894     return S_OK;
895 };
896
897 STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
898 {
899     _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
900     return S_OK;
901 };
902