By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,776 Members | 1,238 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,776 IT Pros & Developers. It's quick & easy.

VB.NET code to C# code

P: n/a
NG
Hi All
Can anyone pls help me convert the following VB.NET code to C#.
This uses MSHTML and an Interface definition.
Thanks
NG

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface

Imports System.Windows.Forms

Public Class dom_lib
Public Function Fun() As String
Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty)

Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop

Fun = objDocument.body.outerHTML

End Function

End Class


Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
Try this:

using System.Runtime.InteropServices;
[ComVisible(true)]
[ComImport()]
[Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)]
public interface IPersistStreamInit {

// IPersist interface
void GetClassID(ref Guid pClassID);

public class dom_lib {

public string Fun() {
mshtml.HTMLDocument objMSHTML;
mshtml.IHTMLDocument2 objDocument;
IPersistStreamInit ips;
objMSHTML = new mshtml.HTMLDocument();
objMSHTML;
IPersistStreamInit;
ips.InitNew();
objDocument = objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty);
for (
; (objDocument.readyState == "complete");
) {
Application.DoEvents();
}
return objDocument.body.outerHTML;
}
}
}
NG wrote:
Hi All
Can anyone pls help me convert the following VB.NET code to C#.
This uses MSHTML and an Interface definition.
Thanks
NG

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.Interface IsIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface

Imports System.Windows.Forms

Public Class dom_lib
Public Function Fun() As String
Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty)

Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop

Fun = objDocument.body.outerHTML

End Function

End Class


Nov 21 '05 #2

P: n/a
This website may be helpful:

http://www.carlosag.net/Tools/CodeTr...r/Default.aspx

The only thing is, if you copy and paste, you have to press enter at the
end to make it translate.
NG wrote:
Hi All
Can anyone pls help me convert the following VB.NET code to C#.
This uses MSHTML and an Interface definition.
Thanks
NG

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.Interface IsIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface

Imports System.Windows.Forms

Public Class dom_lib
Public Function Fun() As String
Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty)

Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop

Fun = objDocument.body.outerHTML

End Function

End Class


Nov 21 '05 #3

P: n/a
Here is the C# version (via our Instant C# Demo Edition -
www.instantcsharp.com)

using System.Runtime.InteropServices;

[ComVisible(true), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)]

public interface IPersistStreamInit
{
// IPersist interface
void GetClassID(ref Guid pClassID);

[PreserveSig()]
int IsDirty();
[PreserveSig()]
int Load(UCOMIStream pstm);
[PreserveSig()]
int Save(UCOMIStream pstm, bool fClearDirty);
[PreserveSig()]
int GetSizeMax([InAttribute(), Out(), MarshalAs(UnmanagedType.U8)]
ref long pcbSize);
[PreserveSig()]
int InitNew();

}
using System.Windows.Forms;

public class dom_lib
{
public string Fun()
{

mshtml.HTMLDocument objMSHTML = null;
mshtml.IHTMLDocument2 objDocument = null;
IPersistStreamInit ips = null;

objMSHTML = new mshtml.HTMLDocument();

ips = (IPersistStreamInit)objMSHTML;
ips.InitNew();

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", string.Empty);

while ( ! (objDocument.readyState == "complete"))
{
Application.DoEvents();
}

return objDocument.body.outerHTML;

}

}

--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"NG" wrote:
Hi All
Can anyone pls help me convert the following VB.NET code to C#.
This uses MSHTML and an Interface definition.
Thanks
NG

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface

Imports System.Windows.Forms

Public Class dom_lib
Public Function Fun() As String
Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty)

Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop

Fun = objDocument.body.outerHTML

End Function

End Class


Nov 21 '05 #4

P: n/a
See the translation via Instant C# in my other reply.
Not sure you've noticed, but the code produced by the online converter you
used is not C# code.
--
David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
"Matt" wrote:
Try this:

using System.Runtime.InteropServices;
[ComVisible(true)]
[ComImport()]
[Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIUnknown)]
public interface IPersistStreamInit {

// IPersist interface
void GetClassID(ref Guid pClassID);

public class dom_lib {

public string Fun() {
mshtml.HTMLDocument objMSHTML;
mshtml.IHTMLDocument2 objDocument;
IPersistStreamInit ips;
objMSHTML = new mshtml.HTMLDocument();
objMSHTML;
IPersistStreamInit;
ips.InitNew();
objDocument = objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty);
for (
; (objDocument.readyState == "complete");
) {
Application.DoEvents();
}
return objDocument.body.outerHTML;
}
}
}
NG wrote:
Hi All
Can anyone pls help me convert the following VB.NET code to C#.
This uses MSHTML and an Interface definition.
Thanks
NG

Option Explicit On
Option Strict On

Imports System.Runtime.InteropServices

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.Interface IsIUnknown)> _
Public Interface IPersistStreamInit
' IPersist interface
Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As Integer
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream, ByVal
ByValfClearDirty As Boolean) As Integer
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As Integer
<PreserveSig()> Function InitNew() As Integer

End Interface

Imports System.Windows.Forms

Public Class dom_lib
Public Function Fun() As String
Dim objMSHTML As mshtml.HTMLDocument
Dim objDocument As mshtml.IHTMLDocument2
Dim ips As IPersistStreamInit

objMSHTML = New mshtml.HTMLDocument

ips = DirectCast(objMSHTML, IPersistStreamInit)
ips.InitNew()

objDocument =
objMSHTML.createDocumentFromUrl("http://microsoft.com/", String.Empty)

Do Until objDocument.readyState = "complete"
Application.DoEvents()
Loop

Fun = objDocument.body.outerHTML

End Function

End Class


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.