0

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?

Scott Alexander
  • 455
  • 2
  • 17
  • Wait, so are you using `TWebBrowser` or `TChromium` ? Could you edit your question to fix this (or describe what does it mean) ? – TLama Oct 24 '12 at 14:56
  • This issue is for TWebBrowser, even though my application can support Chromium. The Key issue is finding the ComService for the TWebBrowser. – Scott Alexander Oct 24 '12 at 15:11

1 Answers1

0

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

Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67
  • So It seems my knowledge on the ComServer is a bit flawed, in the two example APP's what exactly is the ComServer in reference to, if its not the TWebBrowswer? Ignore the Two browsers I was simply stating that the key variable was a TWinControl in case that would have an effect on the ComServer. (If Chromium does not load in the application than IE is used as the default). – Scott Alexander Oct 25 '12 at 08:33
  • Ahhh seen my error in the question (FBrowser as TChromium) is meant to be (FBrowser as TWebBrowser), Sorry for the confusion. – Scott Alexander Oct 25 '12 at 08:46
  • Turns out its was not an issue with the APP, but with my COM set up, will teach me to rush something :) Cheers – Scott Alexander Oct 29 '12 at 14:27
  • @ScottAlexander Can you post the solution? Thanks. – user3060326 Apr 27 '14 at 18:13