[Openmcl-devel] Handle/Pointer-to-Pointer FFI Question

Brent Fulgham bfulg at pacbell.net
Thu Dec 28 17:11:21 PST 2006


I'm attempting to call a QuickTime API function, which expects to be passed a 

First call is to a function to get the graphics importer.
OSErr GetGraphicsImporterForFile (
   const FSSpec         *theFile,
   ComponentInstance    *gi );
This call is done in Lisp as:

(rlet ((&gi :<G>raphics<I>mport<C>omponent)
        (Fsspec :<FSS>pec)
        (Fsref    :<FSR>ef)
        (&ImageDescriptor :<I>mage<D>escription)
... Get a FSRef from a CURL-based path (per Gary's earlier instructions)....

      (let ((err (#_GetGraphicsImporterForFile Fsspec &gi)))
         (unless (= err #$noErr)
                 (error "GetGraphicsImporterForFile ~a" err)))

This works great, returns no error, and produces a &gi value that can be used further in the routine.

Later (with the enclosing rlet above) I wish to get the graphics description of my image file, using the API call:
ComponentResult GraphicsImportGetImageDescription (
   GraphicsImportComponent    ci,
   ImageDescriptionHandle     *desc );

In this case, the component instance is supposed to be the actual GraphicsImportComponent object
(whereas the earlier call used a pointer to a <C>omponent<I>nstance).  The FFI seems to handle this
properly, or at least returns a <G>raphics<I>mport<C>omponent object that I can pass to the above
function without API complaints.

However, I wish to get an <I>mage<D>escription from the ImageDescriptionHandle*, which is effectively
a "ImageDescriptionHandle**".

This looks like the following (still inside the above rlet, so the stuff is in scope):

    (let ((err (#_GraphicsImportGetImageDescription &gi &ImageDescriptor)))
        (unless (= err #$noErr)
            (error "GraphicsImportGetImageDescription ~a" err)))

This seems to work, but produces incorrect results.  If I attempt to extract values from the ImageDescriptor:

 (let ((Width (rref &ImageDescriptor :<I>mage<D>escription.width))
       (Height (rref &ImageDescriptor :<I>mage<D>escription.height))
       (Depth (rref &ImageDescriptor :<I>mage<D>escription.depth))
...

I get very strange values.

I think my problem has to do with the pointer-to-pointer dereferencing, but I'm not sure how to express this using the OpenMCL FFI.

I could do something like:
  (let ((id-ptr (%get-ptr &ImageDescriptor)))
    (let ((err (#_GraphicsImportGetImageDescription &gi id-ptr)))
        (unless (= err #$noErr)
            (error "GraphicsImportGetImageDescription ~a" err)))

... But trying this also gives me weird values.

Can anyone help me figure out how to pass these FFI values?

Thanks,

-Brent






More information about the Openmcl-devel mailing list