Try to improve wording
[vlc.git] / activex / vlccontrol.cpp
blobd9793bf30a87f384bcbe5b56d4aebd6305b1a953
1 /*****************************************************************************
2 * vlccontrol.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
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.
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.
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 *****************************************************************************/
23 #include "plugin.h"
24 #include "vlccontrol.h"
26 #include "utils.h"
28 using namespace std;
30 VLCControl::~VLCControl()
32 if( _p_typeinfo )
33 _p_typeinfo->Release();
36 HRESULT VLCControl::getTypeInfo(void)
38 HRESULT hr = NOERROR;
39 if( NULL == _p_typeinfo )
41 ITypeLib *p_typelib;
43 hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
44 if( SUCCEEDED(hr) )
46 hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl, &_p_typeinfo);
47 if( FAILED(hr) )
49 _p_typeinfo = NULL;
51 p_typelib->Release();
54 return hr;
57 STDMETHODIMP VLCControl::GetTypeInfoCount(UINT* pctInfo)
59 if( NULL == pctInfo )
60 return E_INVALIDARG;
62 if( SUCCEEDED(getTypeInfo()) )
63 *pctInfo = 1;
64 else
65 *pctInfo = 0;
67 return NOERROR;
70 STDMETHODIMP VLCControl::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
72 if( NULL == ppTInfo )
73 return E_INVALIDARG;
75 if( SUCCEEDED(getTypeInfo()) )
77 _p_typeinfo->AddRef();
78 *ppTInfo = _p_typeinfo;
79 return NOERROR;
81 *ppTInfo = NULL;
82 return E_NOTIMPL;
85 STDMETHODIMP VLCControl::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
86 UINT cNames, LCID lcid, DISPID* rgDispID)
88 if( SUCCEEDED(getTypeInfo()) )
90 return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
92 return E_NOTIMPL;
95 STDMETHODIMP VLCControl::Invoke(DISPID dispIdMember, REFIID riid,
96 LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
97 VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
99 if( SUCCEEDED(getTypeInfo()) )
101 return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
102 pVarResult, pExcepInfo, puArgErr);
104 return E_NOTIMPL;
107 STDMETHODIMP VLCControl::get_Visible(VARIANT_BOOL *isVisible)
109 if( NULL == isVisible )
110 return E_POINTER;
112 *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
114 return NOERROR;
117 STDMETHODIMP VLCControl::put_Visible(VARIANT_BOOL isVisible)
119 _p_instance->setVisible(isVisible != VARIANT_FALSE);
121 return NOERROR;
124 STDMETHODIMP VLCControl::play(void)
126 int i_vlc;
127 HRESULT result = _p_instance->getVLCObject(&i_vlc);
128 if( SUCCEEDED(result) )
130 VLC_Play(i_vlc);
131 _p_instance->fireOnPlayEvent();
133 return result;
136 STDMETHODIMP VLCControl::pause(void)
138 int i_vlc;
139 HRESULT result = _p_instance->getVLCObject(&i_vlc);
140 if( SUCCEEDED(result) )
142 VLC_Pause(i_vlc);
143 _p_instance->fireOnPauseEvent();
145 return result;
148 STDMETHODIMP VLCControl::stop(void)
150 int i_vlc;
151 HRESULT result = _p_instance->getVLCObject(&i_vlc);
152 if( SUCCEEDED(result) )
154 VLC_Stop(i_vlc);
155 _p_instance->fireOnStopEvent();
157 return result;
160 STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
162 if( NULL == isPlaying )
163 return E_POINTER;
165 HRESULT result = NOERROR;
166 if( _p_instance->isRunning() )
168 int i_vlc;
169 result = _p_instance->getVLCObject(&i_vlc);
170 if( SUCCEEDED(result) )
172 *isPlaying = VLC_IsPlaying(i_vlc) ? VARIANT_TRUE : VARIANT_FALSE;
173 return NOERROR;
176 *isPlaying = VARIANT_FALSE;
177 return result;
180 STDMETHODIMP VLCControl::get_Position(float *position)
182 if( NULL == position )
183 return E_POINTER;
185 HRESULT result = E_UNEXPECTED;
186 if( _p_instance->isRunning() )
188 int i_vlc;
189 result = _p_instance->getVLCObject(&i_vlc);
190 if( SUCCEEDED(result) )
192 *position = VLC_PositionGet(i_vlc);
193 return NOERROR;
196 *position = 0.0f;
197 return result;
200 STDMETHODIMP VLCControl::put_Position(float position)
202 HRESULT result = E_UNEXPECTED;
203 if( _p_instance->isRunning() )
205 int i_vlc;
206 result = _p_instance->getVLCObject(&i_vlc);
207 if( SUCCEEDED(result) )
209 VLC_PositionSet(i_vlc, position);
212 return result;
215 STDMETHODIMP VLCControl::get_Time(int *seconds)
217 if( NULL == seconds )
218 return E_POINTER;
220 HRESULT result = NOERROR;
221 if( _p_instance->isRunning() )
223 int i_vlc;
224 result = _p_instance->getVLCObject(&i_vlc);
225 if( SUCCEEDED(result) )
227 *seconds = VLC_TimeGet(i_vlc);
230 else
231 *seconds = _p_instance->getTime();
233 return result;
236 STDMETHODIMP VLCControl::put_Time(int seconds)
238 _p_instance->setTime(seconds);
240 return NOERROR;
243 STDMETHODIMP VLCControl::shuttle(int seconds)
245 HRESULT result = E_UNEXPECTED;
246 if( _p_instance->isRunning() )
248 int i_vlc;
249 result = _p_instance->getVLCObject(&i_vlc);
250 if( SUCCEEDED(result) )
252 VLC_TimeSet(i_vlc, seconds, VLC_TRUE);
255 return result;
258 STDMETHODIMP VLCControl::fullscreen(void)
260 HRESULT result = E_UNEXPECTED;
261 if( _p_instance->isRunning() )
263 int i_vlc;
264 result = _p_instance->getVLCObject(&i_vlc);
265 if( SUCCEEDED(result) )
267 VLC_FullScreen(i_vlc);
270 return result;
273 STDMETHODIMP VLCControl::get_Length(int *seconds)
275 if( NULL == seconds )
276 return E_POINTER;
278 HRESULT result = NOERROR;
279 if( _p_instance->isRunning() )
281 int i_vlc;
282 result = _p_instance->getVLCObject(&i_vlc);
283 if( SUCCEEDED(result) )
285 *seconds = VLC_LengthGet(i_vlc);
286 return NOERROR;
289 *seconds = 0;
290 return result;
293 STDMETHODIMP VLCControl::playFaster(void)
295 HRESULT result = E_UNEXPECTED;
296 if( _p_instance->isRunning() )
298 int i_vlc;
299 result = _p_instance->getVLCObject(&i_vlc);
300 if( SUCCEEDED(result) )
302 VLC_SpeedFaster(i_vlc);
305 return result;
308 STDMETHODIMP VLCControl::playSlower(void)
310 HRESULT result = E_UNEXPECTED;
311 if( _p_instance->isRunning() )
313 int i_vlc;
314 result = _p_instance->getVLCObject(&i_vlc);
315 if( SUCCEEDED(result) )
317 VLC_SpeedSlower(i_vlc);
320 return result;
323 STDMETHODIMP VLCControl::get_Volume(int *volume)
325 if( NULL == volume )
326 return E_POINTER;
328 *volume = _p_instance->getVolume();
329 return NOERROR;
332 STDMETHODIMP VLCControl::put_Volume(int volume)
334 _p_instance->setVolume(volume);
335 return NOERROR;
338 STDMETHODIMP VLCControl::toggleMute(void)
340 int i_vlc;
341 HRESULT result = _p_instance->getVLCObject(&i_vlc);
342 if( SUCCEEDED(result) )
344 VLC_VolumeMute(i_vlc);
346 return result;
349 STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
351 if( 0 == SysStringLen(name) )
352 return E_INVALIDARG;
354 int i_vlc;
355 HRESULT hr = _p_instance->getVLCObject(&i_vlc);
356 if( SUCCEEDED(hr) )
358 int codePage = _p_instance->getCodePage();
359 char *psz_varname = CStrFromBSTR(codePage, name);
360 if( NULL == psz_varname )
361 return E_OUTOFMEMORY;
363 int i_type;
364 vlc_value_t val;
366 if( VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type) )
368 VARIANT arg;
369 VariantInit(&arg);
371 switch( i_type )
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;
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;
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;
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) )
400 i_type = VLC_VAR_STRING;
401 val.psz_string = CStrFromBSTR(codePage, V_BSTR(&arg));
402 VariantClear(&arg);
404 break;
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;
413 default:
414 hr = DISP_E_TYPEMISMATCH;
417 else {
418 // no defined type, use type in VARIANT
419 hr = NO_ERROR;
420 switch( V_VT(&value) )
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;
447 if( SUCCEEDED(hr) )
449 hr = (VLC_SUCCESS == VLC_VariableSet(i_vlc, psz_varname, val)) ? NOERROR : E_FAIL;
451 if( (VLC_VAR_STRING == i_type) && (NULL != val.psz_string) )
452 CoTaskMemFree(val.psz_string);
454 CoTaskMemFree(psz_varname);
456 return hr;
459 STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
461 if( NULL == value )
462 return E_POINTER;
464 VariantInit(value);
466 if( 0 == SysStringLen(name) )
467 return E_INVALIDARG;
469 int i_vlc;
470 HRESULT hr = _p_instance->getVLCObject(&i_vlc);
471 if( SUCCEEDED(hr) )
473 UINT codePage = _p_instance->getCodePage();
474 char *psz_varname = CStrFromBSTR(codePage, name);
475 if( NULL == psz_varname )
476 return E_OUTOFMEMORY;
478 hr = E_INVALIDARG;
480 vlc_value_t val;
481 int i_type;
483 if( (VLC_SUCCESS == VLC_VariableGet(i_vlc, psz_varname, &val))
484 && (VLC_SUCCESS == VLC_VariableType(i_vlc, psz_varname, &i_type)) )
486 hr = NOERROR;
487 switch( i_type )
489 case VLC_VAR_BOOL:
490 V_VT(value) = VT_BOOL;
491 V_BOOL(value) = val.b_bool ? VARIANT_TRUE : VARIANT_FALSE;
492 break;
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;
500 case VLC_VAR_FLOAT:
501 V_VT(value) = VT_R4;
502 V_R4(value) = val.f_float;
503 break;
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;
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;
522 default:
523 hr = DISP_E_TYPEMISMATCH;
526 CoTaskMemFree(psz_varname);
527 return hr;
529 return hr;
532 void VLCControl::FreeTargetOptions(char **cOptions, int cOptionCount)
534 // clean up
535 if( NULL != cOptions )
537 for( int pos=0; pos<cOptionCount; ++pos )
539 char *cOption = cOptions[pos];
540 if( NULL != cOption )
541 CoTaskMemFree(cOption);
542 else
543 break;
545 CoTaskMemFree(cOptions);
549 static HRESULT parseStringOptions(int codePage, BSTR bstr, char*** cOptions, int *cOptionCount)
551 HRESULT hr = E_INVALIDARG;
552 if( SysStringLen(bstr) > 0 )
554 hr = E_OUTOFMEMORY;
555 char *s = CStrFromBSTR(codePage, bstr);
556 char *val = s;
557 if( val )
559 long capacity = 16;
560 char **options = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
561 if( options )
563 int nOptions = 0;
565 char *end = val + strlen(val);
566 while( val < end )
568 // skip leading blanks
569 while( (val < end)
570 && ((*val == ' ' ) || (*val == '\t')) )
571 ++val;
573 char *start = val;
574 // skip till we get a blank character
575 while( (val < end)
576 && (*val != ' ' )
577 && (*val != '\t') )
579 char c = *(val++);
580 if( ('\'' == c) || ('"' == c) )
582 // skip till end of string
583 while( (val < end) && (*(val++) != c ) );
587 if( val > start )
589 if( nOptions == capacity )
591 capacity += 16;
592 char **moreOptions = (char **)CoTaskMemRealloc(options, capacity*sizeof(char*));
593 if( ! moreOptions )
595 /* failed to allocate more memory */
596 CoTaskMemFree(s);
597 /* return what we got so far */
598 *cOptionCount = nOptions;
599 *cOptions = options;
600 return NOERROR;
602 options = moreOptions;
604 *(val++) = '\0';
605 options[nOptions] = (char *)CoTaskMemAlloc(val-start);
606 if( options[nOptions] )
608 memcpy(options[nOptions], start, val-start);
609 ++nOptions;
611 else
613 /* failed to allocate memory */
614 CoTaskMemFree(s);
615 /* return what we got so far */
616 *cOptionCount = nOptions;
617 *cOptions = options;
618 return NOERROR;
621 else
622 // must be end of string
623 break;
625 *cOptionCount = nOptions;
626 *cOptions = options;
627 hr = NOERROR;
629 CoTaskMemFree(s);
632 return hr;
635 HRESULT VLCControl::CreateTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
637 HRESULT hr = E_INVALIDARG;
638 if( VT_ERROR == V_VT(options) )
640 if( DISP_E_PARAMNOTFOUND == V_ERROR(options) )
642 // optional parameter not set
643 *cOptions = NULL;
644 *cOptionCount = 0;
645 return NOERROR;
648 else if( (VT_EMPTY == V_VT(options)) || (VT_NULL == V_VT(options)) )
650 // null parameter
651 *cOptions = NULL;
652 *cOptionCount = 0;
653 return NOERROR;
655 else if( VT_DISPATCH == V_VT(options) )
657 // if object is a collection, retrieve enumerator
658 VARIANT colEnum;
659 V_VT(&colEnum) = VT_UNKNOWN;
660 hr = GetObjectProperty(V_DISPATCH(options), DISPID_NEWENUM, colEnum);
661 if( SUCCEEDED(hr) )
663 IEnumVARIANT *enumVar;
664 hr = V_UNKNOWN(&colEnum)->QueryInterface(IID_IEnumVARIANT, (LPVOID *)&enumVar);
665 if( SUCCEEDED(hr) )
667 long pos = 0;
668 long capacity = 16;
669 VARIANT option;
671 *cOptions = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
672 if( NULL != *cOptions )
674 ZeroMemory(*cOptions, sizeof(char *)*capacity);
675 while( SUCCEEDED(hr) && (S_OK == enumVar->Next(1, &option, NULL)) )
677 if( VT_BSTR == V_VT(&option) )
679 char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
680 (*cOptions)[pos] = cOption;
681 if( NULL != cOption )
683 ++pos;
684 if( pos == capacity )
686 char **moreOptions = (char **)CoTaskMemRealloc(*cOptions, (capacity+16)*sizeof(char *));
687 if( NULL != moreOptions )
689 ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
690 capacity += 16;
691 *cOptions = moreOptions;
693 else
694 hr = E_OUTOFMEMORY;
697 else
698 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
699 E_OUTOFMEMORY : E_INVALIDARG;
701 else
702 hr = E_INVALIDARG;
704 VariantClear(&option);
706 *cOptionCount = pos;
707 if( FAILED(hr) )
709 // free already processed elements
710 FreeTargetOptions(*cOptions, *cOptionCount);
713 else
714 hr = E_OUTOFMEMORY;
716 enumVar->Release();
719 else
721 // coerce object into a string and parse it
722 VARIANT v_name;
723 VariantInit(&v_name);
724 hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
725 if( SUCCEEDED(hr) )
727 hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
728 VariantClear(&v_name);
732 else if( V_ISARRAY(options) )
734 // array parameter
735 SAFEARRAY *array = V_ISBYREF(options) ? *V_ARRAYREF(options) : V_ARRAY(options);
737 if( SafeArrayGetDim(array) != 1 )
738 return E_INVALIDARG;
740 long lBound = 0;
741 long uBound = 0;
742 SafeArrayGetLBound(array, 1, &lBound);
743 SafeArrayGetUBound(array, 1, &uBound);
745 // have we got any options
746 if( uBound >= lBound )
748 VARTYPE vType;
749 hr = SafeArrayGetVartype(array, &vType);
750 if( FAILED(hr) )
751 return hr;
753 long pos;
755 // marshall options into an array of C strings
756 if( VT_VARIANT == vType )
758 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
759 if( NULL == *cOptions )
760 return E_OUTOFMEMORY;
762 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
763 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
765 VARIANT option;
766 hr = SafeArrayGetElement(array, &pos, &option);
767 if( SUCCEEDED(hr) )
769 if( VT_BSTR == V_VT(&option) )
771 char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
772 (*cOptions)[pos-lBound] = cOption;
773 if( NULL == cOption )
774 hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
775 E_OUTOFMEMORY : E_INVALIDARG;
777 else
778 hr = E_INVALIDARG;
779 VariantClear(&option);
783 else if( VT_BSTR == vType )
785 *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
786 if( NULL == *cOptions )
787 return E_OUTOFMEMORY;
789 ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
790 for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
792 BSTR option;
793 hr = SafeArrayGetElement(array, &pos, &option);
794 if( SUCCEEDED(hr) )
796 char *cOption = CStrFromBSTR(codePage, option);
798 (*cOptions)[pos-lBound] = cOption;
799 if( NULL == cOption )
800 hr = ( SysStringLen(option) > 0 ) ?
801 E_OUTOFMEMORY : E_INVALIDARG;
802 SysFreeString(option);
806 else
808 // unsupported type
809 return E_INVALIDARG;
812 *cOptionCount = pos-lBound;
813 if( FAILED(hr) )
815 // free already processed elements
816 FreeTargetOptions(*cOptions, *cOptionCount);
819 else
821 // empty array
822 *cOptions = NULL;
823 *cOptionCount = 0;
824 return NOERROR;
827 else if( VT_UNKNOWN == V_VT(options) )
829 // coerce object into a string and parse it
830 VARIANT v_name;
831 VariantInit(&v_name);
832 hr = VariantChangeType(&v_name, options, 0, VT_BSTR);
833 if( SUCCEEDED(hr) )
835 hr = parseStringOptions(codePage, V_BSTR(&v_name), cOptions, cOptionCount);
836 VariantClear(&v_name);
839 else if( VT_BSTR == V_VT(options) )
841 hr = parseStringOptions(codePage, V_BSTR(options), cOptions, cOptionCount);
843 return hr;
847 ** use VARIANT rather than a SAFEARRAY as argument type
848 ** for compatibility with some scripting language (JScript)
851 STDMETHODIMP VLCControl::addTarget( BSTR uri, VARIANT options, enum VLCPlaylistMode mode, int position)
853 if( 0 == SysStringLen(uri) )
854 return E_INVALIDARG;
856 int i_vlc;
857 HRESULT hr = _p_instance->getVLCObject(&i_vlc);
858 if( SUCCEEDED(hr) )
860 char *cUri = CStrFromBSTR(CP_UTF8, uri);
861 if( NULL == cUri )
862 return E_OUTOFMEMORY;
864 int cOptionsCount;
865 char **cOptions;
867 if( FAILED(CreateTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
868 return E_INVALIDARG;
870 if( VLC_SUCCESS <= VLC_AddTarget(i_vlc, cUri, (const char **)cOptions, cOptionsCount, mode, position) )
872 hr = NOERROR;
873 if( mode & PLAYLIST_GO )
874 _p_instance->fireOnPlayEvent();
876 else
878 hr = E_FAIL;
879 if( mode & PLAYLIST_GO )
880 _p_instance->fireOnStopEvent();
883 FreeTargetOptions(cOptions, cOptionsCount);
884 CoTaskMemFree(cUri);
886 return hr;
889 STDMETHODIMP VLCControl::get_PlaylistIndex(int *index)
891 if( NULL == index )
892 return E_POINTER;
894 int i_vlc;
895 HRESULT result = _p_instance->getVLCObject(&i_vlc);
896 if( SUCCEEDED(result) )
898 *index = VLC_PlaylistIndex(i_vlc);
899 return NOERROR;
901 *index = 0;
902 return result;
905 STDMETHODIMP VLCControl::get_PlaylistCount(int *count)
907 int i_vlc;
908 HRESULT result = _p_instance->getVLCObject(&i_vlc);
909 if( SUCCEEDED(result) )
911 *count = VLC_PlaylistNumberOfItems(i_vlc);
912 return NOERROR;
914 *count = 0;
915 return result;
918 STDMETHODIMP VLCControl::playlistNext(void)
920 int i_vlc;
921 HRESULT result = _p_instance->getVLCObject(&i_vlc);
922 if( SUCCEEDED(result) )
924 VLC_PlaylistNext(i_vlc);
925 return NOERROR;
927 return result;
930 STDMETHODIMP VLCControl::playlistPrev(void)
932 int i_vlc;
933 HRESULT result = _p_instance->getVLCObject(&i_vlc);
934 if( SUCCEEDED(result) )
936 VLC_PlaylistPrev(i_vlc);
937 return NOERROR;
939 return result;
942 STDMETHODIMP VLCControl::playlistClear(void)
944 int i_vlc;
945 HRESULT result = _p_instance->getVLCObject(&i_vlc);
946 if( SUCCEEDED(result) )
948 VLC_PlaylistClear(i_vlc);
949 return NOERROR;
951 return result;
954 STDMETHODIMP VLCControl::get_VersionInfo(BSTR *version)
956 if( NULL == version )
957 return E_POINTER;
959 const char *versionStr = VLC_Version();
960 if( NULL != versionStr )
962 *version = BSTRFromCStr(CP_UTF8, versionStr);
964 return NULL == *version ? E_OUTOFMEMORY : NOERROR;
966 *version = NULL;
967 return E_FAIL;
970 STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
972 if( NULL == mrl )
973 return E_POINTER;
975 *mrl = SysAllocStringLen(_p_instance->getMRL(),
976 SysStringLen(_p_instance->getMRL()));
977 return NOERROR;
980 STDMETHODIMP VLCControl::put_MRL(BSTR mrl)
982 _p_instance->setMRL(mrl);
984 return S_OK;
987 STDMETHODIMP VLCControl::get_AutoPlay(VARIANT_BOOL *autoplay)
989 if( NULL == autoplay )
990 return E_POINTER;
992 *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
993 return S_OK;
996 STDMETHODIMP VLCControl::put_AutoPlay(VARIANT_BOOL autoplay)
998 _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
999 return S_OK;
1002 STDMETHODIMP VLCControl::get_AutoLoop(VARIANT_BOOL *autoloop)
1004 if( NULL == autoloop )
1005 return E_POINTER;
1007 *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
1008 return S_OK;
1011 STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
1013 _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
1014 return S_OK;