K
kscho
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.
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.