Zitat von
marabu:
Wieso denn "unterschiedliche" QueryInterface? Die Interfaces teilen sich doch eine Implementierung dieser Methode - oder verstehe ich dich falsch?
marabu
Schon, jedoch ist in diesem C-Beispiel folgendes:
Delphi-Quellcode:
STDMETHODIMP CHTMLEditControlSite::XHTMLEditHost::QueryInterface(REFIID iid, LPVOID far* ppvObj)
{
METHOD_PROLOGUE(CHTMLEditControlSite, HTMLEditHost);
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
und
Delphi-Quellcode:
STDMETHODIMP CHTMLEditControlSite::XHTMLElementBehaviorFactory::QueryInterface(REFIID iid, LPVOID far* ppvObj)
{
METHOD_PROLOGUE(CHTMLEditControlSite, HTMLElementBehaviorFactory);
*ppvObj = NULL;
if (IsEqualIID(iid, IID_IElementBehaviorFactory))
{
*ppvObj = (IUnknown *) this;
return S_OK;
}
else if (IsEqualIID(iid, IID_IElementBehavior))
{
*ppvObj = (IUnknown *) &pThis->m_xHTMLElementBehavior;
return S_OK;
}
return E_NOTIMPL;
}
und
Delphi-Quellcode:
STDMETHODIMP CHTMLEditControlSite::XHTMLPainter::QueryInterface(REFIID iid, LPVOID far* ppvObj)
{
METHOD_PROLOGUE(CHTMLEditControlSite, HTMLPainter);
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
Also drei Mal QueryInterface mit unterschiedlichen Auswirkungen...
Ich habe es jetzt so gelöst, da das ursprüngliche Obj kein Interface ist und ich keinen TypCast hingekiregt habe...
Delphi-Quellcode:
function TForm1.MyQuery(out Obj: IInterface): HRESULT;
begin
Obj := Self as IHTMLPainter;
Result := S_OK;
end;
function TForm1.MyQuery2(out Obj: IInterface): HRESULT;
begin
Obj := Self;
Result := S_OK;
end;
function TForm1.MyQuery3(out Obj: IInterface): HRESULT;
begin
Obj := Self as IElementBehaviorFactory;
Result := S_OK;
end;
function TForm1.MyQuery4(out Obj: IInterface): HRESULT;
begin
Obj := Self as IElementBehavior;
Result := S_OK;
end;
function TForm1.QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
begin
Inherited QueryInterface(IID,Obj);
if IsEqualGUID(IID,IID_IElementBehaviorFactory) then
begin
result := MyQuery3(IUnknown(Obj));
exit;
end;
if IsEqualGUID(IID,IID_IElementBehavior) then
begin
result := MyQuery4(IUnknown(Obj));
exit;
end;
if IsEqualGUID(IID, IID_IHTMLPainter) then
begin
result := MyQuery(IUnknown(Obj));
exit;
end;
if IsEqualGUID(IID, IID_IUnKnown) then
begin
result := MyQuery2(IUnknown(Obj));
exit;
end;
result := E_NOTIMPL;
end;
Ich habe ein Testprogramm mit EmbeddedWB! Diese
Unit "schafft" es den QueryInterface zu erhalten.
Bei mit kommt im Queryinterface immer nur ein TGUID = '{00000000-0000-0000-C000-000000000046}'
einmal und sonst NIX!
Frank