1 /*****************************************************************************
\r
2 * utils.cpp: ActiveX control for VLC
\r
3 *****************************************************************************
\r
4 * Copyright (C) 2005 VideoLAN
\r
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License
\r
19 * along with this program; if not, write to the Free Software
\r
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
\r
21 *****************************************************************************/
\r
26 ** conversion facilities
\r
29 using namespace std;
\r
31 char *CStrFromBSTR(int codePage, BSTR bstr)
\r
33 UINT len = SysStringLen(bstr);
\r
36 size_t mblen = WideCharToMultiByte(codePage,
\r
37 0, bstr, len, NULL, 0, NULL, NULL);
\r
40 char *buffer = (char *)malloc(mblen+1);
\r
41 ZeroMemory(buffer, mblen+1);
\r
42 if( WideCharToMultiByte(codePage, 0, bstr, len, buffer, mblen, NULL, NULL) )
\r
49 BSTR BSTRFromCStr(int codePage, const char *s)
\r
51 int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
\r
54 WCHAR* wideStr = (WCHAR*)malloc(wideLen*sizeof(WCHAR));
\r
55 if( NULL != wideStr )
\r
59 ZeroMemory(wideStr, wideLen*sizeof(WCHAR));
\r
60 MultiByteToWideChar(codePage, 0, s, -1, wideStr, wideLen);
\r
61 bstr = SysAllocString(wideStr);
\r
74 HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v)
\r
77 HRESULT hr = object->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp);
\r
80 DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
\r
82 hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_USER_DEFAULT,
\r
83 DISPATCH_PROPERTYGET, &dispparamsNoArgs, &vres, NULL, NULL);
\r
86 if( V_VT(&v) != V_VT(&vres) )
\r
88 hr = VariantChangeType(&v, &vres, 0, V_VT(&v));
\r
89 VariantClear(&vres);
\r