Working With Microsoft.mshtml.dll and SHDocVw.dll

Introduction

This article contains a discussion on Microsoft.mshtml.dll and SHDocVw.dll.

Background

I was working on BHO for IE in C#. Initially I did not know any thing about BHO and IE extensions. I read articles about the architecture and related information from MSDN. I also read about the architecture of IE from MSDN.

But I got my best understanding of BHO from CodeProject from this article by Pavel Zolnikov. I have listed here some problems that I faced and the solutions to those problems.

Microsoft.mshtml.dll and SHDocVW.dll

I was working on the BHO toolbar and I was trying to access an Object element (<object> tag), Image element (<img> tag), and Embed element (<embed> tag). I had no idea how to get these elements.

I had two solutions:

Use JavaScript to get an element.

Retrieve the Object directly from the page [like from the IE Developer ToolBar]

I used both of them because in many cases the second approach failed to detect the Object tag.

There was a problem with this method. Implementing the above code stopped the actual events of the browser. Events on the web browser were not fired. In other words, events of the web browser were locked. This was an annoying problem, but I found the solution for this problem here by Rick Strahl.

Using the above code, I was able to access the frame but it was giving me an Access Denied Exception. I was trying to attach an event with a Frame/IFrame Document but there were same problems. Finally I got a solution from here. I implemented a solution as follows:

Comments and Discussions

Please help me that how i click on save button on file save dialog for downloading file.
I am able to sign in and go on some links on my website but i am stuck here when i am trying to download csv file on button click event. This issue is just because of FileSave Dialog in Internet Explorer.

Please help me as soon as possible.

Really thanks.
Waiting for your response. (Any Suggestion or idea from You will be helpful for me )
Thanks Again.

Thanks for reply.
I need to download csv file from website after login. For downloading file login is required.
I am able to login and go specific link and click button for file download. When i click button for downloading file. Internet Explorer showing dialog to save file. So i need to click on save button so that file should be save in my download folder.

Using WebClient i don't now how to login ,because without login directly i can't access/download file.

I am encountering a very strange issue with the toolbar. I am using this toolbar to navigate to a custom html page which i am creating on the fly. Such that, the web page is created locally in file system and then I am using Navigate2 function to navigate to that webpage. This works fine except on thing.

The program is unable to write the file very first time. There is no error at all. However when I run the code second time it just works as expected.

I dont understand this behavior why the same code doesn't work for very first time. Is there any security constraint.

Moreover the following lines shows the code behind my DocumentComplete Event.
All I want to do is to fire a "mouseDown" event during my browsing.
In the most of the cases this can be accomplished with the solution you described before (the rick strahl solution).
When browsing some email sites (Microsoft Outlook Web Access) this event doesn't fire. So I thought this could belong to a frame problem.

I tried to use your solution, but I probably don't understand how can I use it.

Firs I used the solution adopted in my prevoiuos post, later, after I read the basis of that solution I retried with the following code, but with no result.

You can write Mouse hooks and on mouse events you can find active element by mouse position and you can have event details as well..
if control beneath is in tool bar then you can record it otherwise
ignore it...

this is very typical way and hooks can crash your browser
so becareful..

please read article by Pavel Zolnikov
[^] on code project.
this is nice article to understand BHO..
And the code i had posted..it is inheriting class from code of Pavel Zolnikov.
He has done almost all things for us..including getSite and SetSite.
And for rest of the the classes you must refer MSDN.

And final answer where to write a code?
I had mentioned it in last answer to you...
please refer that code again..
I have written a complete class demo that is inherited from BHo (of Pavel Zolnikov).
and then Constructor, Load event of class and Document event as well.