/*****************************************************************************
* vlccontrol.cpp: ActiveX control for VLC
*****************************************************************************
- * Copyright (C) 2005 VideoLAN
+ * Copyright (C) 2005 the VideoLAN team
*
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "plugin.h"
return NOERROR;
}
return E_UNEXPECTED;
-}
+};
STDMETHODIMP VLCControl::get_Playing(VARIANT_BOOL *isPlaying)
{
return E_UNEXPECTED;
};
-STDMETHODIMP VLCControl::put_Playing(VARIANT_BOOL isPlaying)
-{
- int i_vlc = _p_instance->getVLCObject();
- if( i_vlc )
- {
- if( VARIANT_FALSE == isPlaying )
- {
- if( VLC_IsPlaying(i_vlc) )
- VLC_Stop(i_vlc);
- }
- else
- {
- if( ! VLC_IsPlaying(i_vlc) )
- VLC_Play(i_vlc);
- }
- return NOERROR;
- }
- return E_UNEXPECTED;
-};
-
STDMETHODIMP VLCControl::get_Position(float *position)
{
if( NULL == position )
return E_UNEXPECTED;
};
-STDMETHODIMP VLCControl::setVariable( BSTR name, VARIANT value)
+STDMETHODIMP VLCControl::setVariable(BSTR name, VARIANT value)
{
if( 0 == SysStringLen(name) )
return E_INVALIDARG;
switch( i_type )
{
case VLC_VAR_BOOL:
- hr = VariantChangeType(&value, &arg, 0, VT_BOOL);
+ hr = VariantChangeType(&arg, &value, 0, VT_BOOL);
if( SUCCEEDED(hr) )
val.b_bool = (VARIANT_TRUE == V_BOOL(&arg)) ? VLC_TRUE : VLC_FALSE;
break;
case VLC_VAR_INTEGER:
case VLC_VAR_HOTKEY:
- hr = VariantChangeType(&value, &arg, 0, VT_I4);
+ hr = VariantChangeType(&arg, &value, 0, VT_I4);
if( SUCCEEDED(hr) )
val.i_int = V_I4(&arg);
break;
case VLC_VAR_FLOAT:
- hr = VariantChangeType(&value, &arg, 0, VT_R4);
+ hr = VariantChangeType(&arg, &value, 0, VT_R4);
if( SUCCEEDED(hr) )
val.f_float = V_R4(&arg);
break;
case VLC_VAR_FILE:
case VLC_VAR_DIRECTORY:
case VLC_VAR_VARIABLE:
- hr = VariantChangeType(&value, &arg, 0, VT_BSTR);
+ hr = VariantChangeType(&arg, &value, 0, VT_BSTR);
if( SUCCEEDED(hr) )
{
+ i_type = VLC_VAR_STRING;
val.psz_string = CStrFromBSTR(codePage, V_BSTR(&arg));
VariantClear(&arg);
}
case VLC_VAR_TIME:
// use a double value to represent time (base is expressed in seconds)
- hr = VariantChangeType(&value, &arg, 0, VT_R8);
+ hr = VariantChangeType(&arg, &value, 0, VT_R8);
if( SUCCEEDED(hr) )
val.i_time = (signed __int64)(V_R8(&arg)*1000000.0);
break;
hr = (VLC_SUCCESS == VLC_VariableSet(i_vlc, psz_varname, val)) ? NOERROR : E_FAIL;
if( (VLC_VAR_STRING == i_type) && (NULL != val.psz_string) )
- free(val.psz_string);
+ CoTaskMemFree(val.psz_string);
}
- free(psz_varname);
+ CoTaskMemFree(psz_varname);
return hr;
}
STDMETHODIMP VLCControl::getVariable( BSTR name, VARIANT *value)
{
- if( 0 == SysStringLen(name) )
- return E_INVALIDARG;
-
if( NULL == value )
return E_POINTER;
+ VariantInit(value);
+
+ if( 0 == SysStringLen(name) )
+ return E_INVALIDARG;
+
int i_vlc = _p_instance->getVLCObject();
if( i_vlc )
{
- int codePage = _p_instance->getCodePage();
+ UINT codePage = _p_instance->getCodePage();
char *psz_varname = CStrFromBSTR(codePage, name);
if( NULL == psz_varname )
return E_OUTOFMEMORY;
case VLC_VAR_VARIABLE:
V_VT(value) = VT_BSTR;
V_BSTR(value) = BSTRFromCStr(codePage, val.psz_string);
- free(val.psz_string);
+ if( NULL != val.psz_string)
+ free(val.psz_string);
break;
case VLC_VAR_TIME:
hr = DISP_E_TYPEMISMATCH;
}
}
- free(psz_varname);
+ CoTaskMemFree(psz_varname);
return hr;
}
return E_UNEXPECTED;
static void freeTargetOptions(char **cOptions, int cOptionCount)
{
// clean up
- for( long pos=0; pos<cOptionCount; ++pos )
+ if( NULL != cOptions )
{
- char *cOption = cOptions[pos];
- if( NULL != cOption )
- free(cOption);
- else
- break;
+ for( int pos=0; pos<cOptionCount; ++pos )
+ {
+ char *cOption = cOptions[pos];
+ if( NULL != cOption )
+ CoTaskMemFree(cOption);
+ else
+ break;
+ }
+ CoTaskMemFree(cOptions);
}
- if( NULL != cOptions )
- free(cOptions);
};
static HRESULT createTargetOptions(int codePage, VARIANT *options, char ***cOptions, int *cOptionCount)
long capacity = 16;
VARIANT option;
- *cOptions = (char **)malloc(capacity*sizeof(char *));
+ *cOptions = (char **)CoTaskMemAlloc(capacity*sizeof(char *));
if( NULL != *cOptions )
{
ZeroMemory(*cOptions, sizeof(char *)*capacity);
++pos;
if( pos == capacity )
{
- char **moreOptions = (char **)realloc(*cOptions, (capacity+16)*sizeof(char *));
+ char **moreOptions = (char **)CoTaskMemRealloc(*cOptions, (capacity+16)*sizeof(char *));
if( NULL != moreOptions )
{
ZeroMemory(moreOptions+capacity, sizeof(char *)*16);
}
}
else
- hr = E_OUTOFMEMORY;
+ hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
+ E_OUTOFMEMORY : E_INVALIDARG;
}
else
hr = E_INVALIDARG;
}
else
hr = E_OUTOFMEMORY;
+
enumVar->Release();
}
}
SafeArrayGetUBound(array, 1, &uBound);
// have we got any options
- if( uBound > lBound )
+ if( uBound >= lBound )
{
VARTYPE vType;
- HRESULT hr = SafeArrayGetVartype(array, &vType);
+ hr = SafeArrayGetVartype(array, &vType);
if( FAILED(hr) )
return hr;
// marshall options into an array of C strings
if( VT_VARIANT == vType )
{
- *cOptions = (char **)malloc(sizeof(char *)*(uBound-lBound));
- if( NULL != options )
+ *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
+ if( NULL == *cOptions )
return E_OUTOFMEMORY;
- for(pos=lBound; SUCCEEDED(hr) && (pos<uBound); ++pos )
+ ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
+ for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
{
VARIANT option;
hr = SafeArrayGetElement(array, &pos, &option);
char *cOption = CStrFromBSTR(codePage, V_BSTR(&option));
(*cOptions)[pos-lBound] = cOption;
if( NULL == cOption )
- hr = E_OUTOFMEMORY;
+ hr = ( SysStringLen(V_BSTR(&option)) > 0 ) ?
+ E_OUTOFMEMORY : E_INVALIDARG;
}
else
hr = E_INVALIDARG;
}
else if( VT_BSTR == vType )
{
- *cOptions = (char **)malloc(sizeof(char *)*(uBound-lBound));
- if( NULL != options )
+ *cOptions = (char **)CoTaskMemAlloc(sizeof(char *)*(uBound-lBound+1));
+ if( NULL == *cOptions )
return E_OUTOFMEMORY;
- ZeroMemory(cOptions, sizeof(char *)*(uBound-lBound));
- for(pos=lBound; SUCCEEDED(hr) && (pos<uBound); ++pos )
+ ZeroMemory(*cOptions, sizeof(char *)*(uBound-lBound+1));
+ for(pos=lBound; (pos<=uBound) && SUCCEEDED(hr); ++pos )
{
BSTR option;
hr = SafeArrayGetElement(array, &pos, &option);
if( SUCCEEDED(hr) )
{
char *cOption = CStrFromBSTR(codePage, option);
+
(*cOptions)[pos-lBound] = cOption;
if( NULL == cOption )
- hr = E_OUTOFMEMORY;
+ hr = ( SysStringLen(option) > 0 ) ?
+ E_OUTOFMEMORY : E_INVALIDARG;
SysFreeString(option);
}
}
}
- else
+ else
+ {
// unsupported type
return E_INVALIDARG;
+ }
*cOptionCount = pos-lBound;
if( FAILED(hr) )
int i_vlc = _p_instance->getVLCObject();
if( i_vlc )
{
- int codePage = _p_instance->getCodePage();
- char *cUri = CStrFromBSTR(codePage, uri);
+ char *cUri = CStrFromBSTR(CP_UTF8, uri);
if( NULL == cUri )
return E_OUTOFMEMORY;
int cOptionsCount;
char **cOptions;
- if( FAILED(createTargetOptions(codePage, &options, &cOptions, &cOptionsCount)) )
+ if( FAILED(createTargetOptions(CP_UTF8, &options, &cOptions, &cOptionsCount)) )
return E_INVALIDARG;
if( VLC_SUCCESS <= VLC_AddTarget(i_vlc, cUri, (const char **)cOptions, cOptionsCount, mode, position) )
{
hr = NOERROR;
- if( mode & VLCPlayListGo )
+ if( mode & PLAYLIST_GO )
_p_instance->fireOnPlayEvent();
}
else
{
hr = E_FAIL;
- if( mode & VLCPlayListGo )
+ if( mode & PLAYLIST_GO )
_p_instance->fireOnStopEvent();
}
freeTargetOptions(cOptions, cOptionsCount);
- free(cUri);
+ CoTaskMemFree(cUri);
}
return hr;
};
*count = VLC_PlaylistNumberOfItems(i_vlc);
return NOERROR;
}
+ *count = 0;
return E_UNEXPECTED;
};
return E_FAIL;
};
+STDMETHODIMP VLCControl::get_MRL(BSTR *mrl)
+{
+ if( NULL == mrl )
+ return E_POINTER;
+
+ *mrl = SysAllocStringLen(_p_instance->getMRL(),
+ SysStringLen(_p_instance->getMRL()));
+ return NOERROR;
+};
+
+STDMETHODIMP VLCControl::put_MRL(BSTR mrl)
+{
+ _p_instance->setMRL(mrl);
+
+ return S_OK;
+};
+
+STDMETHODIMP VLCControl::get_AutoPlay(VARIANT_BOOL *autoplay)
+{
+ if( NULL == autoplay )
+ return E_POINTER;
+
+ *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
+ return S_OK;
+};
+
+STDMETHODIMP VLCControl::put_AutoPlay(VARIANT_BOOL autoplay)
+{
+ _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
+ return S_OK;
+};
+
+STDMETHODIMP VLCControl::get_AutoLoop(VARIANT_BOOL *autoloop)
+{
+ if( NULL == autoloop )
+ return E_POINTER;
+
+ *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
+ return S_OK;
+};
+
+STDMETHODIMP VLCControl::put_AutoLoop(VARIANT_BOOL autoloop)
+{
+ _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
+ return S_OK;
+};
+