I just spent the last hour with this and I have no clue how would I found out this alone. I am trying to figure out the maximum keyframe space of a wmv file and for this I am using the Windows Media Format SDK and the wmvprop sample. At some point of the execution I would make a call for each video stream to find out this property by calling:
hr = pVideoMediaProps->GetMaxKeyFrameSpacing(&pllKeyFrameTime);
When I was stepping through my code and arrived to the call above I received the following error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
I must tell you this error message is dead scary, because I am not a COM guru, nor a C++ one. So I spent an hour trying to figure it out and changed all the calling convetions in my call, but no joy! Then I called for help. Another 20 minutes 2 people staring at the screen then my collegue Kalman suggested to comment out my code and see if that works. It worked! Then we know that I am crappy coder :) Another session of blank staring for 2 mins then I saw this piece: like couple of lines earlier:
hr = pConfig->QueryInterface(IID_IWMStreamConfig, (void **) &pVideoMediaProps);
and the definition of my variable like 30 lines earlier:
IWMVideoMediaProps *pVideoMediaProps = NULL;
so that tells me basically that I screwed this up by querying for one interface and supplying another interface to QueryInterface. So tho correct the error it should be queried like this:
hr = pConfig->QueryInterface(IID_IWMVideoMediaProps, (void **) &pVideoMediaProps);
Honestly, I do not understand what happens under the hood - I really would like too, so someone smart please explain it to me - and why this error message shown, but I thought that I would try to save some time to other people with this. I really hope that this will be handy for someone sometimes :)
Another interesting twist was that after looking at the documentation I learned that:
Remarks
This method retrieves the value set by SetMaxKeyFrameSpacing, or the default value for the key frame spacing, during the encoding process only. If called for a file that is open in the reader, the method always returns zero.
For more information, see the Remarks for SetMaxKeyFrameSpacing.
And I had a reader open and I received 0 as a result when I ignored this error! The moral of the story? COM rulez! Pay respect to it and documentation is your friend!