Reputation: 97
I am using COM to communicate between C++ & C#. My Problem is I have implemented method which contains the parameter as interface object & that interface is implemented by C++ Class which is again implemented by another C++ class. My Code Scenario in C# is mentioned below:
namespace Example
{
public class First:ITest
{
void GetObjectOfC#Interface(ISample sample);
}
}
namespace Example
{
Interface ISample
{
void Test();
}
}
the Class First as well as ITest interface these are COmVisible ,Exposed to C++ Via Com. ISample interface also exposed in the COM but not implemented by C# class First.
Code Scenario in C++:
Class SampleFirst: public Example::ISample
{
};
This SampleFirst class is again Inherited by another C++ Class header file as below :
Class SampleSecond:public SampleFirst
{
public:
void MakeAnObject();
private:
Example::ITestPtr _testPtr;
Example::ISamplePtr _samplePtr;
};
and in the SampleSecond.Cpp file ,
void SampleSecond::MakeAnObject()
{
_testPtr.CreateInstance(__uuidof(Example::First));
samplePtr=this;
_testPtr->GetObjectOfC#Interface(samplePtr);
}
Here this means same class object assigned to samplePtr by considering the Inheritance Functionality. but in the .tli File ,Fails the HResult.Please Let me know if any Solution to the same .
Upvotes: 0
Views: 322
Reputation: 314
No need of static cast only by simple casting i.e.(ISample)this
in QueryInterface is enough
Upvotes: 2
Reputation: 97
To Solve the above problem this Link is very useful as i was doing the silly mistake while implementing the QueryInterface and their was confusion for the interface pointer.
Upvotes: 0