VB.NET code to C# code

N

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.InterfaceIsIUnknown)> _
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
 
M

Matt

Try this:

using System.Runtime.InteropServices;
[ComVisible(true)]
[ComImport()]
[Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
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;
}
}
}
 
G

Guest

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.InterfaceIsIUnknown)]

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
 
G

Guest

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 said:
Try this:

using System.Runtime.InteropServices;
[ComVisible(true)]
[ComImport()]
[Guid("7FD52380-4E07-101B-AE2D-08002B2EC713")]
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
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;
}
}
}

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.InterfaceIsIUnknown)> _
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top