Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Unhandled Exception in AVIFileOpen()

Posted on 2004-08-23
7
Medium Priority
?
1,754 Views
Last Modified: 2011-09-20
I'm having a problem opening an AVI file.

Using VC++ 6.0

In my header file:

protected
    PAVIFILE* m_pAviFile;



in my class constructor:

CAviFile::CAviFile()
{
    AVIFileInit();
    m_pAviFile = NULL;
..//


and then later I try to open the file:

    HRESULT hr = AVIFileOpen(m_pAviFile, m_sMoviePath, OF_WRITE | OF_CREATE, NULL);


That line crashes "Unhandled exception in MYAPP.exe [AVIFIL32.dll]: 0XC0000005: Access Violation"

The file is however being created, I can browse to the folder in windows and see it, so it's not a path problem. So what's going wrong here?

thanks
-Paul
0
Comment
Question by:PMH4514
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 11870586
That should be more like

protected
   PAVIFILE m_pAviFile;

    HRESULT hr = AVIFileOpen(&m_pAviFile, m_sMoviePath, OF_WRITE | OF_CREATE, NULL);

since a 'PAVIFILE *' is expected to store a PAVIFILE in there.
0
 

Author Comment

by:PMH4514
ID: 11870720
oh duh.. damn those pointers!  

but....  wouldn't passing m_pAviFile (no ampersand) into AVIFileOpen, m_pAviFile having being defined as type PAVIFILE* be the same thing? or does "P" in "PAVIFILE" infer it's already a pointer type? (ie. I'm creating a pointer to a pointer by doing what I was doing??)

anyway - I made that change, and AVIFileOpen is no longer crashing. but now I'm getting the same error on this line:

HRESULT hr = AVIFileCreateStream(m_pAviFile, &m_psWrite, &strhdr);

where m_psWrite is defined in the header:
PAVISTREAM m_psWrite

and strhdr is defined locally within my method:

AVISTREAMINFO strhdr;
memset(&strhdr, 0, sizeof(strhdr));
strhdr.fccType                = streamtypeVIDEO;   // stream type
// etc..


0
 
LVL 86

Expert Comment

by:jkr
ID: 11870759
>>or does "P" in "PAVIFILE" infer it's already a pointer type?

Yes, these are MS' naming conventions.

>>now I'm getting the same error on this line:
>>HRESULT hr = AVIFileCreateStream(m_pAviFile, &m_psWrite, &strhdr);

Hm, that actually looks good. Have you tried to

ASSERT(m_pAviFile);
HRESULT hr = AVIFileCreateStream(m_pAviFile, &m_psWrite, &strhdr);

?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:PMH4514
ID: 11870767
actually, I think the CreateStream is crashing because my AVIFileOpen is still not working properly. I don't crash with the access violation, but the pointer remains NULL, and the result equals a long negative number..

(the fact that my code got to my AVIFileCreateStream() call in that state means I need better error trapping, but that's offtopic)

0
 

Author Comment

by:PMH4514
ID: 11870793
looks like we were typing at the same time..  I guess the problem is still that AVIFileOpen() isn't properly returning the file handle (though again, the file is being created, I see it in windows explorer)
0
 
LVL 86

Expert Comment

by:jkr
ID: 11871059
Are you sure you are filling in the header correctly? The sample at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_reading_from_one_stream_and_writing_to_another.asp ("Reading from One Stream and Writing to Another") illustrates how to use these APIs, and they're doing it exactly the same way.
0
 

Author Comment

by:PMH4514
ID: 11871062
Oh duh, once again I forgot to call CoInitialize()..

it's all set now, thanks!
-Paul
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

664 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question