473,387 Members | 3,033 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,387 software developers and data experts.

Code conversion

Sai
Hi I am new to .Net, I have a code in VB.Net and would like to convert that
to c#. Could any one please help me as I have tried the tool "developfusion"
web site but its of no luck.

Here is my code:

// Code in Form class
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef
lpdwFlags As Int32, _
ByVal dwReserved As Int32) As Boolean

Private Declare Function InternetDial Lib "Wininet.dll" (ByVal hwndParent As
IntPtr, _
ByVal lpszConnectoid As String, ByVal dwFlags As Int32, ByRef lpdwConnection
As Int32, _
ByVal dwReserved As Int32) As Int32

Private Declare Function InternetHangUp Lib "Wininet.dll" _
(ByVal lpdwConnection As Int32, ByVal dwReserved As Int32) As Int32

Private Enum Flags As Integer
'Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_INSTALLED = &H10
End Enum

'Declaration Used For InternetDialUp.
Private Enum DialUpOptions As Integer
INTERNET_DIAL_UNATTENDED = &H8000
INTERNET_DIAL_SHOW_OFFLINE = &H4000
INTERNET_DIAL_FORCE_PROMPT = &H2000
End Enum

Private Const ERROR_SUCCESS = &H0
Private Const ERROR_INVALID_PARAMETER = &H87
Private mlConnection As Int32
// Code in Button1 Click
Dim lngFlags As Long

