vlccontrol2.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:67k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * vlccontrol2.cpp: ActiveX control for VLC
  3.  *****************************************************************************
  4.  * Copyright (C) 2006 the VideoLAN team
  5.  *
  6.  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
  7.  *          Jean-Paul Saman <jpsaman _at_ m2x _dot_ nl>
  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
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  22.  *****************************************************************************/
  23. #include "plugin.h"
  24. #include "vlccontrol2.h"
  25. #include "vlccontrol.h"
  26. #include "utils.h"
  27. #include <stdio.h>
  28. #include <shlwapi.h>
  29. #include <wininet.h>
  30. #include <tchar.h>
  31. using namespace std;
  32. VLCAudio::~VLCAudio()
  33. {
  34.     if( _p_typeinfo )
  35.         _p_typeinfo->Release();
  36. };
  37. HRESULT VLCAudio::loadTypeInfo(void)
  38. {
  39.     HRESULT hr = NOERROR;
  40.     if( NULL == _p_typeinfo )
  41.     {
  42.         ITypeLib *p_typelib;
  43.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  44.         if( SUCCEEDED(hr) )
  45.         {
  46.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCAudio, &_p_typeinfo);
  47.             if( FAILED(hr) )
  48.             {
  49.                 _p_typeinfo = NULL;
  50.             }
  51.             p_typelib->Release();
  52.         }
  53.     }
  54.     return hr;
  55. };
  56. STDMETHODIMP VLCAudio::GetTypeInfoCount(UINT* pctInfo)
  57. {
  58.     if( NULL == pctInfo )
  59.         return E_INVALIDARG;
  60.     if( SUCCEEDED(loadTypeInfo()) )
  61.         *pctInfo = 1;
  62.     else
  63.         *pctInfo = 0;
  64.     return NOERROR;
  65. };
  66. STDMETHODIMP VLCAudio::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  67. {
  68.     if( NULL == ppTInfo )
  69.         return E_INVALIDARG;
  70.     if( SUCCEEDED(loadTypeInfo()) )
  71.     {
  72.         _p_typeinfo->AddRef();
  73.         *ppTInfo = _p_typeinfo;
  74.         return NOERROR;
  75.     }
  76.     *ppTInfo = NULL;
  77.     return E_NOTIMPL;
  78. };
  79. STDMETHODIMP VLCAudio::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  80.         UINT cNames, LCID lcid, DISPID* rgDispID)
  81. {
  82.     if( SUCCEEDED(loadTypeInfo()) )
  83.     {
  84.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  85.     }
  86.     return E_NOTIMPL;
  87. };
  88. STDMETHODIMP VLCAudio::Invoke(DISPID dispIdMember, REFIID riid,
  89.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  90.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  91. {
  92.     if( SUCCEEDED(loadTypeInfo()) )
  93.     {
  94.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  95.                 pVarResult, pExcepInfo, puArgErr);
  96.     }
  97.     return E_NOTIMPL;
  98. };
  99. STDMETHODIMP VLCAudio::get_mute(VARIANT_BOOL* mute)
  100. {
  101.     if( NULL == mute )
  102.         return E_POINTER;
  103.     libvlc_instance_t* p_libvlc;
  104.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  105.     if( SUCCEEDED(hr) )
  106.     {
  107.         libvlc_exception_t ex;
  108.         libvlc_exception_init(&ex);
  109.         *mute = libvlc_audio_get_mute(p_libvlc, &ex) ?
  110.                         VARIANT_TRUE : VARIANT_FALSE;
  111.         if( libvlc_exception_raised(&ex) )
  112.         {
  113.             _p_instance->setErrorInfo(IID_IVLCAudio,
  114.                          libvlc_exception_get_message(&ex));
  115.             libvlc_exception_clear(&ex);
  116.             return E_FAIL;
  117.         }
  118.         return NOERROR;
  119.     }
  120.     return hr;
  121. };
  122. STDMETHODIMP VLCAudio::put_mute(VARIANT_BOOL mute)
  123. {
  124.     libvlc_instance_t* p_libvlc;
  125.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  126.     if( SUCCEEDED(hr) )
  127.     {
  128.         libvlc_exception_t ex;
  129.         libvlc_exception_init(&ex);
  130.         libvlc_audio_set_mute(p_libvlc, VARIANT_FALSE != mute, &ex);
  131.         if( libvlc_exception_raised(&ex) )
  132.         {
  133.             _p_instance->setErrorInfo(IID_IVLCAudio,
  134.                          libvlc_exception_get_message(&ex));
  135.             libvlc_exception_clear(&ex);
  136.             return E_FAIL;
  137.         }
  138.         return NOERROR;
  139.     }
  140.     return hr;
  141. };
  142. STDMETHODIMP VLCAudio::get_volume(long* volume)
  143. {
  144.     if( NULL == volume )
  145.         return E_POINTER;
  146.     libvlc_instance_t* p_libvlc;
  147.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  148.     if( SUCCEEDED(hr) )
  149.     {
  150.         libvlc_exception_t ex;
  151.         libvlc_exception_init(&ex);
  152.         *volume = libvlc_audio_get_volume(p_libvlc, &ex);
  153.         if( libvlc_exception_raised(&ex) )
  154.         {
  155.             _p_instance->setErrorInfo(IID_IVLCAudio,
  156.                          libvlc_exception_get_message(&ex));
  157.             libvlc_exception_clear(&ex);
  158.             return E_FAIL;
  159.         }
  160.         return NOERROR;
  161.     }
  162.     return hr;
  163. };
  164. STDMETHODIMP VLCAudio::put_volume(long volume)
  165. {
  166.     libvlc_instance_t* p_libvlc;
  167.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  168.     if( SUCCEEDED(hr) )
  169.     {
  170.         libvlc_exception_t ex;
  171.         libvlc_exception_init(&ex);
  172.         libvlc_audio_set_volume(p_libvlc, volume, &ex);
  173.         if( libvlc_exception_raised(&ex) )
  174.         {
  175.             _p_instance->setErrorInfo(IID_IVLCAudio,
  176.                          libvlc_exception_get_message(&ex));
  177.             libvlc_exception_clear(&ex);
  178.             return E_FAIL;
  179.         }
  180.         return NOERROR;
  181.     }
  182.     return hr;
  183. };
  184. STDMETHODIMP VLCAudio::get_track(long* track)
  185. {
  186.     if( NULL == track )
  187.         return E_POINTER;
  188.     libvlc_media_player_t* p_md;
  189.     HRESULT hr = _p_instance->getMD(&p_md);
  190.     if( SUCCEEDED(hr) )
  191.     {
  192.         libvlc_exception_t ex;
  193.         libvlc_exception_init(&ex);
  194.         *track = libvlc_audio_get_track(p_md, &ex);
  195.         if( libvlc_exception_raised(&ex) )
  196.         {
  197.             _p_instance->setErrorInfo(IID_IVLCAudio,
  198.                          libvlc_exception_get_message(&ex));
  199.             libvlc_exception_clear(&ex);
  200.             return E_FAIL;
  201.         }
  202.         return NOERROR;
  203.     }
  204.     return hr;
  205. };
  206. STDMETHODIMP VLCAudio::put_track(long track)
  207. {
  208.     libvlc_media_player_t *p_md;
  209.     HRESULT hr = _p_instance->getMD(&p_md);
  210.     if( SUCCEEDED(hr) )
  211.     {
  212.         libvlc_exception_t ex;
  213.         libvlc_exception_init(&ex);
  214.         libvlc_audio_set_track(p_md, track, &ex);
  215.         if( libvlc_exception_raised(&ex) )
  216.         {
  217.             _p_instance->setErrorInfo(IID_IVLCAudio,
  218.                          libvlc_exception_get_message(&ex));
  219.             libvlc_exception_clear(&ex);
  220.             return E_FAIL;
  221.         }
  222.         return NOERROR;
  223.     }
  224.     return hr;
  225. };
  226. STDMETHODIMP VLCAudio::get_channel(long *channel)
  227. {
  228.     if( NULL == channel )
  229.         return E_POINTER;
  230.     libvlc_instance_t* p_libvlc;
  231.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  232.     if( SUCCEEDED(hr) )
  233.     {
  234.         libvlc_exception_t ex;
  235.         libvlc_exception_init(&ex);
  236.         *channel = libvlc_audio_get_channel(p_libvlc, &ex);
  237.         if( libvlc_exception_raised(&ex) )
  238.         {
  239.             _p_instance->setErrorInfo(IID_IVLCAudio,
  240.                         libvlc_exception_get_message(&ex));
  241.             libvlc_exception_clear(&ex);
  242.             return E_FAIL;
  243.         }
  244.         return NOERROR;
  245.     }
  246.     return hr;
  247. };
  248. STDMETHODIMP VLCAudio::put_channel(long channel)
  249. {
  250.     libvlc_instance_t* p_libvlc;
  251.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  252.     if( SUCCEEDED(hr) )
  253.     {
  254.         libvlc_exception_t ex;
  255.         libvlc_exception_init(&ex);
  256.         libvlc_audio_set_channel(p_libvlc, channel, &ex);
  257.         if( libvlc_exception_raised(&ex) )
  258.         {
  259.             _p_instance->setErrorInfo(IID_IVLCAudio,
  260.                          libvlc_exception_get_message(&ex));
  261.             libvlc_exception_clear(&ex);
  262.             return E_FAIL;
  263.         }
  264.         return NOERROR;
  265.     }
  266.     return hr;
  267. };
  268. STDMETHODIMP VLCAudio::toggleMute()
  269. {
  270.     libvlc_instance_t* p_libvlc;
  271.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  272.     if( SUCCEEDED(hr) )
  273.     {
  274.         libvlc_exception_t ex;
  275.         libvlc_exception_init(&ex);
  276.         libvlc_audio_toggle_mute(p_libvlc, &ex);
  277.         if( libvlc_exception_raised(&ex) )
  278.         {
  279.             _p_instance->setErrorInfo(IID_IVLCAudio,
  280.                          libvlc_exception_get_message(&ex));
  281.             libvlc_exception_clear(&ex);
  282.             return E_FAIL;
  283.         }
  284.         return NOERROR;
  285.     }
  286.     return hr;
  287. };
  288. /*******************************************************************************/
  289. VLCInput::~VLCInput()
  290. {
  291.     if( _p_typeinfo )
  292.         _p_typeinfo->Release();
  293. };
  294. HRESULT VLCInput::loadTypeInfo(void)
  295. {
  296.     HRESULT hr = NOERROR;
  297.     if( NULL == _p_typeinfo )
  298.     {
  299.         ITypeLib *p_typelib;
  300.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  301.         if( SUCCEEDED(hr) )
  302.         {
  303.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCInput, &_p_typeinfo);
  304.             if( FAILED(hr) )
  305.             {
  306.                 _p_typeinfo = NULL;
  307.             }
  308.             p_typelib->Release();
  309.         }
  310.     }
  311.     return hr;
  312. };
  313. STDMETHODIMP VLCInput::GetTypeInfoCount(UINT* pctInfo)
  314. {
  315.     if( NULL == pctInfo )
  316.         return E_INVALIDARG;
  317.     if( SUCCEEDED(loadTypeInfo()) )
  318.         *pctInfo = 1;
  319.     else
  320.         *pctInfo = 0;
  321.     return NOERROR;
  322. };
  323. STDMETHODIMP VLCInput::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  324. {
  325.     if( NULL == ppTInfo )
  326.         return E_INVALIDARG;
  327.     if( SUCCEEDED(loadTypeInfo()) )
  328.     {
  329.         _p_typeinfo->AddRef();
  330.         *ppTInfo = _p_typeinfo;
  331.         return NOERROR;
  332.     }
  333.     *ppTInfo = NULL;
  334.     return E_NOTIMPL;
  335. };
  336. STDMETHODIMP VLCInput::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  337.         UINT cNames, LCID lcid, DISPID* rgDispID)
  338. {
  339.     if( SUCCEEDED(loadTypeInfo()) )
  340.     {
  341.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  342.     }
  343.     return E_NOTIMPL;
  344. };
  345. STDMETHODIMP VLCInput::Invoke(DISPID dispIdMember, REFIID riid,
  346.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  347.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  348. {
  349.     if( SUCCEEDED(loadTypeInfo()) )
  350.     {
  351.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  352.                 pVarResult, pExcepInfo, puArgErr);
  353.     }
  354.     return E_NOTIMPL;
  355. };
  356. STDMETHODIMP VLCInput::get_length(double* length)
  357. {
  358.     if( NULL == length )
  359.         return E_POINTER;
  360.     *length = 0;
  361.     libvlc_media_player_t *p_md;
  362.     HRESULT hr = _p_instance->getMD(&p_md);
  363.     if( SUCCEEDED(hr) )
  364.     {
  365.         libvlc_exception_t ex;
  366.         libvlc_exception_init(&ex);
  367.         *length = (double)libvlc_media_player_get_length(p_md, &ex);
  368.         if( ! libvlc_exception_raised(&ex) )
  369.         {
  370.             return NOERROR;
  371.         }
  372.         _p_instance->setErrorInfo(IID_IVLCInput,
  373.                      libvlc_exception_get_message(&ex));
  374.         libvlc_exception_clear(&ex);
  375.         return E_FAIL;
  376.     }
  377.     return hr;
  378. };
  379. STDMETHODIMP VLCInput::get_position(double* position)
  380. {
  381.     if( NULL == position )
  382.         return E_POINTER;
  383.     *position = 0.0f;
  384.     libvlc_media_player_t *p_md;
  385.     HRESULT hr = _p_instance->getMD(&p_md);
  386.     if( SUCCEEDED(hr) )
  387.     {
  388.         libvlc_exception_t ex;
  389.         libvlc_exception_init(&ex);
  390.         *position = libvlc_media_player_get_position(p_md, &ex);
  391.         if( ! libvlc_exception_raised(&ex) )
  392.         {
  393.             return NOERROR;
  394.         }
  395.         _p_instance->setErrorInfo(IID_IVLCInput,
  396.                      libvlc_exception_get_message(&ex));
  397.         libvlc_exception_clear(&ex);
  398.         return E_FAIL;
  399.     }
  400.     return hr;
  401. };
  402. STDMETHODIMP VLCInput::put_position(double position)
  403. {
  404.     libvlc_media_player_t *p_md;
  405.     HRESULT hr = _p_instance->getMD(&p_md);
  406.     if( SUCCEEDED(hr) )
  407.     {
  408.         libvlc_exception_t ex;
  409.         libvlc_exception_init(&ex);
  410.         libvlc_media_player_set_position(p_md, position, &ex);
  411.         if( ! libvlc_exception_raised(&ex) )
  412.         {
  413.             return NOERROR;
  414.         }
  415.         _p_instance->setErrorInfo(IID_IVLCInput,
  416.                      libvlc_exception_get_message(&ex));
  417.         libvlc_exception_clear(&ex);
  418.         return E_FAIL;
  419.     }
  420.     return hr;
  421. };
  422. STDMETHODIMP VLCInput::get_time(double* time)
  423. {
  424.     if( NULL == time )
  425.         return E_POINTER;
  426.     libvlc_media_player_t *p_md;
  427.     HRESULT hr = _p_instance->getMD(&p_md);
  428.     if( SUCCEEDED(hr) )
  429.     {
  430.         libvlc_exception_t ex;
  431.         libvlc_exception_init(&ex);
  432.         *time = (double)libvlc_media_player_get_time(p_md, &ex);
  433.         if( ! libvlc_exception_raised(&ex) )
  434.         {
  435.             return NOERROR;
  436.         }
  437.         _p_instance->setErrorInfo(IID_IVLCInput,
  438.                      libvlc_exception_get_message(&ex));
  439.         libvlc_exception_clear(&ex);
  440.         return E_FAIL;
  441.     }
  442.     return hr;
  443. };
  444. STDMETHODIMP VLCInput::put_time(double time)
  445. {
  446.     libvlc_media_player_t *p_md;
  447.     HRESULT hr = _p_instance->getMD(&p_md);
  448.     if( SUCCEEDED(hr) )
  449.     {
  450.         libvlc_exception_t ex;
  451.         libvlc_exception_init(&ex);
  452.         libvlc_media_player_set_time(p_md, (int64_t)time, &ex);
  453.         if( ! libvlc_exception_raised(&ex) )
  454.         {
  455.             return NOERROR;
  456.         }
  457.         _p_instance->setErrorInfo(IID_IVLCInput,
  458.                      libvlc_exception_get_message(&ex));
  459.         libvlc_exception_clear(&ex);
  460.         return E_FAIL;
  461.     }
  462.     return hr;
  463. };
  464. STDMETHODIMP VLCInput::get_state(long* state)
  465. {
  466.     if( NULL == state )
  467.         return E_POINTER;
  468.     libvlc_media_player_t *p_md;
  469.     HRESULT hr = _p_instance->getMD(&p_md);
  470.     if( SUCCEEDED(hr) )
  471.     {
  472.         libvlc_exception_t ex;
  473.         libvlc_exception_init(&ex);
  474.         *state = libvlc_media_player_get_state(p_md, &ex);
  475.         if( ! libvlc_exception_raised(&ex) )
  476.         {
  477.             return NOERROR;
  478.         }
  479.         libvlc_exception_clear(&ex);
  480.         // don't fail, just return the idle state
  481.         *state = 0;
  482.         return NOERROR;
  483.     }
  484.     return hr;
  485. };
  486. STDMETHODIMP VLCInput::get_rate(double* rate)
  487. {
  488.     if( NULL == rate )
  489.         return E_POINTER;
  490.     libvlc_media_player_t *p_md;
  491.     HRESULT hr = _p_instance->getMD(&p_md);
  492.     if( SUCCEEDED(hr) )
  493.     {
  494.         libvlc_exception_t ex;
  495.         libvlc_exception_init(&ex);
  496.         *rate = libvlc_media_player_get_rate(p_md, &ex);
  497.         if( ! libvlc_exception_raised(&ex) )
  498.         {
  499.             return NOERROR;
  500.         }
  501.         _p_instance->setErrorInfo(IID_IVLCInput,
  502.                      libvlc_exception_get_message(&ex));
  503.         libvlc_exception_clear(&ex);
  504.         return E_FAIL;
  505.     }
  506.     return hr;
  507. };
  508. STDMETHODIMP VLCInput::put_rate(double rate)
  509. {
  510.     libvlc_media_player_t *p_md;
  511.     HRESULT hr = _p_instance->getMD(&p_md);
  512.     if( SUCCEEDED(hr) )
  513.     {
  514.         libvlc_exception_t ex;
  515.         libvlc_exception_init(&ex);
  516.         libvlc_media_player_set_rate(p_md, rate, &ex);
  517.         if( ! libvlc_exception_raised(&ex) )
  518.         {
  519.             return NOERROR;
  520.         }
  521.         _p_instance->setErrorInfo(IID_IVLCInput,
  522.                      libvlc_exception_get_message(&ex));
  523.         libvlc_exception_clear(&ex);
  524.         return E_FAIL;
  525.     }
  526.     return hr;
  527. };
  528. STDMETHODIMP VLCInput::get_fps(double* fps)
  529. {
  530.     if( NULL == fps )
  531.         return E_POINTER;
  532.     *fps = 0.0;
  533.     libvlc_media_player_t *p_md;
  534.     HRESULT hr = _p_instance->getMD(&p_md);
  535.     if( SUCCEEDED(hr) )
  536.     {
  537.         libvlc_exception_t ex;
  538.         libvlc_exception_init(&ex);
  539.         *fps = libvlc_media_player_get_fps(p_md, &ex);
  540.         if( ! libvlc_exception_raised(&ex) )
  541.         {
  542.             return NOERROR;
  543.         }
  544.         _p_instance->setErrorInfo(IID_IVLCInput,
  545.                      libvlc_exception_get_message(&ex));
  546.         libvlc_exception_clear(&ex);
  547.         return E_FAIL;
  548.     }
  549.     return hr;
  550. };
  551. STDMETHODIMP VLCInput::get_hasVout(VARIANT_BOOL* hasVout)
  552. {
  553.     if( NULL == hasVout )
  554.         return E_POINTER;
  555.     libvlc_media_player_t *p_md;
  556.     HRESULT hr = _p_instance->getMD(&p_md);
  557.     if( SUCCEEDED(hr) )
  558.     {
  559.         libvlc_exception_t ex;
  560.         libvlc_exception_init(&ex);
  561.         *hasVout = libvlc_media_player_has_vout(p_md, &ex) ?
  562.                                 VARIANT_TRUE : VARIANT_FALSE;
  563.         if( ! libvlc_exception_raised(&ex) )
  564.         {
  565.             return NOERROR;
  566.         }
  567.         _p_instance->setErrorInfo(IID_IVLCInput,
  568.                      libvlc_exception_get_message(&ex));
  569.         libvlc_exception_clear(&ex);
  570.         return E_FAIL;
  571.     }
  572.     return hr;
  573. };
  574. /*******************************************************************************/
  575. VLCLog::~VLCLog()
  576. {
  577.     delete _p_vlcmessages;
  578.     if( _p_log )
  579.         libvlc_log_close(_p_log, NULL);
  580.     if( _p_typeinfo )
  581.         _p_typeinfo->Release();
  582. };
  583. HRESULT VLCLog::loadTypeInfo(void)
  584. {
  585.     HRESULT hr = NOERROR;
  586.     if( NULL == _p_typeinfo )
  587.     {
  588.         ITypeLib *p_typelib;
  589.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  590.         if( SUCCEEDED(hr) )
  591.         {
  592.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCLog, &_p_typeinfo);
  593.             if( FAILED(hr) )
  594.             {
  595.                 _p_typeinfo = NULL;
  596.             }
  597.             p_typelib->Release();
  598.         }
  599.     }
  600.     return hr;
  601. };
  602. STDMETHODIMP VLCLog::GetTypeInfoCount(UINT* pctInfo)
  603. {
  604.     if( NULL == pctInfo )
  605.         return E_INVALIDARG;
  606.     if( SUCCEEDED(loadTypeInfo()) )
  607.         *pctInfo = 1;
  608.     else
  609.         *pctInfo = 0;
  610.     return NOERROR;
  611. };
  612. STDMETHODIMP VLCLog::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  613. {
  614.     if( NULL == ppTInfo )
  615.         return E_INVALIDARG;
  616.     if( SUCCEEDED(loadTypeInfo()) )
  617.     {
  618.         _p_typeinfo->AddRef();
  619.         *ppTInfo = _p_typeinfo;
  620.         return NOERROR;
  621.     }
  622.     *ppTInfo = NULL;
  623.     return E_NOTIMPL;
  624. };
  625. STDMETHODIMP VLCLog::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  626.         UINT cNames, LCID lcid, DISPID* rgDispID)
  627. {
  628.     if( SUCCEEDED(loadTypeInfo()) )
  629.     {
  630.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  631.     }
  632.     return E_NOTIMPL;
  633. };
  634. STDMETHODIMP VLCLog::Invoke(DISPID dispIdMember, REFIID riid,
  635.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  636.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  637. {
  638.     if( SUCCEEDED(loadTypeInfo()) )
  639.     {
  640.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  641.                 pVarResult, pExcepInfo, puArgErr);
  642.     }
  643.     return E_NOTIMPL;
  644. };
  645. STDMETHODIMP VLCLog::get_messages(IVLCMessages** obj)
  646. {
  647.     if( NULL == obj )
  648.         return E_POINTER;
  649.     *obj = _p_vlcmessages;
  650.     if( NULL != _p_vlcmessages )
  651.     {
  652.         _p_vlcmessages->AddRef();
  653.         return NOERROR;
  654.     }
  655.     return E_OUTOFMEMORY;
  656. };
  657. STDMETHODIMP VLCLog::get_verbosity(long* level)
  658. {
  659.     if( NULL == level )
  660.         return E_POINTER;
  661.     if( _p_log )
  662.     {
  663.         libvlc_instance_t* p_libvlc;
  664.         HRESULT hr = _p_instance->getVLC(&p_libvlc);
  665.         if( SUCCEEDED(hr) )
  666.         {
  667.             libvlc_exception_t ex;
  668.             libvlc_exception_init(&ex);
  669.             *level = libvlc_get_log_verbosity(p_libvlc, &ex);
  670.             if( libvlc_exception_raised(&ex) )
  671.             {
  672.                 _p_instance->setErrorInfo(IID_IVLCLog,
  673.                              libvlc_exception_get_message(&ex));
  674.                 libvlc_exception_clear(&ex);
  675.                 return E_FAIL;
  676.             }
  677.         }
  678.         return hr;
  679.     }
  680.     else
  681.     {
  682.         /* log is not enabled, return -1 */
  683.         *level = -1;
  684.         return NOERROR;
  685.     }
  686. };
  687. STDMETHODIMP VLCLog::put_verbosity(long verbosity)
  688. {
  689.     libvlc_exception_t ex;
  690.     libvlc_exception_init(&ex);
  691.     libvlc_instance_t* p_libvlc;
  692.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  693.     if( SUCCEEDED(hr) )
  694.     {
  695.         if( verbosity >= 0 )
  696.         {
  697.             if( ! _p_log )
  698.             {
  699.                 _p_log = libvlc_log_open(p_libvlc, &ex);
  700.                 if( libvlc_exception_raised(&ex) )
  701.                 {
  702.                     _p_instance->setErrorInfo(IID_IVLCLog,
  703.                                  libvlc_exception_get_message(&ex));
  704.                     libvlc_exception_clear(&ex);
  705.                     return E_FAIL;
  706.                 }
  707.             }
  708.             libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
  709.             if( libvlc_exception_raised(&ex) )
  710.             {
  711.                 _p_instance->setErrorInfo(IID_IVLCLog,
  712.                              libvlc_exception_get_message(&ex));
  713.                 libvlc_exception_clear(&ex);
  714.                 return E_FAIL;
  715.             }
  716.         }
  717.         else if( _p_log )
  718.         {
  719.             /* close log  when verbosity is set to -1 */
  720.             libvlc_log_close(_p_log, &ex);
  721.             _p_log = NULL;
  722.             if( libvlc_exception_raised(&ex) )
  723.             {
  724.                 _p_instance->setErrorInfo(IID_IVLCLog,
  725.                              libvlc_exception_get_message(&ex));
  726.                 libvlc_exception_clear(&ex);
  727.                 return E_FAIL;
  728.             }
  729.         }
  730.     }
  731.     return hr;
  732. };
  733. /*******************************************************************************/
  734. /* STL forward iterator used by VLCEnumIterator class to implement IEnumVARIANT */
  735. class VLCMessageSTLIterator
  736. {
  737. public:
  738.     VLCMessageSTLIterator(IVLCMessageIterator* iter) : iter(iter), msg(NULL)
  739.     {
  740.         // get first message
  741.         operator++();
  742.     };
  743.     VLCMessageSTLIterator(const VLCMessageSTLIterator& other)
  744.     {
  745.         iter = other.iter;
  746.         if( iter )
  747.             iter->AddRef();
  748.         msg = other.msg;
  749.         if( msg )
  750.             msg->AddRef();
  751.     };
  752.     virtual ~VLCMessageSTLIterator()
  753.     {
  754.         if( msg )
  755.             msg->Release();
  756.         if( iter )
  757.             iter->Release();
  758.     };
  759.     // we only need prefix ++ operator
  760.     VLCMessageSTLIterator& operator++()
  761.     {
  762.         VARIANT_BOOL hasNext = VARIANT_FALSE;
  763.         if( iter )
  764.         {
  765.             iter->get_hasNext(&hasNext);
  766.             if( msg )
  767.             {
  768.                 msg->Release();
  769.                 msg = NULL;
  770.             }
  771.             if( VARIANT_TRUE == hasNext ) {
  772.                 iter->next(&msg);
  773.             }
  774.         }
  775.         return *this;
  776.     };
  777.     VARIANT operator*() const
  778.     {
  779.         VARIANT v;
  780.         VariantInit(&v);
  781.         if( msg )
  782.         {
  783.             if( SUCCEEDED(msg->QueryInterface(IID_IDispatch,
  784.                           (LPVOID*)&V_DISPATCH(&v))) )
  785.             {
  786.                 V_VT(&v) = VT_DISPATCH;
  787.             }
  788.         }
  789.         return v;
  790.     };
  791.     bool operator==(const VLCMessageSTLIterator& other) const
  792.     {
  793.         return msg == other.msg;
  794.     };
  795.     bool operator!=(const VLCMessageSTLIterator& other) const
  796.     {
  797.         return msg != other.msg;
  798.     };
  799. private:
  800.     IVLCMessageIterator* iter;
  801.     IVLCMessage*         msg;
  802. };
  803. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  804. VLCMessages::~VLCMessages()
  805. {
  806.     if( _p_typeinfo )
  807.         _p_typeinfo->Release();
  808. };
  809. HRESULT VLCMessages::loadTypeInfo(void)
  810. {
  811.     HRESULT hr = NOERROR;
  812.     if( NULL == _p_typeinfo )
  813.     {
  814.         ITypeLib *p_typelib;
  815.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  816.         if( SUCCEEDED(hr) )
  817.         {
  818.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessages, &_p_typeinfo);
  819.             if( FAILED(hr) )
  820.             {
  821.                 _p_typeinfo = NULL;
  822.             }
  823.             p_typelib->Release();
  824.         }
  825.     }
  826.     return hr;
  827. };
  828. STDMETHODIMP VLCMessages::GetTypeInfoCount(UINT* pctInfo)
  829. {
  830.     if( NULL == pctInfo )
  831.         return E_INVALIDARG;
  832.     if( SUCCEEDED(loadTypeInfo()) )
  833.         *pctInfo = 1;
  834.     else
  835.         *pctInfo = 0;
  836.     return NOERROR;
  837. };
  838. STDMETHODIMP VLCMessages::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  839. {
  840.     if( NULL == ppTInfo )
  841.         return E_INVALIDARG;
  842.     if( SUCCEEDED(loadTypeInfo()) )
  843.     {
  844.         _p_typeinfo->AddRef();
  845.         *ppTInfo = _p_typeinfo;
  846.         return NOERROR;
  847.     }
  848.     *ppTInfo = NULL;
  849.     return E_NOTIMPL;
  850. };
  851. STDMETHODIMP VLCMessages::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  852.         UINT cNames, LCID lcid, DISPID* rgDispID)
  853. {
  854.     if( SUCCEEDED(loadTypeInfo()) )
  855.     {
  856.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  857.     }
  858.     return E_NOTIMPL;
  859. };
  860. STDMETHODIMP VLCMessages::Invoke(DISPID dispIdMember, REFIID riid,
  861.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  862.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  863. {
  864.     if( SUCCEEDED(loadTypeInfo()) )
  865.     {
  866.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  867.                 pVarResult, pExcepInfo, puArgErr);
  868.     }
  869.     return E_NOTIMPL;
  870. };
  871. STDMETHODIMP VLCMessages::get__NewEnum(LPUNKNOWN* _NewEnum)
  872. {
  873.     if( NULL == _NewEnum )
  874.         return E_POINTER;
  875.     IVLCMessageIterator* iter = NULL;
  876.     iterator(&iter);
  877.     *_NewEnum= new VLCEnumIterator<IID_IEnumVARIANT,
  878.                        IEnumVARIANT,
  879.                        VARIANT,
  880.                        VLCMessageSTLIterator>
  881.                        (VLCMessageSTLIterator(iter), VLCMessageSTLIterator(NULL));
  882.     return *_NewEnum ? S_OK : E_OUTOFMEMORY;
  883. };
  884. STDMETHODIMP VLCMessages::clear()
  885. {
  886.     libvlc_log_t *p_log = _p_vlclog->_p_log;
  887.     if( p_log )
  888.     {
  889.         libvlc_exception_t ex;
  890.         libvlc_exception_init(&ex);
  891.         libvlc_log_clear(p_log, &ex);
  892.         if( libvlc_exception_raised(&ex) )
  893.         {
  894.             _p_instance->setErrorInfo(IID_IVLCMessages,
  895.                          libvlc_exception_get_message(&ex));
  896.             libvlc_exception_clear(&ex);
  897.             return E_FAIL;
  898.         }
  899.     }
  900.     return NOERROR;
  901. };
  902. STDMETHODIMP VLCMessages::get_count(long* count)
  903. {
  904.     if( NULL == count )
  905.         return E_POINTER;
  906.     libvlc_log_t *p_log = _p_vlclog->_p_log;
  907.     if( p_log )
  908.     {
  909.         libvlc_exception_t ex;
  910.         libvlc_exception_init(&ex);
  911.         *count = libvlc_log_count(p_log, &ex);
  912.         if( libvlc_exception_raised(&ex) )
  913.         {
  914.             _p_instance->setErrorInfo(IID_IVLCMessages,
  915.                          libvlc_exception_get_message(&ex));
  916.             libvlc_exception_clear(&ex);
  917.             return E_FAIL;
  918.         }
  919.     }
  920.     else
  921.         *count = 0;
  922.     return S_OK;
  923. };
  924. STDMETHODIMP VLCMessages::iterator(IVLCMessageIterator** iter)
  925. {
  926.     if( NULL == iter )
  927.         return E_POINTER;
  928.     *iter = new VLCMessageIterator(_p_instance, _p_vlclog);
  929.     return *iter ? S_OK : E_OUTOFMEMORY;
  930. };
  931. /*******************************************************************************/
  932. VLCMessageIterator::VLCMessageIterator(VLCPlugin *p_instance, VLCLog* p_vlclog ) :
  933.     _p_instance(p_instance),
  934.     _p_typeinfo(NULL),
  935.     _refcount(1),
  936.     _p_vlclog(p_vlclog)
  937. {
  938.     if( p_vlclog->_p_log )
  939.     {
  940.         _p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
  941.     }
  942.     else
  943.         _p_iter = NULL;
  944. };
  945. VLCMessageIterator::~VLCMessageIterator()
  946. {
  947.     if( _p_iter )
  948.         libvlc_log_iterator_free(_p_iter, NULL);
  949.     if( _p_typeinfo )
  950.         _p_typeinfo->Release();
  951. };
  952. HRESULT VLCMessageIterator::loadTypeInfo(void)
  953. {
  954.     HRESULT hr = NOERROR;
  955.     if( NULL == _p_typeinfo )
  956.     {
  957.         ITypeLib *p_typelib;
  958.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  959.         if( SUCCEEDED(hr) )
  960.         {
  961.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessageIterator, &_p_typeinfo);
  962.             if( FAILED(hr) )
  963.             {
  964.                 _p_typeinfo = NULL;
  965.             }
  966.             p_typelib->Release();
  967.         }
  968.     }
  969.     return hr;
  970. };
  971. STDMETHODIMP VLCMessageIterator::GetTypeInfoCount(UINT* pctInfo)
  972. {
  973.     if( NULL == pctInfo )
  974.         return E_INVALIDARG;
  975.     if( SUCCEEDED(loadTypeInfo()) )
  976.         *pctInfo = 1;
  977.     else
  978.         *pctInfo = 0;
  979.     return NOERROR;
  980. };
  981. STDMETHODIMP VLCMessageIterator::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  982. {
  983.     if( NULL == ppTInfo )
  984.         return E_INVALIDARG;
  985.     if( SUCCEEDED(loadTypeInfo()) )
  986.     {
  987.         _p_typeinfo->AddRef();
  988.         *ppTInfo = _p_typeinfo;
  989.         return NOERROR;
  990.     }
  991.     *ppTInfo = NULL;
  992.     return E_NOTIMPL;
  993. };
  994. STDMETHODIMP VLCMessageIterator::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  995.         UINT cNames, LCID lcid, DISPID* rgDispID)
  996. {
  997.     if( SUCCEEDED(loadTypeInfo()) )
  998.     {
  999.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  1000.     }
  1001.     return E_NOTIMPL;
  1002. };
  1003. STDMETHODIMP VLCMessageIterator::Invoke(DISPID dispIdMember, REFIID riid,
  1004.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  1005.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  1006. {
  1007.     if( SUCCEEDED(loadTypeInfo()) )
  1008.     {
  1009.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  1010.                 pVarResult, pExcepInfo, puArgErr);
  1011.     }
  1012.     return E_NOTIMPL;
  1013. };
  1014. STDMETHODIMP VLCMessageIterator::get_hasNext(VARIANT_BOOL* hasNext)
  1015. {
  1016.     if( NULL == hasNext )
  1017.         return E_POINTER;
  1018.     if( _p_iter &&  _p_vlclog->_p_log )
  1019.     {
  1020.         libvlc_exception_t ex;
  1021.         libvlc_exception_init(&ex);
  1022.         *hasNext = libvlc_log_iterator_has_next(_p_iter, &ex) ?
  1023.                                      VARIANT_TRUE : VARIANT_FALSE;
  1024.         if( libvlc_exception_raised(&ex) )
  1025.         {
  1026.             _p_instance->setErrorInfo(IID_IVLCMessageIterator,
  1027.                          libvlc_exception_get_message(&ex));
  1028.             libvlc_exception_clear(&ex);
  1029.             return E_FAIL;
  1030.         }
  1031.     }
  1032.     else
  1033.     {
  1034.         *hasNext = VARIANT_FALSE;
  1035.     }
  1036.     return S_OK;
  1037. };
  1038. STDMETHODIMP VLCMessageIterator::next(IVLCMessage** message)
  1039. {
  1040.     if( NULL == message )
  1041.         return E_POINTER;
  1042.     if( _p_iter &&  _p_vlclog->_p_log )
  1043.     {
  1044.         struct libvlc_log_message_t buffer;
  1045.         buffer.sizeof_msg = sizeof(buffer);
  1046.         libvlc_exception_t ex;
  1047.         libvlc_exception_init(&ex);
  1048.         libvlc_log_iterator_next(_p_iter, &buffer, &ex);
  1049.         if( libvlc_exception_raised(&ex) )
  1050.         {
  1051.             _p_instance->setErrorInfo(IID_IVLCMessageIterator,
  1052.                          libvlc_exception_get_message(&ex));
  1053.             libvlc_exception_clear(&ex);
  1054.             return E_FAIL;
  1055.         }
  1056.         *message = new VLCMessage(_p_instance, buffer);
  1057.         return *message ? NOERROR : E_OUTOFMEMORY;
  1058.     }
  1059.     return E_FAIL;
  1060. };
  1061. /*******************************************************************************/
  1062. VLCMessage::~VLCMessage()
  1063. {
  1064.     if( _p_typeinfo )
  1065.         _p_typeinfo->Release();
  1066. };
  1067. HRESULT VLCMessage::loadTypeInfo(void)
  1068. {
  1069.     HRESULT hr = NOERROR;
  1070.     if( NULL == _p_typeinfo )
  1071.     {
  1072.         ITypeLib *p_typelib;
  1073.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  1074.         if( SUCCEEDED(hr) )
  1075.         {
  1076.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCMessage, &_p_typeinfo);
  1077.             if( FAILED(hr) )
  1078.             {
  1079.                 _p_typeinfo = NULL;
  1080.             }
  1081.             p_typelib->Release();
  1082.         }
  1083.     }
  1084.     return hr;
  1085. };
  1086. STDMETHODIMP VLCMessage::GetTypeInfoCount(UINT* pctInfo)
  1087. {
  1088.     if( NULL == pctInfo )
  1089.         return E_INVALIDARG;
  1090.     if( SUCCEEDED(loadTypeInfo()) )
  1091.         *pctInfo = 1;
  1092.     else
  1093.         *pctInfo = 0;
  1094.     return NOERROR;
  1095. };
  1096. STDMETHODIMP VLCMessage::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  1097. {
  1098.     if( NULL == ppTInfo )
  1099.         return E_INVALIDARG;
  1100.     if( SUCCEEDED(loadTypeInfo()) )
  1101.     {
  1102.         _p_typeinfo->AddRef();
  1103.         *ppTInfo = _p_typeinfo;
  1104.         return NOERROR;
  1105.     }
  1106.     *ppTInfo = NULL;
  1107.     return E_NOTIMPL;
  1108. };
  1109. STDMETHODIMP VLCMessage::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  1110.         UINT cNames, LCID lcid, DISPID* rgDispID)
  1111. {
  1112.     if( SUCCEEDED(loadTypeInfo()) )
  1113.     {
  1114.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  1115.     }
  1116.     return E_NOTIMPL;
  1117. };
  1118. STDMETHODIMP VLCMessage::Invoke(DISPID dispIdMember, REFIID riid,
  1119.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  1120.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  1121. {
  1122.     if( SUCCEEDED(loadTypeInfo()) )
  1123.     {
  1124.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  1125.                 pVarResult, pExcepInfo, puArgErr);
  1126.     }
  1127.     return E_NOTIMPL;
  1128. };
  1129. inline const char *msgSeverity(int sev)
  1130. {
  1131.     switch( sev )
  1132.     {
  1133.         case 0:
  1134.             return "info";
  1135.         case 1:
  1136.             return "error";
  1137.         case 2:
  1138.             return "warning";
  1139.         default:
  1140.             return "debug";
  1141.     }
  1142. };
  1143. STDMETHODIMP VLCMessage::get__Value(VARIANT* _Value)
  1144. {
  1145.     if( NULL == _Value )
  1146.         return E_POINTER;
  1147.     char buffer[256];
  1148.     snprintf(buffer, sizeof(buffer), "%s %s %s: %s",
  1149.         _msg.psz_type, _msg.psz_name, msgSeverity(_msg.i_severity), _msg.psz_message);
  1150.     V_VT(_Value) = VT_BSTR;
  1151.     V_BSTR(_Value) = BSTRFromCStr(CP_UTF8, buffer);
  1152.     return S_OK;
  1153. };
  1154. STDMETHODIMP VLCMessage::get_severity(long* level)
  1155. {
  1156.     if( NULL == level )
  1157.         return E_POINTER;
  1158.     *level = _msg.i_severity;
  1159.     return S_OK;
  1160. };
  1161. STDMETHODIMP VLCMessage::get_type(BSTR* type)
  1162. {
  1163.     if( NULL == type )
  1164.         return E_POINTER;
  1165.     *type = BSTRFromCStr(CP_UTF8, _msg.psz_type);
  1166.     return NOERROR;
  1167. };
  1168. STDMETHODIMP VLCMessage::get_name(BSTR* name)
  1169. {
  1170.     if( NULL == name )
  1171.         return E_POINTER;
  1172.     *name = BSTRFromCStr(CP_UTF8, _msg.psz_name);
  1173.     return NOERROR;
  1174. };
  1175. STDMETHODIMP VLCMessage::get_header(BSTR* header)
  1176. {
  1177.     if( NULL == header )
  1178.         return E_POINTER;
  1179.     *header = BSTRFromCStr(CP_UTF8, _msg.psz_header);
  1180.     return NOERROR;
  1181. };
  1182. STDMETHODIMP VLCMessage::get_message(BSTR* message)
  1183. {
  1184.     if( NULL == message )
  1185.         return E_POINTER;
  1186.     *message = BSTRFromCStr(CP_UTF8, _msg.psz_message);
  1187.     return NOERROR;
  1188. };
  1189. /*******************************************************************************/
  1190. VLCPlaylistItems::~VLCPlaylistItems()
  1191. {
  1192.     if( _p_typeinfo )
  1193.         _p_typeinfo->Release();
  1194. };
  1195. HRESULT VLCPlaylistItems::loadTypeInfo(void)
  1196. {
  1197.     HRESULT hr = NOERROR;
  1198.     if( NULL == _p_typeinfo )
  1199.     {
  1200.         ITypeLib *p_typelib;
  1201.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  1202.         if( SUCCEEDED(hr) )
  1203.         {
  1204.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylistItems, &_p_typeinfo);
  1205.             if( FAILED(hr) )
  1206.             {
  1207.                 _p_typeinfo = NULL;
  1208.             }
  1209.             p_typelib->Release();
  1210.         }
  1211.     }
  1212.     return hr;
  1213. };
  1214. STDMETHODIMP VLCPlaylistItems::GetTypeInfoCount(UINT* pctInfo)
  1215. {
  1216.     if( NULL == pctInfo )
  1217.         return E_INVALIDARG;
  1218.     if( SUCCEEDED(loadTypeInfo()) )
  1219.         *pctInfo = 1;
  1220.     else
  1221.         *pctInfo = 0;
  1222.     return NOERROR;
  1223. };
  1224. STDMETHODIMP VLCPlaylistItems::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  1225. {
  1226.     if( NULL == ppTInfo )
  1227.         return E_INVALIDARG;
  1228.     if( SUCCEEDED(loadTypeInfo()) )
  1229.     {
  1230.         _p_typeinfo->AddRef();
  1231.         *ppTInfo = _p_typeinfo;
  1232.         return NOERROR;
  1233.     }
  1234.     *ppTInfo = NULL;
  1235.     return E_NOTIMPL;
  1236. };
  1237. STDMETHODIMP VLCPlaylistItems::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  1238.         UINT cNames, LCID lcid, DISPID* rgDispID)
  1239. {
  1240.     if( SUCCEEDED(loadTypeInfo()) )
  1241.     {
  1242.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  1243.     }
  1244.     return E_NOTIMPL;
  1245. };
  1246. STDMETHODIMP VLCPlaylistItems::Invoke(DISPID dispIdMember, REFIID riid,
  1247.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  1248.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  1249. {
  1250.     if( SUCCEEDED(loadTypeInfo()) )
  1251.     {
  1252.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  1253.                 pVarResult, pExcepInfo, puArgErr);
  1254.     }
  1255.     return E_NOTIMPL;
  1256. };
  1257. STDMETHODIMP VLCPlaylistItems::get_count(long* count)
  1258. {
  1259.     if( NULL == count )
  1260.         return E_POINTER;
  1261.     libvlc_exception_t ex;
  1262.     libvlc_exception_init(&ex);
  1263.     *count = _p_instance->playlist_count(&ex);
  1264.     if( libvlc_exception_raised(&ex) )
  1265.     {
  1266.         _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
  1267.             libvlc_exception_get_message(&ex));
  1268.         libvlc_exception_clear(&ex);
  1269.         return E_FAIL;
  1270.     }
  1271.     return NOERROR;
  1272. };
  1273. STDMETHODIMP VLCPlaylistItems::clear()
  1274. {
  1275.     libvlc_instance_t* p_libvlc;
  1276.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  1277.     if( SUCCEEDED(hr) )
  1278.     {
  1279.         libvlc_exception_t ex;
  1280.         libvlc_exception_init(&ex);
  1281.         _p_instance->playlist_clear(&ex);
  1282.         if( libvlc_exception_raised(&ex) )
  1283.         {
  1284.             _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
  1285.                          libvlc_exception_get_message(&ex));
  1286.             libvlc_exception_clear(&ex);
  1287.             return E_FAIL;
  1288.         }
  1289.         return NOERROR;
  1290.     }
  1291.     return hr;
  1292. };
  1293. STDMETHODIMP VLCPlaylistItems::remove(long item)
  1294. {
  1295.     libvlc_instance_t* p_libvlc;
  1296.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  1297.     if( SUCCEEDED(hr) )
  1298.     {
  1299.         libvlc_exception_t ex;
  1300.         libvlc_exception_init(&ex);
  1301.         _p_instance->playlist_delete_item(item, &ex);
  1302.         if( libvlc_exception_raised(&ex) )
  1303.         {
  1304.             _p_instance->setErrorInfo(IID_IVLCPlaylistItems,
  1305.                          libvlc_exception_get_message(&ex));
  1306.             libvlc_exception_clear(&ex);
  1307.             return E_FAIL;
  1308.         }
  1309.         return NOERROR;
  1310.     }
  1311.     return hr;
  1312. };
  1313. /*******************************************************************************/
  1314. VLCPlaylist::~VLCPlaylist()
  1315. {
  1316.     delete _p_vlcplaylistitems;
  1317.     if( _p_typeinfo )
  1318.         _p_typeinfo->Release();
  1319. };
  1320. HRESULT VLCPlaylist::loadTypeInfo(void)
  1321. {
  1322.     HRESULT hr = NOERROR;
  1323.     if( NULL == _p_typeinfo )
  1324.     {
  1325.         ITypeLib *p_typelib;
  1326.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  1327.         if( SUCCEEDED(hr) )
  1328.         {
  1329.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCPlaylist, &_p_typeinfo);
  1330.             if( FAILED(hr) )
  1331.             {
  1332.                 _p_typeinfo = NULL;
  1333.             }
  1334.             p_typelib->Release();
  1335.         }
  1336.     }
  1337.     return hr;
  1338. };
  1339. STDMETHODIMP VLCPlaylist::GetTypeInfoCount(UINT* pctInfo)
  1340. {
  1341.     if( NULL == pctInfo )
  1342.         return E_INVALIDARG;
  1343.     if( SUCCEEDED(loadTypeInfo()) )
  1344.         *pctInfo = 1;
  1345.     else
  1346.         *pctInfo = 0;
  1347.     return NOERROR;
  1348. };
  1349. STDMETHODIMP VLCPlaylist::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  1350. {
  1351.     if( NULL == ppTInfo )
  1352.         return E_INVALIDARG;
  1353.     if( SUCCEEDED(loadTypeInfo()) )
  1354.     {
  1355.         _p_typeinfo->AddRef();
  1356.         *ppTInfo = _p_typeinfo;
  1357.         return NOERROR;
  1358.     }
  1359.     *ppTInfo = NULL;
  1360.     return E_NOTIMPL;
  1361. };
  1362. STDMETHODIMP VLCPlaylist::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  1363.         UINT cNames, LCID lcid, DISPID* rgDispID)
  1364. {
  1365.     if( SUCCEEDED(loadTypeInfo()) )
  1366.     {
  1367.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  1368.     }
  1369.     return E_NOTIMPL;
  1370. };
  1371. STDMETHODIMP VLCPlaylist::Invoke(DISPID dispIdMember, REFIID riid,
  1372.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  1373.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  1374. {
  1375.     if( SUCCEEDED(loadTypeInfo()) )
  1376.     {
  1377.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  1378.                 pVarResult, pExcepInfo, puArgErr);
  1379.     }
  1380.     return E_NOTIMPL;
  1381. };
  1382. STDMETHODIMP VLCPlaylist::get_itemCount(long* count)
  1383. {
  1384.     if( NULL == count )
  1385.         return E_POINTER;
  1386.     *count = 0;
  1387.     libvlc_exception_t ex;
  1388.     libvlc_exception_init(&ex);
  1389.     *count = _p_instance->playlist_count(&ex);
  1390.     if( libvlc_exception_raised(&ex) )
  1391.     {
  1392.         _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1393.             libvlc_exception_get_message(&ex));
  1394.         libvlc_exception_clear(&ex);
  1395.         return E_FAIL;
  1396.     }
  1397.     return NOERROR;
  1398. };
  1399. STDMETHODIMP VLCPlaylist::get_isPlaying(VARIANT_BOOL* isPlaying)
  1400. {
  1401.     if( NULL == isPlaying )
  1402.         return E_POINTER;
  1403.     libvlc_media_player_t *p_md;
  1404.     HRESULT hr = _p_instance->getMD(&p_md);
  1405.     if( SUCCEEDED(hr) )
  1406.     {
  1407.         libvlc_exception_t ex;
  1408.         libvlc_exception_init(&ex);
  1409.         *isPlaying = libvlc_media_player_is_playing(p_md, &ex) ?
  1410.                                     VARIANT_TRUE: VARIANT_FALSE;
  1411.         if( libvlc_exception_raised(&ex) )
  1412.         {
  1413.             _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1414.                          libvlc_exception_get_message(&ex));
  1415.             libvlc_exception_clear(&ex);
  1416.             return E_FAIL;
  1417.         }
  1418.         return NOERROR;
  1419.     }
  1420.     return hr;
  1421. };
  1422. STDMETHODIMP VLCPlaylist::add(BSTR uri, VARIANT name, VARIANT options, long* item)
  1423. {
  1424.     if( NULL == item )
  1425.         return E_POINTER;
  1426.     if( 0 == SysStringLen(uri) )
  1427.         return E_INVALIDARG;
  1428.     libvlc_instance_t* p_libvlc;
  1429.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  1430.     if( SUCCEEDED(hr) )
  1431.     {
  1432.         libvlc_exception_t ex;
  1433.         libvlc_exception_init(&ex);
  1434.         char *psz_uri = NULL;
  1435.         if( SysStringLen(_p_instance->getBaseURL()) > 0 )
  1436.         {
  1437.             /*
  1438.             ** if the MRL a relative URL, we should end up with an absolute URL
  1439.             */
  1440.             LPWSTR abs_url = CombineURL(_p_instance->getBaseURL(), uri);
  1441.             if( NULL != abs_url )
  1442.             {
  1443.                 psz_uri = CStrFromWSTR(CP_UTF8, abs_url, wcslen(abs_url));
  1444.                 CoTaskMemFree(abs_url);
  1445.             }
  1446.             else
  1447.             {
  1448.                 psz_uri = CStrFromBSTR(CP_UTF8, uri);
  1449.             }
  1450.         }
  1451.         else
  1452.         {
  1453.             /*
  1454.             ** baseURL is empty, assume MRL is absolute
  1455.             */
  1456.             psz_uri = CStrFromBSTR(CP_UTF8, uri);
  1457.         }
  1458.         if( NULL == psz_uri )
  1459.         {
  1460.             return E_OUTOFMEMORY;
  1461.         }
  1462.         int i_options;
  1463.         char **ppsz_options;
  1464.         hr = VLCControl::CreateTargetOptions(CP_UTF8, &options, &ppsz_options, &i_options);
  1465.         if( FAILED(hr) )
  1466.         {
  1467.             CoTaskMemFree(psz_uri);
  1468.             return hr;
  1469.         }
  1470.         char *psz_name = NULL;
  1471.         VARIANT v_name;
  1472.         VariantInit(&v_name);
  1473.         if( SUCCEEDED(VariantChangeType(&v_name, &name, 0, VT_BSTR)) )
  1474.         {
  1475.             if( SysStringLen(V_BSTR(&v_name)) > 0 )
  1476.                 psz_name = CStrFromBSTR(CP_UTF8, V_BSTR(&v_name));
  1477.             VariantClear(&v_name);
  1478.         }
  1479.         *item = _p_instance->playlist_add_extended_untrusted(psz_uri,
  1480.                     i_options, const_cast<const char **>(ppsz_options), &ex);
  1481.         VLCControl::FreeTargetOptions(ppsz_options, i_options);
  1482.         CoTaskMemFree(psz_uri);
  1483.         if( psz_name )
  1484.             CoTaskMemFree(psz_name);
  1485.         if( libvlc_exception_raised(&ex) )
  1486.         {
  1487.             _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1488.                 libvlc_exception_get_message(&ex));
  1489.             libvlc_exception_clear(&ex);
  1490.             return E_FAIL;
  1491.         }
  1492.         return NOERROR;
  1493.     }
  1494.     return hr;
  1495. };
  1496. STDMETHODIMP VLCPlaylist::play()
  1497. {
  1498.     libvlc_exception_t ex;
  1499.     libvlc_exception_init(&ex);
  1500.     _p_instance->playlist_play(&ex);
  1501.     if( libvlc_exception_raised(&ex) )
  1502.     {
  1503.         libvlc_exception_clear(&ex);
  1504.         return E_FAIL;
  1505.     }
  1506.     return NOERROR;
  1507. };
  1508. STDMETHODIMP VLCPlaylist::playItem(long item)
  1509. {
  1510.     libvlc_exception_t ex;
  1511.     libvlc_exception_init(&ex);
  1512.     _p_instance->playlist_play_item(item,&ex);
  1513.     if( libvlc_exception_raised(&ex) )
  1514.     {
  1515.         _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1516.             libvlc_exception_get_message(&ex));
  1517.         libvlc_exception_clear(&ex);
  1518.         return E_FAIL;
  1519.     }
  1520.     return NOERROR;
  1521. };
  1522. STDMETHODIMP VLCPlaylist::togglePause()
  1523. {
  1524.     libvlc_media_player_t* p_md;
  1525.     HRESULT hr = _p_instance->getMD(&p_md);
  1526.     if( SUCCEEDED(hr) )
  1527.     {
  1528.         libvlc_exception_t ex;
  1529.         libvlc_exception_init(&ex);
  1530.         libvlc_media_player_pause(p_md, &ex);
  1531.         if( libvlc_exception_raised(&ex) )
  1532.         {
  1533.             _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1534.                 libvlc_exception_get_message(&ex));
  1535.             libvlc_exception_clear(&ex);
  1536.             return E_FAIL;
  1537.         }
  1538.         return NOERROR;
  1539.     }
  1540.     return hr;
  1541. };
  1542. STDMETHODIMP VLCPlaylist::stop()
  1543. {
  1544.     libvlc_media_player_t *p_md;
  1545.     HRESULT hr = _p_instance->getMD(&p_md);
  1546.     if( SUCCEEDED(hr) )
  1547.     {
  1548.         libvlc_exception_t ex;
  1549.         libvlc_exception_init(&ex);
  1550.         libvlc_media_player_stop(p_md, &ex);
  1551.         if( libvlc_exception_raised(&ex) )
  1552.         {
  1553.             _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1554.                 libvlc_exception_get_message(&ex));
  1555.             libvlc_exception_clear(&ex);
  1556.             return E_FAIL;
  1557.         }
  1558.         return NOERROR;
  1559.     }
  1560.     return hr;
  1561. };
  1562. STDMETHODIMP VLCPlaylist::next()
  1563. {
  1564.     libvlc_exception_t ex;
  1565.     libvlc_exception_init(&ex);
  1566.     _p_instance->playlist_next(&ex);
  1567.     if( libvlc_exception_raised(&ex) )
  1568.     {
  1569.         _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1570.             libvlc_exception_get_message(&ex));
  1571.         libvlc_exception_clear(&ex);
  1572.         return E_FAIL;
  1573.     }
  1574.     return NOERROR;
  1575. };
  1576. STDMETHODIMP VLCPlaylist::prev()
  1577. {
  1578.     libvlc_exception_t ex;
  1579.     libvlc_exception_init(&ex);
  1580.     _p_instance->playlist_prev(&ex);
  1581.     if( libvlc_exception_raised(&ex) )
  1582.     {
  1583.         _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1584.             libvlc_exception_get_message(&ex));
  1585.         libvlc_exception_clear(&ex);
  1586.         return E_FAIL;
  1587.     }
  1588.     return NOERROR;
  1589. };
  1590. STDMETHODIMP VLCPlaylist::clear()
  1591. {
  1592.     libvlc_exception_t ex;
  1593.     libvlc_exception_init(&ex);
  1594.     _p_instance->playlist_clear(&ex);
  1595.     if( libvlc_exception_raised(&ex) )
  1596.     {
  1597.         _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1598.             libvlc_exception_get_message(&ex));
  1599.         libvlc_exception_clear(&ex);
  1600.         return E_FAIL;
  1601.     }
  1602.     return NOERROR;
  1603. };
  1604. STDMETHODIMP VLCPlaylist::removeItem(long item)
  1605. {
  1606.     libvlc_instance_t* p_libvlc;
  1607.     HRESULT hr = _p_instance->getVLC(&p_libvlc);
  1608.     if( SUCCEEDED(hr) )
  1609.     {
  1610.         libvlc_exception_t ex;
  1611.         libvlc_exception_init(&ex);
  1612.         _p_instance->playlist_delete_item(item, &ex);
  1613.         if( libvlc_exception_raised(&ex) )
  1614.         {
  1615.             _p_instance->setErrorInfo(IID_IVLCPlaylist,
  1616.                 libvlc_exception_get_message(&ex));
  1617.             libvlc_exception_clear(&ex);
  1618.             return E_FAIL;
  1619.         }
  1620.         return NOERROR;
  1621.     }
  1622.     return hr;
  1623. };
  1624. STDMETHODIMP VLCPlaylist::get_items(IVLCPlaylistItems** obj)
  1625. {
  1626.     if( NULL == obj )
  1627.         return E_POINTER;
  1628.     *obj = _p_vlcplaylistitems;
  1629.     if( NULL != _p_vlcplaylistitems )
  1630.     {
  1631.         _p_vlcplaylistitems->AddRef();
  1632.         return NOERROR;
  1633.     }
  1634.     return E_OUTOFMEMORY;
  1635. };
  1636. /*******************************************************************************/
  1637. VLCVideo::~VLCVideo()
  1638. {
  1639.     if( _p_typeinfo )
  1640.         _p_typeinfo->Release();
  1641. };
  1642. HRESULT VLCVideo::loadTypeInfo(void)
  1643. {
  1644.     HRESULT hr = NOERROR;
  1645.     if( NULL == _p_typeinfo )
  1646.     {
  1647.         ITypeLib *p_typelib;
  1648.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  1649.         if( SUCCEEDED(hr) )
  1650.         {
  1651.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCVideo, &_p_typeinfo);
  1652.             if( FAILED(hr) )
  1653.             {
  1654.                 _p_typeinfo = NULL;
  1655.             }
  1656.             p_typelib->Release();
  1657.         }
  1658.     }
  1659.     return hr;
  1660. };
  1661. STDMETHODIMP VLCVideo::GetTypeInfoCount(UINT* pctInfo)
  1662. {
  1663.     if( NULL == pctInfo )
  1664.         return E_INVALIDARG;
  1665.     if( SUCCEEDED(loadTypeInfo()) )
  1666.         *pctInfo = 1;
  1667.     else
  1668.         *pctInfo = 0;
  1669.     return NOERROR;
  1670. };
  1671. STDMETHODIMP VLCVideo::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  1672. {
  1673.     if( NULL == ppTInfo )
  1674.         return E_INVALIDARG;
  1675.     if( SUCCEEDED(loadTypeInfo()) )
  1676.     {
  1677.         _p_typeinfo->AddRef();
  1678.         *ppTInfo = _p_typeinfo;
  1679.         return NOERROR;
  1680.     }
  1681.     *ppTInfo = NULL;
  1682.     return E_NOTIMPL;
  1683. };
  1684. STDMETHODIMP VLCVideo::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  1685.         UINT cNames, LCID lcid, DISPID* rgDispID)
  1686. {
  1687.     if( SUCCEEDED(loadTypeInfo()) )
  1688.     {
  1689.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  1690.     }
  1691.     return E_NOTIMPL;
  1692. };
  1693. STDMETHODIMP VLCVideo::Invoke(DISPID dispIdMember, REFIID riid,
  1694.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  1695.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  1696. {
  1697.     if( SUCCEEDED(loadTypeInfo()) )
  1698.     {
  1699.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  1700.                 pVarResult, pExcepInfo, puArgErr);
  1701.     }
  1702.     return E_NOTIMPL;
  1703. };
  1704. STDMETHODIMP VLCVideo::get_fullscreen(VARIANT_BOOL* fullscreen)
  1705. {
  1706.     if( NULL == fullscreen )
  1707.         return E_POINTER;
  1708.     libvlc_media_player_t *p_md;
  1709.     HRESULT hr = _p_instance->getMD(&p_md);
  1710.     if( SUCCEEDED(hr) )
  1711.     {
  1712.         libvlc_exception_t ex;
  1713.         libvlc_exception_init(&ex);
  1714.         *fullscreen = libvlc_get_fullscreen(p_md, &ex) ? VARIANT_TRUE : VARIANT_FALSE;
  1715.         if( ! libvlc_exception_raised(&ex) )
  1716.         {
  1717.             return NOERROR;
  1718.         }
  1719.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1720.         libvlc_exception_clear(&ex);
  1721.         return E_FAIL;
  1722.     }
  1723.     return hr;
  1724. };
  1725. STDMETHODIMP VLCVideo::put_fullscreen(VARIANT_BOOL fullscreen)
  1726. {
  1727.     libvlc_media_player_t *p_md;
  1728.     HRESULT hr = _p_instance->getMD(&p_md);
  1729.     if( SUCCEEDED(hr) )
  1730.     {
  1731.         libvlc_exception_t ex;
  1732.         libvlc_exception_init(&ex);
  1733.         libvlc_set_fullscreen(p_md, VARIANT_FALSE != fullscreen, &ex);
  1734.         if( ! libvlc_exception_raised(&ex) )
  1735.         {
  1736.             return NOERROR;
  1737.         }
  1738.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1739.         libvlc_exception_clear(&ex);
  1740.         return E_FAIL;
  1741.     }
  1742.     return hr;
  1743. };
  1744. STDMETHODIMP VLCVideo::get_width(long* width)
  1745. {
  1746.     if( NULL == width )
  1747.         return E_POINTER;
  1748.     libvlc_media_player_t *p_md;
  1749.     HRESULT hr = _p_instance->getMD(&p_md);
  1750.     if( SUCCEEDED(hr) )
  1751.     {
  1752.         libvlc_exception_t ex;
  1753.         libvlc_exception_init(&ex);
  1754.         *width = libvlc_video_get_width(p_md, &ex);
  1755.         if( ! libvlc_exception_raised(&ex) )
  1756.         {
  1757.             return NOERROR;
  1758.         }
  1759.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1760.         libvlc_exception_clear(&ex);
  1761.         return E_FAIL;
  1762.     }
  1763.     return hr;
  1764. };
  1765. STDMETHODIMP VLCVideo::get_height(long* height)
  1766. {
  1767.     if( NULL == height )
  1768.         return E_POINTER;
  1769.     libvlc_media_player_t *p_md;
  1770.     HRESULT hr = _p_instance->getMD(&p_md);
  1771.     if( SUCCEEDED(hr) )
  1772.     {
  1773.         libvlc_exception_t ex;
  1774.         libvlc_exception_init(&ex);
  1775.         *height = libvlc_video_get_height(p_md, &ex);
  1776.         if( ! libvlc_exception_raised(&ex) )
  1777.         {
  1778.             return NOERROR;
  1779.         }
  1780.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1781.         libvlc_exception_clear(&ex);
  1782.         return E_FAIL;
  1783.     }
  1784.     return hr;
  1785. };
  1786. STDMETHODIMP VLCVideo::get_aspectRatio(BSTR* aspect)
  1787. {
  1788.     if( NULL == aspect )
  1789.         return E_POINTER;
  1790.     libvlc_media_player_t *p_md;
  1791.     HRESULT hr = _p_instance->getMD(&p_md);
  1792.     if( SUCCEEDED(hr) )
  1793.     {
  1794.         libvlc_exception_t ex;
  1795.         libvlc_exception_init(&ex);
  1796.         char *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
  1797.         if( ! libvlc_exception_raised(&ex) )
  1798.         {
  1799.             if( NULL == psz_aspect )
  1800.                 return E_OUTOFMEMORY;
  1801.             *aspect = BSTRFromCStr(CP_UTF8, psz_aspect);
  1802.             free( psz_aspect );
  1803.             psz_aspect = NULL;
  1804.             return (NULL == *aspect) ? E_OUTOFMEMORY : NOERROR;
  1805.         }
  1806.         free( psz_aspect );
  1807.         psz_aspect = NULL;
  1808.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1809.         libvlc_exception_clear(&ex);
  1810.         return E_FAIL;
  1811.     }
  1812.     return hr;
  1813. };
  1814. STDMETHODIMP VLCVideo::put_aspectRatio(BSTR aspect)
  1815. {
  1816.     if( NULL == aspect )
  1817.         return E_POINTER;
  1818.     libvlc_media_player_t *p_md;
  1819.     HRESULT hr = _p_instance->getMD(&p_md);
  1820.     if( SUCCEEDED(hr) )
  1821.     {
  1822.         libvlc_exception_t ex;
  1823.         libvlc_exception_init(&ex);
  1824.         char *psz_aspect = CStrFromBSTR(CP_UTF8, aspect);
  1825.         if( NULL == psz_aspect )
  1826.         {
  1827.             return E_OUTOFMEMORY;
  1828.         }
  1829.         libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
  1830.         CoTaskMemFree(psz_aspect);
  1831.         if( libvlc_exception_raised(&ex) )
  1832.         {
  1833.             _p_instance->setErrorInfo(IID_IVLCVideo,
  1834.                 libvlc_exception_get_message(&ex));
  1835.             libvlc_exception_clear(&ex);
  1836.             return E_FAIL;
  1837.         }
  1838.         return NOERROR;
  1839.     }
  1840.     return hr;
  1841. };
  1842. STDMETHODIMP VLCVideo::get_subtitle(long* spu)
  1843. {
  1844.     if( NULL == spu )
  1845.         return E_POINTER;
  1846.     libvlc_media_player_t *p_md;
  1847.     HRESULT hr = _p_instance->getMD(&p_md);
  1848.     if( SUCCEEDED(hr) )
  1849.     {
  1850.         libvlc_exception_t ex;
  1851.         libvlc_exception_init(&ex);
  1852.         *spu = libvlc_video_get_spu(p_md, &ex);
  1853.         if( ! libvlc_exception_raised(&ex) )
  1854.         {
  1855.             return NOERROR;
  1856.         }
  1857.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1858.         libvlc_exception_clear(&ex);
  1859.         return E_FAIL;
  1860.     }
  1861.     return hr;
  1862. };
  1863. STDMETHODIMP VLCVideo::put_subtitle(long spu)
  1864. {
  1865.     libvlc_media_player_t *p_md;
  1866.     HRESULT hr = _p_instance->getMD(&p_md);
  1867.     if( SUCCEEDED(hr) )
  1868.     {
  1869.         libvlc_exception_t ex;
  1870.         libvlc_exception_init(&ex);
  1871.         libvlc_video_set_spu(p_md, spu, &ex);
  1872.         if( libvlc_exception_raised(&ex) )
  1873.         {
  1874.             _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1875.             libvlc_exception_clear(&ex);
  1876.             return E_FAIL;
  1877.         }
  1878.         return NOERROR;
  1879.     }
  1880.     return hr;
  1881. };
  1882. STDMETHODIMP VLCVideo::get_crop(BSTR* geometry)
  1883. {
  1884.     if( NULL == geometry )
  1885.         return E_POINTER;
  1886.     libvlc_media_player_t *p_md;
  1887.     HRESULT hr = _p_instance->getMD(&p_md);
  1888.     if( SUCCEEDED(hr) )
  1889.     {
  1890.         libvlc_exception_t ex;
  1891.         libvlc_exception_init(&ex);
  1892.         char *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
  1893.         if( ! libvlc_exception_raised(&ex) )
  1894.         {
  1895.             if( NULL == psz_geometry )
  1896.                 return E_OUTOFMEMORY;
  1897.             *geometry = BSTRFromCStr(CP_UTF8, psz_geometry);
  1898.             free( psz_geometry );
  1899.             psz_geometry = NULL;
  1900.             return (NULL == geometry) ? E_OUTOFMEMORY : NOERROR;
  1901.         }
  1902.         free( psz_geometry );
  1903.         psz_geometry = NULL;
  1904.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1905.         libvlc_exception_clear(&ex);
  1906.         return E_FAIL;
  1907.     }
  1908.     return hr;
  1909. };
  1910. STDMETHODIMP VLCVideo::put_crop(BSTR geometry)
  1911. {
  1912.     if( NULL == geometry )
  1913.         return E_POINTER;
  1914.     if( 0 == SysStringLen(geometry) )
  1915.         return E_INVALIDARG;
  1916.     libvlc_media_player_t *p_md;
  1917.     HRESULT hr = _p_instance->getMD(&p_md);
  1918.     if( SUCCEEDED(hr) )
  1919.     {
  1920.         libvlc_exception_t ex;
  1921.         libvlc_exception_init(&ex);
  1922.         char *psz_geometry = CStrFromBSTR(CP_UTF8, geometry);
  1923.         if( NULL == psz_geometry )
  1924.         {
  1925.             return E_OUTOFMEMORY;
  1926.         }
  1927.         libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
  1928.         CoTaskMemFree(psz_geometry);
  1929.         if( libvlc_exception_raised(&ex) )
  1930.         {
  1931.             _p_instance->setErrorInfo(IID_IVLCVideo,
  1932.                 libvlc_exception_get_message(&ex));
  1933.             libvlc_exception_clear(&ex);
  1934.             return E_FAIL;
  1935.         }
  1936.         return NOERROR;
  1937.     }
  1938.     return hr;
  1939. };
  1940. STDMETHODIMP VLCVideo::get_teletext(long* page)
  1941. {
  1942.     if( NULL == page )
  1943.         return E_POINTER;
  1944.     libvlc_media_player_t *p_md;
  1945.     HRESULT hr = _p_instance->getMD(&p_md);
  1946.     if( SUCCEEDED(hr) )
  1947.     {
  1948.         libvlc_exception_t ex;
  1949.         libvlc_exception_init(&ex);
  1950.         *page = libvlc_video_get_teletext(p_md, &ex);
  1951.         if( ! libvlc_exception_raised(&ex) )
  1952.         {
  1953.             return NOERROR;
  1954.         }
  1955.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1956.         libvlc_exception_clear(&ex);
  1957.         return E_FAIL;
  1958.     }
  1959.     return hr;
  1960. };
  1961. STDMETHODIMP VLCVideo::put_teletext(long page)
  1962. {
  1963.     libvlc_media_player_t *p_md;
  1964.     HRESULT hr = _p_instance->getMD(&p_md);
  1965.     if( SUCCEEDED(hr) )
  1966.     {
  1967.         libvlc_exception_t ex;
  1968.         libvlc_exception_init(&ex);
  1969.         libvlc_video_set_teletext(p_md, page, &ex);
  1970.         if( libvlc_exception_raised(&ex) )
  1971.         {
  1972.             _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  1973.             libvlc_exception_clear(&ex);
  1974.             return E_FAIL;
  1975.         }
  1976.         return NOERROR;
  1977.     }
  1978.     return hr;
  1979. };
  1980. STDMETHODIMP VLCVideo::takeSnapshot(LPPICTUREDISP* picture)
  1981. {
  1982.     if( NULL == picture )
  1983.         return E_POINTER;
  1984.     libvlc_media_player_t *p_md;
  1985.     HRESULT hr = _p_instance->getMD(&p_md);
  1986.     if( SUCCEEDED(hr) )
  1987.     {
  1988.         libvlc_exception_t ex;
  1989.         libvlc_exception_init(&ex);
  1990.         static int uniqueId = 0;
  1991.         TCHAR path[MAX_PATH+1];
  1992.         int pathlen = GetTempPath(MAX_PATH-24, path);
  1993.         if( (0 == pathlen) || (pathlen > (MAX_PATH-24)) )
  1994.             return E_FAIL;
  1995.         /* check temp directory path by openning it */
  1996.         {
  1997.             HANDLE dirHandle = CreateFile(path, GENERIC_READ,
  1998.                        FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
  1999.                        NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
  2000.             if( INVALID_HANDLE_VALUE == dirHandle )
  2001.             {
  2002.                 _p_instance->setErrorInfo(IID_IVLCVideo,
  2003.                         "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
  2004.                 return E_FAIL;
  2005.             }
  2006.             else
  2007.             {
  2008.                 BY_HANDLE_FILE_INFORMATION bhfi;
  2009.                 BOOL res = GetFileInformationByHandle(dirHandle, &bhfi);
  2010.                 CloseHandle(dirHandle);
  2011.                 if( !res || !(bhfi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
  2012.                 {
  2013.                     _p_instance->setErrorInfo(IID_IVLCVideo,
  2014.                             "Invalid temporary directory for snapshot images, check values of TMP, TEMP envars.");
  2015.                     return E_FAIL;
  2016.                 }
  2017.             }
  2018.         }
  2019.         TCHAR filepath[MAX_PATH+1];
  2020.         _stprintf(filepath, TEXT("%sAXVLC%lXS%lX.bmp"),
  2021.                  path, GetCurrentProcessId(), ++uniqueId);
  2022. #ifdef _UNICODE
  2023.         /* reuse path storage for UTF8 string */
  2024.         char *psz_filepath = (char *)path;
  2025.         WCHAR* wpath = filepath;
  2026. #else
  2027.         char *psz_filepath = path;
  2028.         /* first convert to unicode using current code page */
  2029.         WCHAR wpath[MAX_PATH+1];
  2030.         if( 0 == MultiByteToWideChar(CP_ACP, 0, filepath, -1, wpath, sizeof(wpath)/sizeof(WCHAR)) )
  2031.             return E_FAIL;
  2032. #endif
  2033.         /* convert to UTF8 */
  2034.         pathlen = WideCharToMultiByte(CP_UTF8, 0, wpath, -1, psz_filepath, sizeof(path), NULL, NULL);
  2035.         // fail if path is 0 or too short (i.e pathlen is the same as storage size)
  2036.         if( (0 == pathlen) || (sizeof(path) == pathlen) )
  2037.             return E_FAIL;
  2038.         /* take snapshot into file */
  2039.         libvlc_video_take_snapshot(p_md, psz_filepath, 0, 0, &ex);
  2040.         if( ! libvlc_exception_raised(&ex) )
  2041.         {
  2042.             hr = E_FAIL;
  2043.             /* open snapshot file */
  2044.             HANDLE snapPic = LoadImage(NULL, filepath, IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
  2045.             if( snapPic )
  2046.             {
  2047.                 PICTDESC snapDesc;
  2048.                 snapDesc.cbSizeofstruct = sizeof(PICTDESC);
  2049.                 snapDesc.picType        = PICTYPE_BITMAP;
  2050.                 snapDesc.bmp.hbitmap    = (HBITMAP)snapPic;
  2051.                 snapDesc.bmp.hpal       = NULL;
  2052.                 hr = OleCreatePictureIndirect(&snapDesc, IID_IPictureDisp, TRUE, (LPVOID*)picture);
  2053.                 if( FAILED(hr) )
  2054.                 {
  2055.                     *picture = NULL;
  2056.                     DeleteObject(snapPic);
  2057.                 }
  2058.             }
  2059.             DeleteFile(filepath);
  2060.             return hr;
  2061.         }
  2062.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  2063.         libvlc_exception_clear(&ex);
  2064.         return E_FAIL;
  2065.     }
  2066.     return hr;
  2067. };
  2068. STDMETHODIMP VLCVideo::toggleFullscreen()
  2069. {
  2070.     libvlc_media_player_t *p_md;
  2071.     HRESULT hr = _p_instance->getMD(&p_md);
  2072.     if( SUCCEEDED(hr) )
  2073.     {
  2074.         libvlc_exception_t ex;
  2075.         libvlc_exception_init(&ex);
  2076.         libvlc_toggle_fullscreen(p_md, &ex);
  2077.         if( ! libvlc_exception_raised(&ex) )
  2078.         {
  2079.             return NOERROR;
  2080.         }
  2081.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  2082.         libvlc_exception_clear(&ex);
  2083.         return E_FAIL;
  2084.     }
  2085.     return hr;
  2086. };
  2087. STDMETHODIMP VLCVideo::toggleTeletext()
  2088. {
  2089.     libvlc_media_player_t *p_md;
  2090.     HRESULT hr = _p_instance->getMD(&p_md);
  2091.     if( SUCCEEDED(hr) )
  2092.     {
  2093.         libvlc_exception_t ex;
  2094.         libvlc_exception_init(&ex);
  2095.         libvlc_toggle_teletext(p_md, &ex);
  2096.         if( ! libvlc_exception_raised(&ex) )
  2097.         {
  2098.             return NOERROR;
  2099.         }
  2100.         _p_instance->setErrorInfo(IID_IVLCVideo, libvlc_exception_get_message(&ex));
  2101.         libvlc_exception_clear(&ex);
  2102.         return E_FAIL;
  2103.     }
  2104.     return hr;
  2105. };
  2106. /*******************************************************************************/
  2107. VLCControl2::VLCControl2(VLCPlugin *p_instance) :
  2108.     _p_instance(p_instance),
  2109.     _p_typeinfo(NULL),
  2110.     _p_vlcaudio(NULL),
  2111.     _p_vlcinput(NULL),
  2112.     _p_vlcplaylist(NULL),
  2113.     _p_vlcvideo(NULL)
  2114. {
  2115.     _p_vlcaudio     = new VLCAudio(p_instance);
  2116.     _p_vlcinput     = new VLCInput(p_instance);
  2117.     _p_vlclog       = new VLCLog(p_instance);
  2118.     _p_vlcplaylist  = new VLCPlaylist(p_instance);
  2119.     _p_vlcvideo     = new VLCVideo(p_instance);
  2120. };
  2121. VLCControl2::~VLCControl2()
  2122. {
  2123.     delete _p_vlcvideo;
  2124.     delete _p_vlcplaylist;
  2125.     delete _p_vlclog;
  2126.     delete _p_vlcinput;
  2127.     delete _p_vlcaudio;
  2128.     if( _p_typeinfo )
  2129.         _p_typeinfo->Release();
  2130. };
  2131. HRESULT VLCControl2::loadTypeInfo(void)
  2132. {
  2133.     HRESULT hr = NOERROR;
  2134.     if( NULL == _p_typeinfo )
  2135.     {
  2136.         ITypeLib *p_typelib;
  2137.         hr = _p_instance->getTypeLib(LOCALE_USER_DEFAULT, &p_typelib);
  2138.         if( SUCCEEDED(hr) )
  2139.         {
  2140.             hr = p_typelib->GetTypeInfoOfGuid(IID_IVLCControl2, &_p_typeinfo);
  2141.             if( FAILED(hr) )
  2142.             {
  2143.                 _p_typeinfo = NULL;
  2144.             }
  2145.             p_typelib->Release();
  2146.         }
  2147.     }
  2148.     return hr;
  2149. };
  2150. STDMETHODIMP VLCControl2::GetTypeInfoCount(UINT* pctInfo)
  2151. {
  2152.     if( NULL == pctInfo )
  2153.         return E_INVALIDARG;
  2154.     if( SUCCEEDED(loadTypeInfo()) )
  2155.         *pctInfo = 1;
  2156.     else
  2157.         *pctInfo = 0;
  2158.     return NOERROR;
  2159. };
  2160. STDMETHODIMP VLCControl2::GetTypeInfo(UINT iTInfo, LCID lcid, LPTYPEINFO* ppTInfo)
  2161. {
  2162.     if( NULL == ppTInfo )
  2163.         return E_INVALIDARG;
  2164.     if( SUCCEEDED(loadTypeInfo()) )
  2165.     {
  2166.         _p_typeinfo->AddRef();
  2167.         *ppTInfo = _p_typeinfo;
  2168.         return NOERROR;
  2169.     }
  2170.     *ppTInfo = NULL;
  2171.     return E_NOTIMPL;
  2172. };
  2173. STDMETHODIMP VLCControl2::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames,
  2174.         UINT cNames, LCID lcid, DISPID* rgDispID)
  2175. {
  2176.     if( SUCCEEDED(loadTypeInfo()) )
  2177.     {
  2178.         return DispGetIDsOfNames(_p_typeinfo, rgszNames, cNames, rgDispID);
  2179.     }
  2180.     return E_NOTIMPL;
  2181. };
  2182. STDMETHODIMP VLCControl2::Invoke(DISPID dispIdMember, REFIID riid,
  2183.         LCID lcid, WORD wFlags, DISPPARAMS* pDispParams,
  2184.         VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  2185. {
  2186.     if( SUCCEEDED(loadTypeInfo()) )
  2187.     {
  2188.         return DispInvoke(this, _p_typeinfo, dispIdMember, wFlags, pDispParams,
  2189.                 pVarResult, pExcepInfo, puArgErr);
  2190.     }
  2191.     return E_NOTIMPL;
  2192. };
  2193. STDMETHODIMP VLCControl2::get_AutoLoop(VARIANT_BOOL *autoloop)
  2194. {
  2195.     if( NULL == autoloop )
  2196.         return E_POINTER;
  2197.     *autoloop = _p_instance->getAutoLoop() ? VARIANT_TRUE: VARIANT_FALSE;
  2198.     return S_OK;
  2199. };
  2200. STDMETHODIMP VLCControl2::put_AutoLoop(VARIANT_BOOL autoloop)
  2201. {
  2202.     _p_instance->setAutoLoop((VARIANT_FALSE != autoloop) ? TRUE: FALSE);
  2203.     return S_OK;
  2204. };
  2205. STDMETHODIMP VLCControl2::get_AutoPlay(VARIANT_BOOL *autoplay)
  2206. {
  2207.     if( NULL == autoplay )
  2208.         return E_POINTER;
  2209.     *autoplay = _p_instance->getAutoPlay() ? VARIANT_TRUE: VARIANT_FALSE;
  2210.     return S_OK;
  2211. };
  2212. STDMETHODIMP VLCControl2::put_AutoPlay(VARIANT_BOOL autoplay)
  2213. {
  2214.     _p_instance->setAutoPlay((VARIANT_FALSE != autoplay) ? TRUE: FALSE);
  2215.     return S_OK;
  2216. };
  2217. STDMETHODIMP VLCControl2::get_BaseURL(BSTR *url)
  2218. {
  2219.     if( NULL == url )
  2220.         return E_POINTER;
  2221.     *url = SysAllocStringLen(_p_instance->getBaseURL(),
  2222.                 SysStringLen(_p_instance->getBaseURL()));
  2223.     return NOERROR;
  2224. };
  2225. STDMETHODIMP VLCControl2::put_BaseURL(BSTR mrl)
  2226. {
  2227.     _p_instance->setBaseURL(mrl);
  2228.     return S_OK;
  2229. };
  2230. STDMETHODIMP VLCControl2::get_MRL(BSTR *mrl)
  2231. {
  2232.     if( NULL == mrl )
  2233.         return E_POINTER;
  2234.     *mrl = SysAllocStringLen(_p_instance->getMRL(),
  2235.                 SysStringLen(_p_instance->getMRL()));
  2236.     return NOERROR;
  2237. };
  2238. STDMETHODIMP VLCControl2::put_MRL(BSTR mrl)
  2239. {
  2240.     _p_instance->setMRL(mrl);
  2241.     return S_OK;
  2242. };
  2243. STDMETHODIMP VLCControl2::get_Toolbar(VARIANT_BOOL *visible)
  2244. {
  2245.     if( NULL == visible )
  2246.         return E_POINTER;
  2247.     /*
  2248.      * Note to developers
  2249.      *
  2250.      * Returning the _b_toolbar is closer to the method specification.
  2251.      * But returning True when toolbar is not implemented so not displayed
  2252.      * could be bad for ActiveX users which rely on this value to show their
  2253.      * own toolbar if not provided by the ActiveX.
  2254.      *
  2255.      * This is the reason why FALSE is returned, until toolbar get implemented.
  2256.      */
  2257.     /* DISABLED for now */
  2258.     //  *visible = _p_instance->getShowToolbar() ? VARIANT_TRUE: VARIANT_FALSE;
  2259.     *visible = VARIANT_FALSE;
  2260.     return S_OK;
  2261. };
  2262. STDMETHODIMP VLCControl2::put_Toolbar(VARIANT_BOOL visible)
  2263. {
  2264.     _p_instance->setShowToolbar((VARIANT_FALSE != visible) ? TRUE: FALSE);
  2265.     return S_OK;
  2266. };
  2267. STDMETHODIMP VLCControl2::get_StartTime(long *seconds)
  2268. {
  2269.     if( NULL == seconds )
  2270.         return E_POINTER;
  2271.     *seconds = _p_instance->getStartTime();
  2272.     return S_OK;
  2273. };
  2274. STDMETHODIMP VLCControl2::put_StartTime(long seconds)
  2275. {
  2276.     _p_instance->setStartTime(seconds);
  2277.     return NOERROR;
  2278. };
  2279. STDMETHODIMP VLCControl2::get_VersionInfo(BSTR *version)
  2280. {
  2281.     if( NULL == version )
  2282.         return E_POINTER;
  2283.     const char *versionStr = libvlc_get_version();
  2284.     if( NULL != versionStr )
  2285.     {
  2286.         *version = BSTRFromCStr(CP_UTF8, versionStr);
  2287.         return (NULL == *version) ? E_OUTOFMEMORY : NOERROR;
  2288.     }
  2289.     *version = NULL;
  2290.     return E_FAIL;
  2291. };
  2292. STDMETHODIMP VLCControl2::get_Visible(VARIANT_BOOL *isVisible)
  2293. {
  2294.     if( NULL == isVisible )
  2295.         return E_POINTER;
  2296.     *isVisible = _p_instance->getVisible() ? VARIANT_TRUE : VARIANT_FALSE;
  2297.     return NOERROR;
  2298. };
  2299. STDMETHODIMP VLCControl2::put_Visible(VARIANT_BOOL isVisible)
  2300. {
  2301.     _p_instance->setVisible(isVisible != VARIANT_FALSE);
  2302.     return NOERROR;
  2303. };
  2304. STDMETHODIMP VLCControl2::get_Volume(long *volume)
  2305. {
  2306.     if( NULL == volume )
  2307.         return E_POINTER;
  2308.     *volume  = _p_instance->getVolume();
  2309.     return NOERROR;
  2310. };
  2311. STDMETHODIMP VLCControl2::put_Volume(long volume)
  2312. {
  2313.     _p_instance->setVolume(volume);
  2314.     return NOERROR;
  2315. };
  2316. STDMETHODIMP VLCControl2::get_BackColor(OLE_COLOR *backcolor)
  2317. {
  2318.     if( NULL == backcolor )
  2319.         return E_POINTER;
  2320.     *backcolor  = _p_instance->getBackColor();
  2321.     return NOERROR;
  2322. };
  2323. STDMETHODIMP VLCControl2::put_BackColor(OLE_COLOR backcolor)
  2324. {
  2325.     _p_instance->setBackColor(backcolor);
  2326.     return NOERROR;
  2327. };
  2328. STDMETHODIMP VLCControl2::get_audio(IVLCAudio** obj)
  2329. {
  2330.     if( NULL == obj )
  2331.         return E_POINTER;
  2332.     *obj = _p_vlcaudio;
  2333.     if( NULL != _p_vlcaudio )
  2334.     {
  2335.         _p_vlcaudio->AddRef();
  2336.         return NOERROR;
  2337.     }
  2338.     return E_OUTOFMEMORY;
  2339. };
  2340. STDMETHODIMP VLCControl2::get_input(IVLCInput** obj)
  2341. {
  2342.     if( NULL == obj )
  2343.         return E_POINTER;
  2344.     *obj = _p_vlcinput;
  2345.     if( NULL != _p_vlcinput )
  2346.     {
  2347.         _p_vlcinput->AddRef();
  2348.         return NOERROR;
  2349.     }
  2350.     return E_OUTOFMEMORY;
  2351. };
  2352. STDMETHODIMP VLCControl2::get_log(IVLCLog** obj)
  2353. {
  2354.     if( NULL == obj )
  2355.         return E_POINTER;
  2356.     *obj = _p_vlclog;
  2357.     if( NULL != _p_vlclog )
  2358.     {
  2359.         _p_vlclog->AddRef();
  2360.         return NOERROR;
  2361.     }
  2362.     return E_OUTOFMEMORY;
  2363. };
  2364. STDMETHODIMP VLCControl2::get_playlist(IVLCPlaylist** obj)
  2365. {
  2366.     if( NULL == obj )
  2367.         return E_POINTER;
  2368.     *obj = _p_vlcplaylist;
  2369.     if( NULL != _p_vlcplaylist )
  2370.     {
  2371.         _p_vlcplaylist->AddRef();
  2372.         return NOERROR;
  2373.     }
  2374.     return E_OUTOFMEMORY;
  2375. };
  2376. STDMETHODIMP VLCControl2::get_video(IVLCVideo** obj)
  2377. {
  2378.     if( NULL == obj )
  2379.         return E_POINTER;
  2380.     *obj = _p_vlcvideo;
  2381.     if( NULL != _p_vlcvideo )
  2382.     {
  2383.         _p_vlcvideo->AddRef();
  2384.         return NOERROR;
  2385.     }
  2386.     return E_OUTOFMEMORY;
  2387. };