|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
problem in converting to C#DownloadManager of the Internet explorer. Te class ServiceProvider have the function query service is returning some pointer in vb.net. We have commented that total code and there we displayed our own form to download the file. But when it is converted into C# the function QueryService is not returning a pointer if it returns the pointer the default IE download Manager Dialog Box is appearing. How can i solve this problem. It has to work same like in vb.net after converting it into C#. Any solutions. To run this vb application have to import the COM.dll i am also attatching the dll file. to run this vb code have to add web browser and rename that web browser name as Browser. Thanks in advance. Imports System.Runtime.InteropServices Public Delegate Sub delegate1(ByVal s As System.Object, ByVal e As System.EventArgs) Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Browser As AxSHDocVw.AxWebBrowser Friend WithEvents Splitter1 As System.Windows.Forms.Splitter Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Browser = New AxSHDocVw.AxWebBrowser Me.Splitter1 = New System.Windows.Forms.Splitter Me.Button1 = New System.Windows.Forms.Button Me.Label1 = New System.Windows.Forms.Label Me.TextBox1 = New System.Windows.Forms.TextBox Me.StatusBar1 = New System.Windows.Forms.StatusBar CType(Me.Browser, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Browser ' Me.Browser.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.Browser.Enabled = True Me.Browser.Location = New System.Drawing.Point(8, 32) Me.Browser.OcxState = CType(resources.GetObject("Browser.OcxState"), System.Windows.Forms.AxHost.State) Me.Browser.Size = New System.Drawing.Size(776, 528) Me.Browser.TabIndex = 0 ' 'Splitter1 ' Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Top Me.Splitter1.Location = New System.Drawing.Point(0, 0) Me.Splitter1.Name = "Splitter1" Me.Splitter1.Size = New System.Drawing.Size(792, 24) Me.Splitter1.TabIndex = 1 Me.Splitter1.TabStop = False ' 'Button1 ' Me.Button1.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.Button1.Location = New System.Drawing.Point(752, 0) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(40, 23) Me.Button1.TabIndex = 2 Me.Button1.Text = "Go" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(0, 3) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(64, 16) Me.Label1.TabIndex = 3 Me.Label1.Text = "Entrer URL" ' 'TextBox1 ' Me.TextBox1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles) Me.TextBox1.Location = New System.Drawing.Point(64, 0) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(680, 20) Me.TextBox1.TabIndex = 4 Me.TextBox1.Text = "http://my.mindvision.com/~ben/tools/" ' 'StatusBar1 ' Me.StatusBar1.Location = New System.Drawing.Point(0, 544) Me.StatusBar1.Name = "StatusBar1" Me.StatusBar1.Size = New System.Drawing.Size(792, 22) Me.StatusBar1.TabIndex = 5 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(792, 566) Me.Controls.Add(Me.StatusBar1) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.Splitter1) Me.Controls.Add(Me.Browser) Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "Form1" CType(Me.Browser, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Public Event e As delegate1 Public myReq As HttpWebRequest Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private m_DownloadManagerCookie As System.Int32 Private Sub SetDownloadManager() Dim ips As COMVB.IProfferService Dim objBrowser As Object Dim ispBrowser As COMVB.UCOMIServiceProvider Dim ip As IntPtr Try ' Get a handle to the browser ocx objBrowser = Browser.GetOcx() ispBrowser = DirectCast(objBrowser, COMVB.UCOMIServiceProvider) ' Query the browser for the IProfferService interface ip = ispBrowser.QueryService(COMVB.SID_SProfferService, COMVB.IID_IProfferService) ips = DirectCast(Marshal.GetObjectForIUnknown(ip), COMVB.IProfferService) ' Proffer the new object as the provider of the IHTMLEditHostinterface handler ips.ProfferService(COMVB.IID_IDownloadManager, New ServiceProvider, m_DownloadManagerCookie) Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim url As System.Object = TextBox1.Text Dim o As System.Object = Nothing Dim myReq As HttpWebRequest = WebRequest.Create(url) Browser.Navigate2(url, o, o, o, o) SetDownloadManager() End Sub Private Sub Browser_BeforeNavigate2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles Browser.BeforeNavigate2 'MsgBox(e.uRL & " ") RemoteUrl = e.uRL 'Dim x As New AxSHDocVw.AxWebBrowser End Sub Private Sub Browser_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles Browser.NavigateComplete2 End Sub Public Sub Browser_DownloadBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles Browser.DownloadBegin 'MsgBox(RemoteUrl.ToString()) End Sub Private Sub Browser_DownloadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Browser.DownloadComplete End Sub End Class Class ServiceProvider Implements COMVB.UCOMIServiceProvider Public Function QueryService(ByRef guidService As System.Guid, ByRef riid As System.Guid) As IntPtr Implements COMVB.UCOMIServiceProvider.QueryService Dim f As New DownloadTestHarnessForm f.Show() 'Dim ()arr As String = riid.GetType().GetFields 'MsgBox(riid) 'If guidService.Equals(COMVB.IID_IDownloadManager) Then ' 'MessageBox.Show("Now only the IDownloadManager Called") ' If riid.Equals(COMVB.IID_IDownloadManager) Then ' Dim idm As COM.Interfaces.IDownloadManager ' idm = New DownloadManager ' Return GetInterface(idm, COMVB.IID_IDownloadManager) ' Else ' Return Nothing ' End If 'Else ' Return Nothing 'End If End Function Public Function GetInterface(ByVal obj As Object, ByRef iid As Guid) As IntPtr Dim pUnk As IntPtr Dim pInterface As IntPtr Dim hr As Integer pUnk = Marshal.GetIUnknownForObject(obj) hr = Marshal.QueryInterface(pUnk, iid, pInterface) If hr < 0 Then Marshal.ThrowExceptionForHR(hr) End If Marshal.Release(pUnk) Return pInterface End Function End Class Class DownloadManager Implements COM.Interfaces.IDownloadManager Public Function Download(ByVal pmk As System.Runtime.InteropServices.UCOMIMoniker, ByVal pbc As System.Runtime.InteropServices.UCOMIBindCtx, ByVal dwBindVerb As System.UInt32, ByVal grfBINDF As Integer, ByVal pBindInfo As System.IntPtr, ByVal pszHeaders As String, ByVal pszRedir As String, ByVal uiCP As System.UInt32) As Integer Implements COM.Interfaces.IDownloadManager.Download Return New System.Int32 End Function End Class Class COMVB ' IServiceProvider interface <ComVisible(True), ComImport(), Guid("6d5140c1-7436-11ce-8034-00aa006009fa"), _ InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ Public Interface UCOMIServiceProvider Function QueryService(ByRef guidService As Guid, ByRef riid As Guid) As IntPtr End Interface ' IProfferService interface <ComVisible(True), ComImport(), Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0"), _ InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _ Public Interface IProfferService Sub ProfferService(ByRef guidService As Guid, ByVal psp As UCOMIServiceProvider, ByRef cookie As Integer) Sub RevokeService(ByVal cookie As Integer) End Interface Public Shared SID_SProfferService As New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0") Public Shared IID_IProfferService As New Guid("cb728b20-f786-11ce-92ad-00aa00a74cd0") Public Shared SID_SHTMLEditHost As New Guid("3050f6a0-98b5-11cf-bb82-00aa00bdce0b") Public Shared IID_IDownloadManager As New Guid("988934A4-064B-11D3-BB80-00104B35E7F9") End Class [attached file: COM.dll] "kamal" <kamal***@nannacomputers.com> schrieb: Converting code between .NET programming languages> This is the code i have. By usin this code we can overload the > DownloadManager of the Internet explorer. Te class ServiceProvider have > the function query service is returning some pointer in vb.net. We have > commented that total code and there we displayed our own form to download > the file. > > But when it is converted into C# the function QueryService is not > returning a pointer if it returns the pointer the default IE download > Manager Dialog Box is appearing. How can i solve this problem. It has to > work same like in vb.net after converting it into C#. Any solutions. <URL:http://dotnet.mvps.org/dotnet/faqs/?id=languageconverters&lang=en> Personally I recommend the converters of Tangible Software Solutions Inc. because the results of the conversion are of good quality. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> |
|||||||||||||||||||||||