Author: Tomas Rutkauskas
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:
1
2 procedure AddProtocol(Details, Protocol, Command: string);
3 var
4 Reg: TRegistry;
5 begin
6 Reg := TRegistry.Create;
7 Reg.RootKey := HKEY_CLASSES_ROOT;
8 Reg.LazyWrite := false;
9 Reg.OpenKey(Protocol, true);
10 Reg.WriteString('', Details);
11 Reg.WriteString('URL Protocol', '');
12 Reg.OpenKey('shell\open\command', true);
13 Reg.WriteString('', command);
14 Reg.CloseKey;
15 Reg.free;
16 end;
17
18 //example
19
20 AddProtocol('URL: DKB Protocol', 'dkb',
21 '"D:\Projects\Programs\DKB\Compiled\dkb.exe" %1');
|