AviFileOpen Handler Problem



I found some problems in dealing with Avi functions when trying the following
code (on visual Studio 2005 VC++):

#include <Vfw.h>

using namespace System;

using namespace System::IO;

using namespace System::Windows::Forms;

using namespace System::Diagnostics;

using namespace System::Runtime::InteropServices;

{

Stream^ myStream;

OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;



openFileDialog1->Filter = "Audio-Video Interleaved (*.avi)|*.avi";



if (openFileDialog1->ShowDialog()==System::Windows::Forms::DialogResult::OK)

{

if ( (myStream = openFileDialog1->OpenFile()) != nullptr )

{

//declaration of some parameters

#define _SIZE MAX_PATH //Size of [char] buffers

PAVIFILE aviFile; //Handle for AVI file

PAVISTREAM aviStream; //Handle for video stream

AVISTREAMINFO aviStreamInfo; //Information about video stream

#define ErrAVIFile "Unable to open AVI file!"

#define ErrNoAVI "We need AVI file to work with!"

#define ErrGetStream "Unable to get video stream!"

#define ErrStreamInfo "Unable to resolve information about stream!"



String^ AVIFileName1; //AVI file

AVIFileName1 = openFileDialog1->FileName;

if (AVIFileName1[0]==0) //We need AVI file to work with

Debug::WriteLine(ErrNoAVI);



//Convert AVIFileName1 from String^ to LPCTSTR type.

IntPtr ptr = Marshal::StringToHGlobalAnsi(AVIFileName1);

LPCTSTR AVIFileName = reinterpret_cast<LPCTSTR>(ptr.ToPointer());

Marshal::FreeHGlobal(ptr);



AVIFileInit();

//The AVIFileOpen function opens an AVI file and returns the address of a
file interface used to access it.

int retVal=AVIFileOpen(&aviFile,AVIFileName,OF_READ,NULL);

if (retVal!=0)

Debug::WriteLine(ErrAVIFile);

if (retVal==REGDB_E_CLASSNOTREG)

Debug::WriteLine("According to the registry, the type of file
specified in AVIFileOpen does not have a handler to process it. ");





//The AVIFileGetStream function returns the address of a stream interface
that is associated with a specified AVI file.

retVal=AVIFileGetStream(aviFile,&aviStream,streamtypeVIDEO,0);

if (retVal!=0)

AVIFileExit(),Debug::WriteLine(ErrGetStream);

//The AVIFileRelease function decrements the reference count of an AVI file
interface handle and closes the file if the count reaches zero.

AVIFileRelease(aviFile);

//The AVIStreamInfo function obtains stream header information.

retVal=AVIStreamInfo(aviStream,&aviStreamInfo,sizeof(aviStreamInfo));

if (retVal!=0)

AVIFileExit(),Debug::WriteLine(ErrStreamInfo);



myStream->Close();

}

}

}



The Problem appeared when using AviFileOpen, I got "Unable to open AVI file!"

The function returns REGDB_E_CLASSNOTREG ("According to the registry, the
type of file specified in AVIFileOpen does not have a handler to process it.
")

When the debug continued to the next function AVIFileGetStream the program
broke and the following message appeared (First-chance exception at
0x73b55d6a in PixelPrecision.exe: 0xC0000005: Access violation reading
location 0x00000000.

A first chance exception of type 'System.AccessViolationException' occurred
in PixelPrecision.exe

An unhandled exception of type 'System.AccessViolationException' occurred in
PixelPrecision.exe



Additional information: Attempted to read or write protected memory. This is
often an indication that other memory is corrupt.)



I added the Vfw32.lib to the project>properties>Linker>Input>Additional
Dependencies

According to the problem: there is something wrong with the RIFF (Header)of
the Avi file, So I checked many different avi files and got the same problem.

Another possibilty for that problem is the Registry problem So I checked the
registry to make sure that the avi is right configured:

HKEY_CLASSES_ROUTE\.avi:

Avifile

HKEY_CLASSES_ROUTE\.avi\PersistentHandler:

{098f2470-bae0-11cd-b579-08002b30bfeb}

HKEY_CLASSES_ROUTE\AviFile\RIFFHANDLERS\Avi:

{00020000-0000-0000-C000-000000000046}

HKEY_CLASSES_ROUTE\AviFile\RIFFHANDLERS\Wave:

{00020003-0000-0000-C000-000000000046}

So could you figure out what’s the problem and make the corrections for the
previous code…
Thanks A lot
.



Relevant Pages

  • Re: Timecode location in avi file
    ... A valid AVI file must conform to ... since they define the new 'iavs' stream type ... AVI file: you need to actually understand the MPEG-4 ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: .AVI file
    ... plus video. ... It has just this one .AVI file on CD ... WMP has the ability to play .avi files. ... and installed VLC Media Player. ...
    (microsoft.public.windowsxp.newusers)
  • Re: [SLE] can I convert a dvd to mpeg, avi. . . OFF LIST
    ... Also try avidemux2 home page. ... AVI: Missing video strem!? ... for quality try the FFm AC3 codec. ... I get a .avi file but it crashes Mplayer. ...
    (SuSE)
  • how do you get a good, small AVI from Premiere?
    ... How can I get Premiere 7 to export a good quality, full size, full ... frame rate AVI file for playback in Windows media player or other ... AVI file from some footage that I shot on a Canon GL2. ...
    (rec.video.desktop)
  • Cant save to DV-AVI..... continued
    ... I'm having similar situations from other user postings that I can't save to ... I a have 37 minute project which will equate to 8.7 GB AVI file. ... I do have 10.7 GB of free HDD space to create a 8.7 GB avi file. ...
    (microsoft.public.windowsxp.moviemaker)

Loading