-/*****************************************************************************\r
- * utils.cpp: ActiveX control for VLC\r
- *****************************************************************************\r
- * Copyright (C) 2005 VideoLAN\r
- *\r
- * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.\r
- *****************************************************************************/\r
-\r
-#include "utils.h"\r
-\r
-/*\r
-** conversion facilities\r
-*/\r
-\r
-using namespace std;\r
-\r
-char *CStrFromBSTR(int codePage, BSTR bstr)\r
-{\r
- UINT len = SysStringLen(bstr);\r
- if( len > 0 )\r
- {\r
- size_t mblen = WideCharToMultiByte(codePage,\r
- 0, bstr, len, NULL, 0, NULL, NULL);\r
- if( mblen > 0 )\r
- {\r
- char *buffer = (char *)malloc(mblen+1);\r
- ZeroMemory(buffer, mblen+1);\r
- if( WideCharToMultiByte(codePage, 0, bstr, len, buffer, mblen, NULL, NULL) )\r
- return buffer;\r
- }\r
- }\r
- return NULL;\r
-};\r
-\r
-BSTR BSTRFromCStr(int codePage, const char *s)\r
-{\r
- int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);\r
- if( wideLen )\r
- {\r
- WCHAR* wideStr = (WCHAR*)malloc(wideLen*sizeof(WCHAR));\r
- if( NULL != wideStr )\r
- {\r
- BSTR bstr;\r
-\r
- ZeroMemory(wideStr, wideLen*sizeof(WCHAR));\r
- MultiByteToWideChar(codePage, 0, s, -1, wideStr, wideLen);\r
- bstr = SysAllocString(wideStr);\r
- free(wideStr);\r
-\r
- return bstr;\r
- }\r
- }\r
- return NULL;\r
-};\r
-\r
-/*\r
-** properties\r
-*/\r
-\r
-HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v)\r
-{\r
- IDispatch *pDisp;\r
- HRESULT hr = object->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp);\r
- if( SUCCEEDED(hr) )\r
- {\r
- DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};\r
- VARIANT vres;\r
- hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_USER_DEFAULT,\r
- DISPATCH_PROPERTYGET, &dispparamsNoArgs, &vres, NULL, NULL);\r
- if( SUCCEEDED(hr) )\r
- {\r
- if( V_VT(&v) != V_VT(&vres) )\r
- {\r
- hr = VariantChangeType(&v, &vres, 0, V_VT(&v));\r
- VariantClear(&vres);\r
- }\r
- else\r
- {\r
- v = vres;\r
- }\r
- }\r
- pDisp->Release();\r
- }\r
- return hr;\r
-};\r
-\r
-\r
+/*****************************************************************************
+ * utils.cpp: ActiveX control for VLC
+ *****************************************************************************
+ * Copyright (C) 2005 VideoLAN
+ *
+ * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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.
+ *****************************************************************************/
+
+#include "utils.h"
+
+/*
+** conversion facilities
+*/
+
+using namespace std;
+
+char *CStrFromBSTR(int codePage, BSTR bstr)
+{
+ UINT len = SysStringLen(bstr);
+ if( len > 0 )
+ {
+ size_t mblen = WideCharToMultiByte(codePage,
+ 0, bstr, len, NULL, 0, NULL, NULL);
+ if( mblen > 0 )
+ {
+ char *buffer = (char *)malloc(mblen+1);
+ ZeroMemory(buffer, mblen+1);
+ if( WideCharToMultiByte(codePage, 0, bstr, len, buffer, mblen, NULL, NULL) )
+ return buffer;
+ }
+ }
+ return NULL;
+};
+
+BSTR BSTRFromCStr(int codePage, const char *s)
+{
+ int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
+ if( wideLen )
+ {
+ WCHAR* wideStr = (WCHAR*)malloc(wideLen*sizeof(WCHAR));
+ if( NULL != wideStr )
+ {
+ BSTR bstr;
+
+ ZeroMemory(wideStr, wideLen*sizeof(WCHAR));
+ MultiByteToWideChar(codePage, 0, s, -1, wideStr, wideLen);
+ bstr = SysAllocString(wideStr);
+ free(wideStr);
+
+ return bstr;
+ }
+ }
+ return NULL;
+};
+
+/*
+** properties
+*/
+
+HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v)
+{
+ IDispatch *pDisp;
+ HRESULT hr = object->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp);
+ if( SUCCEEDED(hr) )
+ {
+ DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
+ VARIANT vres;
+ hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_USER_DEFAULT,
+ DISPATCH_PROPERTYGET, &dispparamsNoArgs, &vres, NULL, NULL);
+ if( SUCCEEDED(hr) )
+ {
+ if( V_VT(&v) != V_VT(&vres) )
+ {
+ hr = VariantChangeType(&v, &vres, 0, V_VT(&v));
+ VariantClear(&vres);
+ }
+ else
+ {
+ v = vres;
+ }
+ }
+ pDisp->Release();
+ }
+ return hr;
+};
+
+