]> git.sesse.net Git - vlc/blobdiff - activex/utils.cpp
Use playlist loop libvlc facility
[vlc] / activex / utils.cpp
index 46288b05ca92312191a7945fdf3321b94277143d..fdad6d4173573238bd4b91f3a52790f9b06b463a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * utils.cpp: ActiveX control for VLC
  *****************************************************************************
- * Copyright (C) 2005 VideoLAN (Centrale Réseaux) and its contributors
+ * Copyright (C) 2005 the VideoLAN team
  *
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
  *
@@ -17,7 +17,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "utils.h"
@@ -28,7 +28,7 @@
 
 using namespace std;
 
-char *CStrFromBSTR(int codePage, BSTR bstr)
+char *CStrFromBSTR(UINT codePage, BSTR bstr)
 {
     UINT len = SysStringLen(bstr);
     if( len > 0 )
@@ -37,29 +37,32 @@ char *CStrFromBSTR(int codePage, BSTR bstr)
                 0, bstr, len, NULL, 0, NULL, NULL);
         if( mblen > 0 )
         {
-            char *buffer = (char *)malloc(mblen+1);
+            char *buffer = (char *)CoTaskMemAlloc(mblen+1);
             ZeroMemory(buffer, mblen+1);
             if( WideCharToMultiByte(codePage, 0, bstr, len, buffer, mblen, NULL, NULL) )
+            {
+                buffer[mblen] = '\0';
                 return buffer;
+            }
         }
     }
     return NULL;
 };
 
-BSTR BSTRFromCStr(int codePage, const char *s)
+BSTR BSTRFromCStr(UINT codePage, LPCSTR s)
 {
     int wideLen = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
-    if( wideLen )
+    if( wideLen > 0 )
     {
-        WCHAR* wideStr = (WCHAR*)malloc(wideLen*sizeof(WCHAR));
+        WCHAR* wideStr = (WCHAR*)CoTaskMemAlloc(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);
+            bstr = SysAllocStringLen(wideStr, wideLen);
+            CoTaskMemFree(wideStr);
 
             return bstr;
         }
@@ -67,6 +70,28 @@ BSTR BSTRFromCStr(int codePage, const char *s)
     return NULL;
 };
 
+char *CStrFromGUID(REFGUID clsid)
+{
+    LPOLESTR oleStr;
+
+    if( FAILED(StringFromIID(clsid, &oleStr)) )
+        return NULL;
+
+#ifdef OLE2ANSI
+    return (LPCSTR)oleStr;
+#else
+    char *pct_CLSID = NULL;
+    size_t len = WideCharToMultiByte(CP_ACP, 0, oleStr, -1, NULL, 0, NULL, NULL);
+    if( len > 0 )
+    {
+        pct_CLSID = (char *)CoTaskMemAlloc(len);
+        WideCharToMultiByte(CP_ACP, 0, oleStr, -1, pct_CLSID, len, NULL, NULL);
+    }
+    CoTaskMemFree(oleStr);
+    return pct_CLSID;
+#endif
+};
+
 /*
 **  properties
 */
@@ -79,6 +104,7 @@ HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v)
     {
         DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
         VARIANT vres;
+        VariantInit(&vres);
         hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_USER_DEFAULT,
                 DISPATCH_PROPERTYGET, &dispparamsNoArgs, &vres, NULL, NULL);
         if( SUCCEEDED(hr) )
@@ -101,33 +127,61 @@ HRESULT GetObjectProperty(LPUNKNOWN object, DISPID dispID, VARIANT& v)
 HDC CreateDevDC(DVTARGETDEVICE *ptd)
 {
        HDC hdc=NULL;
-       LPDEVNAMES lpDevNames;
-       LPDEVMODE lpDevMode;
-       LPTSTR lpszDriverName;
-       LPTSTR lpszDeviceName;
-       LPTSTR lpszPortName;
-
-       if (ptd == NULL) {
+       if( NULL == ptd )
+    {
                hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
-               goto errReturn;
        }
+    else
+    {
+        LPDEVNAMES lpDevNames;
+        LPDEVMODE lpDevMode;
+        LPTSTR lpszDriverName;
+        LPTSTR lpszDeviceName;
+        LPTSTR lpszPortName;
 
-       lpDevNames = (LPDEVNAMES) ptd; // offset for size field
-
-       if (ptd->tdExtDevmodeOffset == 0) {
-               lpDevMode = NULL;
-       }else{
-               lpDevMode  = (LPDEVMODE) ((LPTSTR)ptd + ptd->tdExtDevmodeOffset);
-       }
+        lpDevNames = (LPDEVNAMES) ptd; // offset for size field
 
-       lpszDriverName = (LPTSTR) lpDevNames + ptd->tdDriverNameOffset;
-       lpszDeviceName = (LPTSTR) lpDevNames + ptd->tdDeviceNameOffset;
-       lpszPortName   = (LPTSTR) lpDevNames + ptd->tdPortNameOffset;
+        if (ptd->tdExtDevmodeOffset == 0)
+        {
+            lpDevMode = NULL;
+        }
+        else
+        {
+            lpDevMode  = (LPDEVMODE) ((LPTSTR)ptd + ptd->tdExtDevmodeOffset);
+        }
 
-       hdc = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, lpDevMode);
+        lpszDriverName = (LPTSTR) lpDevNames + ptd->tdDriverNameOffset;
+        lpszDeviceName = (LPTSTR) lpDevNames + ptd->tdDeviceNameOffset;
+        lpszPortName   = (LPTSTR) lpDevNames + ptd->tdPortNameOffset;
 
-errReturn:
+        hdc = CreateDC(lpszDriverName, lpszDeviceName, lpszPortName, lpDevMode);
+    }
        return hdc;
 };
 
+#define HIMETRIC_PER_INCH 2540
+
+void DPFromHimetric(HDC hdc, LPPOINT pt, int count)
+{
+    LONG lpX = GetDeviceCaps(hdc, LOGPIXELSX);
+    LONG lpY = GetDeviceCaps(hdc, LOGPIXELSY);
+    while( count-- )
+    {
+        pt->x = pt->x*lpX/HIMETRIC_PER_INCH;
+        pt->y = pt->y*lpY/HIMETRIC_PER_INCH;
+        ++pt;
+    }
+};
+
+void HimetricFromDP(HDC hdc, LPPOINT pt, int count)
+{
+    LONG lpX = GetDeviceCaps(hdc, LOGPIXELSX);
+    LONG lpY = GetDeviceCaps(hdc, LOGPIXELSY);
+    while( count-- )
+    {
+        pt->x = pt->x*HIMETRIC_PER_INCH/lpX;
+        pt->y = pt->y*HIMETRIC_PER_INCH/lpY;
+        ++pt;
+    }
+};