I followed the instructions from this source : http://www.codeguru.com/cpp/com-tech/atl/atl/article.php/c11007/Customize-an-IE-Context-Menu-to-Add-CodeGuru-Favorites.htm to add a context menu entry and to call a method of an ActiveX control through Javascript. This is the important part :
<SCRIPT LANGUAGE="JavaScript">
var parentwin = external.menuArguments;
var doc = parentwin.document;
var str = new String(parentwin.event.srcElement.name);
var oFav = new ActiveXObject("CodeguruFavorites.CGFavorites");
oFav.ShowDefaultContextMenu(parentwin,doc.title, doc.location);
</SCRIPT>
In this example, the author sends to the ActiveX method the title of the web page and the URL of the web page I triggered the context menu on.
I want to know how to get the URL of the image I triggered the context menu on.
I found the answer in this post: How can one identify the currently clicked link with Javascript?.
The object on which the context menu is triggered is menuArguments.event.srcElement . It is passed to the ActiveX control's method as an IDispatch interface pointer. On this pointer you can call QueryInterface to get a pointer to a IHTMLImgElement.