Greetings,
I am trying to make a custom download manager in c#. The code compile, I
register it with gacutil and regasm, but when I open IE and click on a link
to download, I get the standard IE download dialog. Is there something I'm
missing? I am new to COM, so any help would be appreciated. Here is my
complete code:
/* BEGIN CODE */
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace MyDownloader
{
[ComImport, GuidAttribute("988934A4-064B-11D3-BB80-00104B35E7F9"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown),
ComVisible(false)]
public interface IDownloadManager
{
void Download(
System.Runtime.InteropServices.ComTypes.IMoniker pmk,
System.Runtime.InteropServices.ComTypes.IBindCtx pbc,
UInt32 dwBindVerb,
Int32 grfBINDF,
IntPtr pBindInfo,
String pszHeaders,
String pszRedir,
UInt32 uiCP
);
}
[ComImport, Guid("988934A4-064B-11D3-BB80-00104B35E7F9")]
public interface Downloader
{
}
[Guid("78BC4A4C-63B7-41CC-B287-858663AF4281"),
ClassInterface(ClassInterfaceType.None)]
public class MainClass : IDownloadManager
{
public MainClass()
{
}
public void Download(
System.Runtime.InteropServices.ComTypes.IMoniker pmk,
System.Runtime.InteropServices.ComTypes.IBindCtx pbc,
UInt32 dwBindVerb,
Int32 grfBINDF,
IntPtr pBindInfo,
String pszHeaders,
String pszRedir,
UInt32 uiCP)
{
MessageBox.Show("Got it!");
}
}
}
/* END CODE */
Thanks,
Kevin
Mattias Sjögren - 28 Jun 2007 06:37 GMT
Kevin,
>I am trying to make a custom download manager in c#. The code compile, I
>register it with gacutil and regasm, but when I open IE and click on a link
>to download, I get the standard IE download dialog. Is there something I'm
>missing?
Have you registered the download manager in the Registry?
Also, I believe you have to add the [MarshalAs(UnmanagedType.LPWStr)]
attribute to the pszHeaders and pszRedir parameters.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Kevin Cochran - 28 Jun 2007 15:40 GMT
Hi Mattias,
> Have you registered the download manager in the Registry?
I assumed that regasm did this for me. I had also used regsvcs, but it did
not change the results. Is there some other way to register my control?
Thanks,
Kevin
Mattias Sjögren - 28 Jun 2007 18:26 GMT
Kevin,
>I assumed that regasm did this for me.
It will only handle normal COM registration (unless you add additional
code in a ComRegisterFunction). Not the special registration
requirements for download managers
http://msdn2.microsoft.com/en-us/library/aa753618.aspx
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Kevin Cochran - 28 Jun 2007 19:42 GMT
Hi Mattias,
Perfect! Thanks for your help. There is still one problem, though, which is
a bit strange. For most downloads, this works. But there is a site which
pushes the file bits via an ADO Stream object. In this scenario, IE does not
use the download manager, but instead uses it's built-in. The content type
varies (application/octet-stream, audio/mp3, video/wmv, etc.), and the file
name is set properly in the content disposition.
Do you have any idea about this? Is there another interface I need to
implement in order to catch all downloads?
Thanks,
Kevin
> Kevin,
>
[quoted text clipped - 7 lines]
>
> Mattias
Mattias Sjögren - 28 Jun 2007 21:10 GMT
>Do you have any idea about this? Is there another interface I need to
>implement in order to catch all downloads?
Not a clue, sorry. I'd try asking in one of the IE developer
newsgroups.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Kevin Cochran - 28 Jun 2007 21:06 GMT
> Kevin,
>
[quoted text clipped - 7 lines]
>
> Mattias
Kevin Cochran - 28 Jun 2007 21:08 GMT
It looks like a specific problem with the Content-Disposition header, and can
be solved with RegisterBindStatusCallback. Any idea about how I would
implement that?
Thanks,
Kevin
> Kevin,
>
[quoted text clipped - 7 lines]
>
> Mattias