Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to implementing com interface?

Reply
Thread Tools

How to implementing com interface?

 
 
kscho
Guest
Posts: n/a
 
      09-16-2003
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 Testublic 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.


 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      09-16-2003
kscho wrote in news:bk66l1$9s2$(E-Mail Removed):

> 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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Implementing Interface Gomathi ASP .Net 1 11-17-2005 03:09 PM
Implementing the CORDIC algorithm without using Real Data Type Johnsy Joseph VHDL 2 10-29-2004 10:49 AM
Implementing E1 - E3 Dev VHDL 1 09-09-2004 09:06 AM
vhdl for implementing pre-fetch and an instruction cache Eqbal Z VHDL 3 11-16-2003 06:07 AM



Advertisments