Question

My idea is to check if this dll has the version i need or is it older or newer? I'm trying to use a THUNK/Trampoline function.

here is my usage in a different *.dll file.

int FilterVersion(CBaseFilter* pFilter)
{
 //this is line 178
    void* ProgVersion = (CBaseFilter::AbstractProgVersion)(void *)&CBaseFilter::FilterVersionStatic;
    return (*(CBaseFilter::AbstractProgVersion)ProgVersion)(*pFilter);
}

This is the declaration of the class in which i declared the trampoline.

class PROG_CORE_API CBaseFilter
{
friend class CProgEngineInternal;

// Trampoline Design pattern
// this FilterVersion function will be used on a global function exported from a 
// cpp file exporting the dlls functions (therfore must be: static = global).
// it will use an arbitrary BaseFilter object - so Pure abstract function will
// make it possible to use polimorphism to all types of derived classes objects.

public:

    typedef int (*AbstractProgVersion)(CBaseFilter&);

    virtual int FilterVersionAbs() =0 ; 

    // a single spot (static) where all derived implemented filters versions tested. 
    // developer can specify version numbers to prohibit from running
    // returning 0 should block the filter from loading.

    static int FilterVersionStatic(CBaseFilter& FilterObj)
    {
        // version is 4 bytes 
        return FilterObj.FilterVersionAbs();
    }

    mutable int m_Version;

private:.....

The warning i get is:

GCC Build Error in - AddBorders_F.cpp:178:76: error: invalid conversion from ‘CBaseFilter::AbstractProgVersion {aka int (*)(CBaseFilter&)}’ to ‘void*’ [-fpermissive]
GCC Build Error in - AddBorders_F.o] Error 1
GCC Build Error in - make: *** [AddBorders] Error 2

as far as my search goes i understand i'm missing a casting to but i don't understand why?

Was it helpful?

Solution

I'm not sure what you are trying to do here, but it that line is broken in more ways that one. (And no, it has nothing to do with any casts to int *. Where did int * even come from? There's no int * anywhere in your code.)

The last conversion in your convoluted conversion sequence is to CBaseFilter::AbstractProgVersion type, which is a function pointer type. But then you attempt to initialize a void * variable with it. Function pointer types are not implicitly convertible to void *. That's your error.

If you want to force that conversion with an explicit cast, you can do

void* ProgVersion = (void *) &CBaseFilter::FilterVersionStatic;

What was the point of that extra conversion to CBaseFilter::AbstractProgVersion?

But in any case, void * is a data pointer type that should not be mixed with function pointer types. The language does not support conversions between data pointers and function pointers. The entire approach is hopelessly broken.

In fact, why on Earth are you even doing all these conversions? Why not just

int FilterVersion(CBaseFilter* pFilter)
{
    return CBaseFilter::FilterVersionStatic(*pFilter);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top