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