How can I find the ComServer for a TWebBrowser Asy

2019-09-07 08:13发布

问题:

I've currently implemented this demo code for an APP sucessfully, http://www.jasontpenny.com/blog/2010/03/23/custom-protocol-handler-in-delphi/, However it seems to only work if the application is a single form application.

What I have found is that no Factory is returned for CoGetClassObject in:

procedure NewProtocolHandler(const aProtocolName: String; aProtocolCallback: TProtocolCallback; aProtocollType: TGUID);
var
    error : HRESULT;
begin
    if _protocol <> '' then
        raise Exception.Create('Currently only supports a single asynchronous pluggable protocol');

    _protocol := aProtocolName;
    _protocolCallback := aProtocolCallback;

    error := CoGetClassObject(Class_AsyncPlugProto_Protocol, CLSCTX_SERVER, nil, IClassFactory, Factory);
    CoInternetGetSession(0, InternetSession, 0);
    InternetSession.RegisterNameSpace(Factory, Class_AsyncPlugProto_Protocol, PChar(_protocol), 0, nil, 0);

    CoCreateInstance(aProtocollType, nil {was IUnknown(Self)}, CLSCTX_INPROC_SERVER, IUnknown, MyProtocol);
end;

and I've come to believe that this is due to an incorrect ComServer in the initialization section.

initialization
    TComObjectFactory.Create(ComServer, TAsyncPlugProto, Class_AsyncPlugProto_Protocol, 'Protocol', '', ciMultiInstance, tmApartment);
finalization
    EndProtocolHandler;
end. 

My web browser is not actually part of a form as I've allowed for multiple browsers to be used in my application, so the Browser is declared as a TWinControl and if the conditions are meet for a TWebBrowser its created through :

FBrowser := TWebBrowser.Create(nil);

and accessed as:

(FBrowser as TWebBrowser)

I'm fairly new to Com functions so how can I go about finding the ComServer relative to the TWebBrowser?

回答1:

I think you're confusing a number of things. If you'd like to make an APP, it would help if you've done some work with COM objects in several ways.

The ComServer object is actually a central object that wraps around some if the COM internals, ready for use in a Delphi project. Since Internet Explorer is not a Delphi project you won't be able to get its ComServer. Also if you have a close look at the TWebBrowser object, you'll notice that it also is a wrapper around the COM internals of the IWebBrowser2 object.

TWebBrowser and TChromium are two separate projects. As is a great operator but it can't change something to whichever you want.

If you want another example of an APP have a look here: http://xxm.svn.sourceforge.net/viewvc/xxm/trunk/Delphi/local/xxmHandler.pas?revision=235&view=markup