* Sync up to trunk head (r64829).
[reactos.git] / dll / win32 / avifil32 / api.c
index 8ef75d3..9ae26b9 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#define COBJMACROS
-
-#include "windef.h"
-#include "winbase.h"
-#include "winnls.h"
-#include "wingdi.h"
-#include "winuser.h"
-#include "winreg.h"
-#include "winerror.h"
-
-#include "ole2.h"
-#include "shellapi.h"
-#include "shlobj.h"
-#include "vfw.h"
-#include "msacm.h"
-
 #include "avifile_private.h"
 
-#include "wine/debug.h"
-#include "wine/unicode.h"
-
-WINE_DEFAULT_DEBUG_CHANNEL(avifile);
-
+#include <winreg.h>
 
 /***********************************************************************
  * for AVIBuildFilterW -- uses fixed size table
@@ -995,6 +973,7 @@ HRESULT WINAPI AVIBuildFilterA(LPSTR szFilter, LONG cbFilter, BOOL fSaving)
  */
 HRESULT WINAPI AVIBuildFilterW(LPWSTR szFilter, LONG cbFilter, BOOL fSaving)
 {
+  static const WCHAR all_files[] = { '*','.','*',0,0 };
   static const WCHAR szClsid[] = {'C','L','S','I','D',0};
   static const WCHAR szExtensionFmt[] = {';','*','.','%','s',0};
   static const WCHAR szAVIFileExtensions[] =
@@ -1023,8 +1002,8 @@ HRESULT WINAPI AVIBuildFilterW(LPWSTR szFilter, LONG cbFilter, BOOL fSaving)
 
   /*
    * 1. iterate over HKEY_CLASSES_ROOT\\AVIFile\\Extensions and collect
-   *    extensions and CLSID's
-   * 2. iterate over collected CLSID's and copy its description and its
+   *    extensions and CLSIDs
+   * 2. iterate over collected CLSIDs and copy its description and its
    *    extensions to szFilter if it fits
    *
    * First filter is named "All multimedia files" and its filter is a
@@ -1117,22 +1096,12 @@ HRESULT WINAPI AVIBuildFilterW(LPWSTR szFilter, LONG cbFilter, BOOL fSaving)
 
   /* add "All files" "*.*" filter if enough space left */
   size = LoadStringW(AVIFILE_hModule, IDS_ALLFILES,
-                    szAllFiles, sizeof(szAllFiles)/sizeof(szAllFiles[0])) + 1;
-  if (cbFilter > size) {
-    int i;
+                     szAllFiles, (sizeof(szAllFiles) - sizeof(all_files))/sizeof(WCHAR)) + 1;
+  memcpy( szAllFiles + size, all_files, sizeof(all_files) );
+  size += sizeof(all_files) / sizeof(WCHAR);
 
-    /* replace '@' with \000 to separate description of filter */
-    for (i = 0; i < size && szAllFiles[i] != 0; i++) {
-      if (szAllFiles[i] == '@') {
-       szAllFiles[i] = 0;
-       break;
-      }
-    }
-      
+  if (cbFilter > size) {
     memcpy(szFilter, szAllFiles, size * sizeof(szAllFiles[0]));
-    szFilter += size;
-    szFilter[0] = 0;
-
     return AVIERR_OK;
   } else {
     szFilter[0] = 0;
@@ -1253,7 +1222,7 @@ static BOOL AVISaveOptionsFmtChoose(HWND hWnd)
       pOptions->dwFlags |= AVICOMPRESSF_VALID;
 
     HeapFree(GetProcessHeap(), 0, afmtc.pwfxEnum);
-    return (ret == S_OK ? TRUE : FALSE);
+    return ret == S_OK;
   } else {
     ERR(": unknown streamtype 0x%08X\n", sInfo.fccType);
     return FALSE;
@@ -1524,7 +1493,7 @@ HRESULT WINAPI AVISaveVA(LPCSTR szFile, CLSID *pclsidHandler,
   HRESULT hr;
   int     len;
 
-  TRACE("%s,%p,%p,%d,%p,%p)\n", debugstr_a(szFile), pclsidHandler,
+  TRACE("(%s,%p,%p,%d,%p,%p)\n", debugstr_a(szFile), pclsidHandler,
        lpfnCallback, nStream, ppavi, plpOptions);
 
   if (szFile == NULL || ppavi == NULL || plpOptions == NULL)
@@ -2150,9 +2119,7 @@ HRESULT WINAPI EditStreamSetInfoA(PAVISTREAM pstream, LPAVISTREAMINFOA asi,
 
   TRACE("(%p,%p,%d)\n", pstream, asi, size);
 
-  if (pstream == NULL)
-    return AVIERR_BADHANDLE;
-  if ((DWORD)size < sizeof(AVISTREAMINFOA))
+  if (size >= 0 && size < sizeof(AVISTREAMINFOA))
     return AVIERR_BADSIZE;
 
   memcpy(&asiw, asi, sizeof(asiw) - sizeof(asiw.szName));
@@ -2173,6 +2140,9 @@ HRESULT WINAPI EditStreamSetInfoW(PAVISTREAM pstream, LPAVISTREAMINFOW asi,
 
   TRACE("(%p,%p,%d)\n", pstream, asi, size);
 
+  if (size >= 0 && size < sizeof(AVISTREAMINFOA))
+    return AVIERR_BADSIZE;
+
   hr = IAVIStream_QueryInterface(pstream, &IID_IAVIEditStream,(LPVOID*)&pEdit);
   if (SUCCEEDED(hr) && pEdit != NULL) {
     hr = IAVIEditStream_SetInfo(pEdit, asi, size);