Re: Problem with VB -> C++ interface pointer
Hi,
Thanks for the reply but I'm afraid I still don't see why it doesn't
work. I understand what you are saying about the cast and totally
agree that if they were completely separate objects then pSpot would be
garbage. But (and this is where I might have things muddled) they are
not sepeare objects...are they? Doesn't CSpot derive from ISpot via
IDispatchImpl?
I'm very new to COM so maybe it isn't as simple as I think. I see it
like this:
class ClassA : public ClassB
{
public:
void foo();
};
ClassB* myClass = new ClassA();
Bar(myClass);
void Bar (ClassB* pMyClass)
{
ClassA* pClassA = reinterpret_cast<ClassA*>(pMyClass);
pClassA->foo();
}
This should work fine (not the best code, but it would work). My
understanding is that I am doing this in COM (maybe the QueryInterface
should be replaced with a dynamic_cast) - so maybe there is something
COM related that I am not understanding that stops it from being a
valid thing to do?
What I am ultimately trying to achieve here is that I want to call a
function of CSpot from within the C code. I thought I could retrieve
the CSpot* from the ISpot* so that I could do this.
I hope that all makes sense!
Thanks for any help.
Cheers,
Steve
Igor Tandetnik wrote:
"spforeman" <google@sforeman.com> wrote in message
news:1164622183.990036.71710@f16g2000cwb.googlegroups.com
STDMETHODIMP CFoo::ProcessSpot(ISpot *pAnalysisSpot)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CComObject<CSpot> *pSpot = 0;
hr = pAnalysisSpot->QueryInterface(IID_ISpot, (void **)&pSpot)
What exactly is that supposed to achieve? You query for IID_ISpot, you
get back ISpot* pointer, not CComObject<CSpot>. The net effect of this
call is the same as a simple cast:
CComObject<CSpot> *pSpot =
reinterpret_cast<CComObject<CSpot> *>(pAnalysisSpot);
Do you see now why it won't work?
When I trace through the code I can step into the code where VB sets x
and y to be -1, but when ProcessSpot is stepped into and
QueryInterface is called pSpot has garbage in the x and y values.
pSpot pointer itself is garbage.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925