Internet Explorer Extension (COM)

M

Milos

Hello,

I need to create a IE Extension in C#. I want to add a button to IE standard
toolbar and then make IE call the DLL when button is clicked.
I have started with the following code

-------------------------------- code --------------------------------
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct OLECMDTEXT
{
public uint cmdtextf;
public uint cwActual;
public uint cwBuf;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=100)]public char rgwz;
}

[StructLayout(LayoutKind.Sequential)]
public struct OLECMD
{
public uint cmdID;
public uint cmdf;
}

[ComImport,
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleCommandTarget
{
void QueryStatus(ref Guid pguidCmdGroup, UInt32 cCmds,
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)]
OLECMD[] prgCmds, ref OLECMDTEXT CmdText);
void Exec(ref Guid pguidCmdGroup, uint nCmdId, uint nCmdExecOpt,
ref object pvaIn, ref object pvaOut);
}

[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(COM_Events))]
public class COMAddin: IOleCommandTarget
{
// ....

public void QueryStatus(ref Guid pguidCmdGroup,
UInt32 cCmds, OLECMD[] prgCmds, ref OLECMDTEXT CmdText)
{
// ....
}

public void Exec(ref Guid pguidCmdGroup, uint nCmdId,
uint nCmdExecOpt, ref object pvaIn, ref object pvaOut)
{
// .... I would add here OnClick actions
}

}
---------------------------- end code --------------------------------

But I don't know what to do next.

I know that I have to add a key in
HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Extensions.

And I have to somehow register the COM DLL, and create some GUIDs. But this
is a managed DLL, and all articles that I find on the net are related to
plain native C++. And I need to get the IE Document data somehow
(IHTMLDocument2 or something?)

Can anyone point me to a good article for this, or help me directly?

Thank you in advance,
Milos
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


In project properties/ Configuration Properties you have a "register for
COM Interop" set it.
Then you can decorate your class with Guid and/or ClassInterface
attributes.

For the registry you can use the classes provided by the framework.

I do not know how to make a COM be accesible to IE, but if you have some C
or VB code the above may hepl you.

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top