2005. szeptember 2., péntek

Plug-in Internet Protocols (without DLL's)


Problem/Question/Abstract:

Show how to make a plugin protocol which executes your program and can pass variables to your application (like mailto:, http:, telnet:, outlook:,...)

Answer:

After searching through the internet for a way to integrate my application into Internet Explorer in the form of a protocol I found 2 different ways that were documented and included delphi code:

myprotocol://
http://mynamespace//

However I was looking for a way which would look like this:

myprotocol:

Eventually I gave up, until I noticed that on http://messenger.yahoo.com/messenger/imv they used this to execute a chat window with the desired theme. So I decided to look in the registry (as with all previous work I had discovered that the relevant data, usually including CLSID's would be linked together in the registry) and I discovered something
incredibly simple yet effective. Rather than using a DLL and CLSID's they had simply added some keys and values to the HKEY_CLASSES_ROOT exactly the same way as you would if you were associating a file-type. However there were 2 abnormal values:

HKEY_CLASSES_ROOTymsgr (Default) was equal to "URL: YMessenger Protocol"
There was a blank string added as HKEY_CLASSES_ROOTymsgr "URL Protocol"

After changing the default value I found that it made no difference, so all you need to do is to add a blank string named "URL Protocol".

This type of protocol can take parameters, which are parsed as follows:
Lets say that our program is named c:\program.exe and our protocol is program: if you use program:minimize, this is parsed asif you entered the following at the commandline:

c:>program.exe program:minimize

therefore ParamStr(1) is equal to program:minimize

Now, if you are wondering what this has to do with myprotocol:// type protocols, then I think you dont quite understand what was written above. Despite the fact that our protocol program: does not end with //, does not mean that we can not use it in the same way, after all, program: does take parameters, therefore you can actually use myprotocol:// and simply ignore that prefix.

Heres some code to add your program as a protocol:

procedure AddProtocol(Details, Protocol, Command: string);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  Reg.LazyWrite := false;
  Reg.OpenKey(Protocol, true);
  Reg.WriteString('', Details);
  Reg.WriteString('URL Protocol', '');
  Reg.OpenKey('shell\open\command', true);
  Reg.WriteString('', command);
  Reg.CloseKey;
  Reg.free;
end;

example

AddProtocol('URL: DKB Protocol', 'dkb',
  '"D:\Projects\Programs\DKB\Compiled\dkb.exe" %1');

Nincsenek megjegyzések:

Megjegyzés küldése