some unimplemented COM stuff

David Hagood wowbagger at sktc.net
Wed May 30 06:55:28 CDT 2001


> Because all I have is an IDispatch pointer and a vtable offset to the method. 
> Calling Invoke itself is not a problem at all. The method to be called by 
> Invoke isn't known at compile time.
> -Malte
> 

It sounds to me like you have an impedance mismatch: you have a system 
that wants to call a C linkage function, and you want to tie it into a 
C++ object.

What you'll have to do is something like this:

class Base_class
{
    ...
    virtual RETTYPE Real_func(arg1, arg2, <etc>) = 0;

    static RETTYPE Entry_func_stub(void *dis, arg1, arg2, <etc>)
    {
        Base_class *ptr = (Base_class *)dis;
        return dis->Real_func(arg1,arg2,<etc>);
    }
    void Hook_up_function(void)
    {
       Set_some_func_ptr(Entry_func_stub,(void *)this);
    }
};

....

class Child1: public Base_class
{
     RETTYPE Real_func(arg1,arg2,<etc>);
};

Class Child2: public Base_class
{
     RETTYPE  Real_func(arg1,arg2,<etc>);
};

The stub function in the base class can be coorced into having non-C++ 
linkage with an appropriate declaration, and will call the appropriate 
vtable entry and offset the this pointer correctly.

While I've not done this under Wine or Windows, I have done this sort of 
thing in several RTOSs with great success.





More information about the wine-devel mailing list