473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to implementing com interface?

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.
Jul 19 '05 #1
1 3573
kscho wrote in news:bk**********@news1.kornet.net:
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/
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Martyn Lawson | last post by:
Hi, I am currently working as an Analyst on a .NET Web Project using ASP.NET and C#.NET. I have a couple of, at least what should be, quick questions: 1. My understanding of UML says that...
4
by: Frank J. Reashore | last post by:
Hello Everyone, I am implementing a simple interface in C# using Visual Studio .net and was quite surprised to discover that the C# compiler does NOT complain if a method on the interface is not...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
0
by: Yatin Bhuta | last post by:
Hi, I have an interface in vb 6.0. It has a property set member, which takes a parameter by reference. When I try to implement this interface in my vb.net project it gives me an error saying...
7
by: Scott M. | last post by:
In a typical class, do I need to indicate that it implements the IDisposable interface and then create a Dispose method that implements the Dispose required by the IDisposable interface or can I...
2
by: larzeb | last post by:
I receive the following error from the compiler: ScheduledInfo' must implement 'Property AddrLine1() As String' for interface 'ICASSBatch'. Implementing property must have matching...
3
by: David Veeneman | last post by:
I'm new to VB.NET, and I am translating an object model from C# to VB.NET, and I have come across an odd problem implementing an interface. The interface is a custom interface, IDrillDown, which...
0
by: ZA_AJR | last post by:
Hi All I have a class (aClass, derived from aBaseClass) with implements an interface IMyInterface. aClass also has a private member of type aNotherClass which raises various events. I would like...
6
by: Raj Wall | last post by:
Hi, I am trying to implement the IEqualityComparer interface for a struct so I can use it as the Key for a Dictionary. My struct declaration has: public struct Ring : IEqualityComparer {...
5
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.