I
IK
Hello All,
Please excuse me for posting this here, but I don't find any other group where I
will get a proper answer. This is about clarifying the C++ part of COM.
I understand that COM is a mechanism by which interface and implementation is
seperated. A basic com implementation in c++ can be as follows.
// Dev-CPP
// interface
// Ai.h
class Ai {
public:
virtual void foo() = 0;
virtual Ai* GetInterface() =0;
};
// Implementation
// A.h
#include "Ai.h"
class AImpl : public Ai {
public:
void foo();
Ai* GetInterface();
};
// A.cpp
#include "A.h"
AImpl::foo()
{
}
Ai* AImpl::GetInterface()
{
Aimpl* imp = new Ai();
return (Ai*) imp;
}
// vc++
// Code using the interface
#include "Ai.h"
int main()
{
// Ai* a = NULL;
// Load the dll
// Get the address to the function GetInteface
// a = <address>->GetInterface();
// a->foo()
}
This is the principle of COM. I couldnt make out why in the interface it should
be "pure" virtual function ? Why cant it be simple virtual function like.
virtual void foo(); Will it really matters, since the examples I have written,
doesnt have any problem while compiling and running. The test I did is that I
did the implementation on Dev-Cpp which uses MingW, then I called this DLL from
VC++ , to know whether any name mangling issues creates any problem. Can
somebody please help me to understand it better ?
Thanks and Regards
Ik
Please excuse me for posting this here, but I don't find any other group where I
will get a proper answer. This is about clarifying the C++ part of COM.
I understand that COM is a mechanism by which interface and implementation is
seperated. A basic com implementation in c++ can be as follows.
// Dev-CPP
// interface
// Ai.h
class Ai {
public:
virtual void foo() = 0;
virtual Ai* GetInterface() =0;
};
// Implementation
// A.h
#include "Ai.h"
class AImpl : public Ai {
public:
void foo();
Ai* GetInterface();
};
// A.cpp
#include "A.h"
AImpl::foo()
{
}
Ai* AImpl::GetInterface()
{
Aimpl* imp = new Ai();
return (Ai*) imp;
}
// vc++
// Code using the interface
#include "Ai.h"
int main()
{
// Ai* a = NULL;
// Load the dll
// Get the address to the function GetInteface
// a = <address>->GetInterface();
// a->foo()
}
This is the principle of COM. I couldnt make out why in the interface it should
be "pure" virtual function ? Why cant it be simple virtual function like.
virtual void foo(); Will it really matters, since the examples I have written,
doesnt have any problem while compiling and running. The test I did is that I
did the implementation on Dev-Cpp which uses MingW, then I called this DLL from
VC++ , to know whether any name mangling issues creates any problem. Can
somebody please help me to understand it better ?
Thanks and Regards
Ik