473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

VB.NET code to C# code

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
4 5031
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
4
by: jason | last post by:
Hello. Newbie on SQL and suffering through this. I have two tables created as such: drop table table1; go drop table table2; go
16
by: Dario de Judicibus | last post by:
I'm getting crazy. Look at this code: #include <string.h> #include <stdio.h> #include <iostream.h> using namespace std ; char ini_code = {0xFF, 0xFE} ; char line_sep = {0x20, 0x28} ;
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.