If InternetGetConnectedState(lngFlags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_CONNECTION_LAN Then
'LAN connection.
MsgBox("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_MODEM Then
'Modem connection.
MsgBox("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_PROXY Then
'Proxy connection.
MsgBox("Proxy connection.")
End If
Else
'not connected.
MsgBox("Not connected.")
End If
// Code in Button2 click
Dim DResult As Int32

DResult = InternetDial(Me.Handle, "My Connection",
DialUpOptions.INTERNET_DIAL_FORCE_PROMPT, mlConnection, 0)

If (DResult = ERROR_SUCCESS) Then
MessageBox.Show("Dial Up Successful", "Dial-Up Connection")
Else
MessageBox.Show("UnSuccessFull Error Code" & DResult, "Dial-Up
Connection")
End If
//Code in button3 click
Dim Result As Int32

If Not (mlConnection = 0) Then
Result = InternetHangUp(mlConnection, 0&)
If Result = 0 Then
MessageBox.Show("Hang up successful", "Hang Up Connection")
Else
MessageBox.Show("Hang up NOT successful", "Hang Up Connection")
End If
Else
MessageBox.Show("You must dial a connection first!", "Hang Up
Connection")
End If
Thanks in advance

Sai
Apr 11 '06 #1
1 4384
The following is produced with out Instant C# VB to C# converter. Note that
since your sample is fragmented, Instant C# cannot determine that your code
is internal to a method until the "If" statement - that's why the variable
"lngFlags" is treated like a class variable. In general (with any converter)
the more fragmented the code, the worse the result. However, Instant C# does
use heuristics to try to handle these cases (unlike the on-line converters).

// Code in Form class
[System.Runtime.InteropServices.DllImport("wininet. dll",
EntryPoint="InternetGetConnectedState", ExactSpelling=true,
CharSet=System.Runtime.InteropServices.CharSet.Ans i, SetLastError=true)]
private static extern bool InternetGetConnectedState(ref Int32 lpdwFlags,
Int32 dwReserved);

[System.Runtime.InteropServices.DllImport("Wininet. dll",
EntryPoint="InternetDial", ExactSpelling=true,
CharSet=System.Runtime.InteropServices.CharSet.Ans i, SetLastError=true)]
private static extern Int32 InternetDial(IntPtr hwndParent, string
lpszConnectoid, Int32 dwFlags, ref Int32 lpdwConnection, Int32 dwReserved);

[System.Runtime.InteropServices.DllImport("Wininet. dll",
EntryPoint="InternetHangUp", ExactSpelling=true,
CharSet=System.Runtime.InteropServices.CharSet.Ans i, SetLastError=true)]
private static extern Int32 InternetHangUp(Int32 lpdwConnection, Int32
dwReserved);

private enum Flags: int
{
//Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = 0X2,
//Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = 0X1,
//Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = 0X4,
//Local system has RAS installed.
INTERNET_RAS_INSTALLED = 0X10
}

//Declaration Used For InternetDialUp.
private enum DialUpOptions: int
{
INTERNET_DIAL_UNATTENDED = 0X8000,
INTERNET_DIAL_SHOW_OFFLINE = 0X4000,
INTERNET_DIAL_FORCE_PROMPT = 0X2000
}

private const int ERROR_SUCCESS = 0X0;
private const int ERROR_INVALID_PARAMETER = 0X87;
private Int32 mlConnection;
// Code in Button1 Click
private long lngFlags;

if (InternetGetConnectedState(ref lngFlags, 0))
{
//connected.
if (lngFlags & Flags.INTERNET_CONNECTION_LAN)
{
//LAN connection.
MessageBox.Show("LAN connection.");
}
else if (lngFlags & Flags.INTERNET_CONNECTION_MODEM)
{
//Modem connection.
MessageBox.Show("Modem connection.");
}
else if (lngFlags & Flags.INTERNET_CONNECTION_PROXY)
{
//Proxy connection.
MessageBox.Show("Proxy connection.");
}
}
else
{
//not connected.
MessageBox.Show("Not connected.");
}
// Code in Button2 click
Int32 DResult = 0;

DResult = InternetDial(this.Handle, "My Connection",
DialUpOptions.INTERNET_DIAL_FORCE_PROMPT, ref mlConnection, 0);

if (DResult == ERROR_SUCCESS)
MessageBox.Show("Dial Up Successful", "Dial-Up Connection");
else
MessageBox.Show("UnSuccessFull Error Code" + DResult, "Dial-Up
Connection");
//Code in button3 click
Int32 Result = 0;

if (! (mlConnection == 0))
{
Result = InternetHangUp(mlConnection, 0);
if (Result == 0)
MessageBox.Show("Hang up successful", "Hang Up Connection");
else
MessageBox.Show("Hang up NOT successful", "Hang Up Connection");
}
else
MessageBox.Show("You must dial a connection first!", "Hang Up Connection");

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter & VB to C++ converter
Instant J#: VB to J# converter

"Sai" wrote:
Hi I am new to .Net, I have a code in VB.Net and would like to convert that
to c#. Could any one please help me as I have tried the tool "developfusion"
web site but its of no luck.

Here is my code:

// Code in Form class
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef
lpdwFlags As Int32, _
ByVal dwReserved As Int32) As Boolean

Private Declare Function InternetDial Lib "Wininet.dll" (ByVal hwndParent As
IntPtr, _
ByVal lpszConnectoid As String, ByVal dwFlags As Int32, ByRef lpdwConnection
As Int32, _
ByVal dwReserved As Int32) As Int32

Private Declare Function InternetHangUp Lib "Wininet.dll" _
(ByVal lpdwConnection As Int32, ByVal dwReserved As Int32) As Int32

Private Enum Flags As Integer
'Local system uses a LAN to connect to the Internet.
INTERNET_CONNECTION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNECTION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNECTION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_INSTALLED = &H10
End Enum

'Declaration Used For InternetDialUp.
Private Enum DialUpOptions As Integer
INTERNET_DIAL_UNATTENDED = &H8000
INTERNET_DIAL_SHOW_OFFLINE = &H4000
INTERNET_DIAL_FORCE_PROMPT = &H2000
End Enum

Private Const ERROR_SUCCESS = &H0
Private Const ERROR_INVALID_PARAMETER = &H87
Private mlConnection As Int32
// Code in Button1 Click
Dim lngFlags As Long

If InternetGetConnectedState(lngFlags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_CONNECTION_LAN Then
'LAN connection.
MsgBox("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_MODEM Then
'Modem connection.
MsgBox("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_CONNECTION_PROXY Then
'Proxy connection.
MsgBox("Proxy connection.")
End If
Else
'not connected.
MsgBox("Not connected.")
End If
// Code in Button2 click
Dim DResult As Int32

DResult = InternetDial(Me.Handle, "My Connection",
DialUpOptions.INTERNET_DIAL_FORCE_PROMPT, mlConnection, 0)

If (DResult = ERROR_SUCCESS) Then
MessageBox.Show("Dial Up Successful", "Dial-Up Connection")
Else
MessageBox.Show("UnSuccessFull Error Code" & DResult, "Dial-Up
Connection")
End If
//Code in button3 click
Dim Result As Int32

If Not (mlConnection = 0) Then
Result = InternetHangUp(mlConnection, 0&)
If Result = 0 Then
MessageBox.Show("Hang up successful", "Hang Up Connection")
Else
MessageBox.Show("Hang up NOT successful", "Hang Up Connection")
End If
Else
MessageBox.Show("You must dial a connection first!", "Hang Up
Connection")
End If
Thanks in advance

Sai

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Aakash Bordia | last post by:
Hello, Does anybody know what is the documented and known behavior of inserting/updating binary columns using host variables from a client to a server which have different code pages? Will any...
5
by: Darren Grant | last post by:
Hi there, I've attempted to implement an Angle class. An Angle is a subset of an integer, where the range is [0,360). All other operations should be permitted. The code works, I think......
13
by: Christopher Benson-Manica | last post by:
This is intended to be a simple version of the Unix "head" command, i.e. a utility that displays the first n lines of a file. Comments welcomed... #include <cstdlib> #include <iostream>...
4
by: yanyo | last post by:
hi, im trying to figure out whats the problem with this program i get a runtime error but i dont see where the problem is i tried changing declaration but nothing if somrbody can try this on their...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
2
by: Alex Sedow | last post by:
Why explicit conversion from SomeType* to IntPtr is not ambiguous (according to standart)? Example: // System.IntPtr class IntPtr { public static explicit System.IntPtr (int); public...
3
by: nan | last post by:
Hi All, I am trying to connect the Database which is installed in AS400 using DB2 Client Version 8 in Windows box. First i created the Catalog, then when i selected the connection type...
7
by: dtecmeister | last post by:
Looking to see how many people could use this kind of tool. I've got several large databases I've developed in Access with MySQL as the back-end. I've started using Linux instead of windows and...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
2
by: Netwatcher | last post by:
Hello, i am new to c++ windows and DX programming, i encountered a code in the book stated in the title, which doesn't work for a reason, here is the code // Beginning Game Programming // Chapter...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.