* Sync up to trunk head (r65074).
[reactos.git] / dll / cpl / desk / devsett.c
index 0bac48b..8006153 100644 (file)
@@ -1,12 +1,14 @@
 /*
-* COPYRIGHT:       See COPYING in the top level directory
+ * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS Display Control Panel
- * FILE:            lib/cpl/desk/devsett.c
+ * FILE:            dll/cpl/desk/devsett.c
  * PURPOSE:         ReactOS Display Control Panel Shell Extension Support
  */
 
 #include "desk.h"
 
+#include <cfgmgr32.h>
+
 #define NDEBUG
 #include <debug.h>
 
@@ -17,15 +19,15 @@ typedef struct _CDevSettings
     const struct IDataObjectVtbl *lpIDataObjectVtbl;
     DWORD ref;
 
-    CLIPFORMAT cfExtInterface; /* "Desk.cpl extension interface" */
-    CLIPFORMAT cfDisplayDevice; /* "Display Device" */
-    CLIPFORMAT cfDisplayName; /* "Display Name" */
-    CLIPFORMAT cfDisplayId; /* "Display ID" */
-    CLIPFORMAT cfMonitorName; /* "Monitor Name" */
-    CLIPFORMAT cfMonitorDevice; /* "Monitor Device" */
-    CLIPFORMAT cfDisplayKey; /* "Display Key" */
+    CLIPFORMAT cfExtInterface;      /* "Desk.cpl extension interface" */
+    CLIPFORMAT cfDisplayDevice;     /* "Display Device" */
+    CLIPFORMAT cfDisplayName;       /* "Display Name" */
+    CLIPFORMAT cfDisplayId;         /* "Display ID" */
+    CLIPFORMAT cfMonitorName;       /* "Monitor Name" */
+    CLIPFORMAT cfMonitorDevice;     /* "Monitor Device" */
+    CLIPFORMAT cfDisplayKey;        /* "Display Key" */
     CLIPFORMAT cfDisplayStateFlags; /* "Display State Flags" */
-    CLIPFORMAT cfPruningMode; /* "Pruning Mode" */
+    CLIPFORMAT cfPruningMode;       /* "Pruning Mode" */
 
     PWSTR pDisplayDevice;
     PWSTR pDisplayName;
@@ -81,7 +83,7 @@ pCDevSettings_AllocAndCopyString(const TCHAR *pszSrc)
     if (str != NULL)
     {
 #ifdef UNICODE
-        wcscpy(str,
+        StringCbCopyW(str, c * sizeof(WCHAR),
                pszSrc);
 #else
         MultiByteToWideChar(CP_ACP,
@@ -181,19 +183,19 @@ pCDevSettings_GetDeviceInstanceId(const WCHAR *pszDevice)
                             CM_LOCATE_DEVNODE_NORMAL);
     if (cr == CR_SUCCESS)
     {
-        DbgPrint("Success1\n");
+        DPRINT1("Success1\n");
         cr = CM_Get_Device_ID_Size(&BufLen,
                                    DevInst,
                                    0);
         if (cr == CR_SUCCESS)
         {
-            DbgPrint("Success2\n");
+            DPRINT1("Success2\n");
             lpDevInstId = LocalAlloc(LMEM_FIXED,
                                      (BufLen + 1) * sizeof(WCHAR));
 
             if (lpDevInstId != NULL)
             {
-                DbgPrint("Success3\n");
+                DPRINT1("Success3\n");
                 cr = CM_Get_Device_IDW(DevInst,
                                        lpDevInstId,
                                        BufLen,
@@ -204,7 +206,7 @@ pCDevSettings_GetDeviceInstanceId(const WCHAR *pszDevice)
                     LocalFree((HLOCAL)lpDevInstId);
                     lpDevInstId = NULL;
                 }
-                DbgPrint("instance id: %ws\n", lpDevInstId);
+                DPRINT1("instance id: %ws\n", lpDevInstId);
             }
         }
     }
@@ -554,7 +556,7 @@ CDevSettings_GetData(IDataObject* iface,
     PCWSTR pszRet = NULL;
     PWSTR pszBuf;
     PCDevSettings This = impl_from_IDataObject(iface);
-
+    
     ZeroMemory(pmedium,
                sizeof(STGMEDIUM));
 
@@ -660,11 +662,15 @@ CDevSettings_GetData(IDataObject* iface,
             pszRet = szEmpty;
 
         pszBuf = GlobalAlloc(GPTR,
-                             (_tcslen(pszRet) + 1) * sizeof(WCHAR));
+                             (wcslen(pszRet) + 1) * sizeof(WCHAR));
         if (pszBuf != NULL)
         {
-            _tcscpy(pszBuf,
-                    pszRet);
+            hr = StringCbCopy(pszBuf, (wcslen(pszRet) + 1) * sizeof(WCHAR), pszRet);
+            if (FAILED(hr))
+            {
+                GlobalFree(pszBuf);
+                return hr;
+            }
 
             pmedium->tymed = TYMED_HGLOBAL;
             pmedium->hGlobal = pszBuf;