Quicktime 7 API for Windows - couldNotResolveDataRef

0

I'm trying to use the Quicktime 7 API for Windows (I know) because eventually I'm going to try to change the audio channel layout flags in Quicktime files, but right now I'm simply trying to create a "Movie" object.

I'm very familiar with languages like Python and JavaScript, but very new to C++. Despite that, I'm able to get the following code to all link up and compile nicely:

#include <iostream>
#include <Movies.h>
#include <QTML.h>


int main()
{
    std::string mystring = "D:/CodingProjects/testfiles/mytestfile.mov";
    OSErr initerr = InitializeQTML(0L);
    OSErr entererr = EnterMovies();

    Movie myMovie;
    short myResID;
    Size mySize = (Size)strlen(mystring.c_str()) + 1;
    Handle myHandle = NewHandleClear(mySize);

    BlockMove(mystring.c_str(), *myHandle, mySize);

    OSErr newmovieerr = NewMovieFromDataRef(&myMovie, 0, &myResID, myHandle, URLDataHandlerSubType);
}

It all seems to run well, with initerr and entererr returning 0, and the entire program also exiting with 0. The problem is in the NewMovieFromDataRef function. newmovieerr seems to be returning code -2000 and not assigning anything (0x00000000) to myMovie. After looking this up, it turns out that this error code is a Quicktime error that means "couldNotResolveDataRef".

I've also tried creating a Movie using the function NewMovieFromHandle and got the same error code.

Can anyone help me figure out what I'm doing wrong?

c++
windows
quicktime
asked on Stack Overflow Jan 31, 2021 by CageFury • edited Jan 31, 2021 by CageFury

1 Answer

1

For anyone interested. I finally got it to work with this code.

#include <iostream>
#include <Movies.h>
#include <QTML.h>


int main()
{
    std::string mystring = "D:\\CodingProjects\\_ffmpeg\\test.mov";
    OSErr initerr = InitializeQTML(0L);
    OSErr entererr = EnterMovies();

    CFStringRef inPath = CFStringCreateWithCString(CFAllocatorGetDefault(), mystring.c_str(), CFStringGetSystemEncoding());    

    Movie myMovie;
    short myResID;
    Size mySize = (Size)strlen(mystring.c_str()) + 1;
    Handle myHandle = NewHandle(mySize);
    OSType myDataRefType = NULL;

    OSErr datareferr = QTNewDataReferenceFromFullPathCFString(inPath, kQTWindowsPathStyle, 0, &myHandle, &myDataRefType);
    OSErr newmovieerr = NewMovieFromDataRef(&myMovie, 0, &myResID, myHandle, myDataRefType);

}

A big part of it was using \\ in the path instead of /, and also using CFStringCreateWithCString to get a CFStringRef to pass into QTNewDataReferenceFromFullPathCFString to get the proper Handle and OSType to then pass into NewMovieFromDataRef.

answered on Stack Overflow Jan 31, 2021 by CageFury • edited Jan 31, 2021 by CageFury

User contributions licensed under CC BY-SA 3.0