How to implementing com interface?

Discussion in 'C++' started by kscho, Sep 16, 2003.

  1. kscho

    kscho Guest

    Hi~

    i wanna implement like COM interface, but I have problem pass this pointer.

    How can i pass this pointer in C ?

    How can i pass this pointer in CPP (thus not occured error)?

    //_______ test1.cpp _______________________________________

    #include <stdio.h>
    extern "C" void main_test();

    class ITest {
    public:
    virtual void ftn(int pParam) = 0;
    virtual void ftn222(int pParam) = 0;
    };



    class Test:public ITest{
    public:
    virtual void ftn(int pParam);
    virtual void ftn222(int pParam);
    int a;
    };

    // error occurs because this pointer passing
    void Test:: ftn(int pParam){
    a = 10; // this makes error, error occurs the time of access member
    valuable
    printf("ftn test\n");
    }


    void Test:: ftn222(int pParam){
    printf("ftn test222\n");
    }

    extern "C" ITest *createTest(void){
    return new Test();
    }

    extern "C" void deleteTest(void * pTest){
    delete (Test*)pTest;
    }

    int main(int argc, char* argv[]){
    main_test();
    return 0;

    }
    //_______test2.c _______________________________

    #include <stdio.h>

    typedef struct I_XX {
    void ( __stdcall *ftn ) (int );
    void ( __stdcall *ftn222 ) (int );
    } I_XX;


    typedef struct XX{
    const struct I_XX *lpVtbl;
    }XX;
    extern void *createTest(void);
    extern void deleteTest(void * pTest);
    void main_test()
    {
    XX* p = (XX*)createTest();
    p->lpVtbl->ftn(10);
    p->lpVtbl->ftn222(20);
    deleteTest(p);
    }

    i'm referenced basetype.h

    /** basetype.h

    STDMETHOD_(ULONG,AddRef) (THIS) PURE;

    #if defined(__cplusplus) && !defined(CINTERFACE)

    define THIS void

    #else

    #define THIS INTERFACE FAR * This

    #endif

    **/

    thanks in advance,
    cho.
     
    kscho, Sep 16, 2003
    #1
    1. Advertising

  2. kscho wrote in news:bk66l1$9s2$:

    > i wanna implement like COM interface, but I have problem pass this
    > pointer.
    >


    Your code has a compiler specific dependancies ( e.g. __stdcall and
    the way you assume stuff about the layout of vtables ). Standard C++
    doesn't even assume the existance of vtables, any mechanism which
    does the job is OK.

    You need to ask this in a compiler specific newsgroup or possibly
    a COM specific newsgroup.

    Look for a group's starting with comp.os.ms-windows.programmer.*
    and microsoft.public.* ( you may need to use microsoft's news server
    to post to these, so the comp... ones may be prefered).

    HTH

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Sep 16, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gomathi

    Implementing Interface

    Gomathi, Nov 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    557
    S.M. Altaf [MVP]
    Nov 17, 2005
  2. Manavendra Gupta
    Replies:
    1
    Views:
    360
    Manavendra Gupta
    Mar 7, 2004
  3. Robert Maas, see http://tinyurl.com/uh3t

    Trouble implementing an interface, strange compiler error

    Robert Maas, see http://tinyurl.com/uh3t, May 15, 2005, in forum: Java
    Replies:
    4
    Views:
    513
    Ross Bamford
    May 15, 2005
  4. golem
    Replies:
    13
    Views:
    789
    Nigel Wade
    Feb 17, 2006
  5. Henry Townsend
    Replies:
    6
    Views:
    445
    Oliver Wong
    May 29, 2006
Loading...

Share This Page