FactoryXCode / MfPack

Delphi translations for Microsoft Media Foundation and related API's
Mozilla Public License 2.0
80 stars 22 forks source link

Wrong translation of SAL Annotations #3

Closed pyscripter closed 4 years ago

pyscripter commented 4 years ago

Windows header files have SAL annotations that make the indent of the code explicit. An example of such annotation is _Out_writesbytes. See the Annotating function parameters and return values topic. The SAL annotations should be ignored.

Example: In d2d1svg.h you have:

    STDMETHOD(GetAttributeValue)(
        _In_ PCWSTR name,
        D2D1_SVG_ATTRIBUTE_POD_TYPE type,
        _Out_writes_bytes_(valueSizeInBytes) void *value,
        UINT32 valueSizeInBytes 
        ) PURE;

This is translated as:

    function GetAttributeValue(name: PCWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_POD_TYPE;
                               out value {IUnknown} ;
                               valueSizeInBytes: UINT32): HResult; overload; stdcall;

This should be:

    function GetAttributeValue(name: PCWSTR;
                               _type: D2D1_SVG_ATTRIBUTE_POD_TYPE;
                               value: Pointer;
                               valueSizeInBytes: UINT32): HResult; overload; stdcall;

The above has been tested and it works.

FactoryXCode commented 4 years ago

Thank you. This will be implemented in #2 The Models release.

FactoryXCode commented 4 years ago

You shouldn't take the SAL for granted. For instance when a callback function parameter is declared as [in], in Delphi this should be a var to avoid a $FFFFFFFF (nil) pointer exception, however on FPC this works. And so there are many others behaving different than C/C++ compiler meanings that are valid for C/C++ but not for Delphi. The only way is testing, other ways it would be easy to translate C/C++ API's, don't you think? By the way: at the time MfPack was introduced, there was a poor or wrong documentation from MS. Since Docs is introduced it gets a lot better, but still has errors and incompletions. That is for the interface function sequences as wel a different explanation comparing the header files. We keep working on it.