473,788 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "developfus ion"
web site but its of no luck.

Here is my code:

// Code in Form class
Private Declare Function InternetGetConn ectedState Lib "wininet.dl l" (ByRef
lpdwFlags As Int32, _
ByVal dwReserved As Int32) As Boolean

Private Declare Function InternetDial Lib "Wininet.dl l" (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.dl l" _
(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_CONNEC TION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNEC TION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNEC TION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_IN STALLED = &H10
End Enum

'Declaration Used For InternetDialUp.
Private Enum DialUpOptions As Integer
INTERNET_DIAL_U NATTENDED = &H8000
INTERNET_DIAL_S HOW_OFFLINE = &H4000
INTERNET_DIAL_F ORCE_PROMPT = &H2000
End Enum

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

If InternetGetConn ectedState(lngF lags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_ CONNECTION_LAN Then
'LAN connection.
MsgBox("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_ CONNECTION_MODE M Then
'Modem connection.
MsgBox("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_ CONNECTION_PROX Y 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.I NTERNET_DIAL_FO RCE_PROMPT, mlConnection, 0)

If (DResult = ERROR_SUCCESS) Then
MessageBox.Show ("Dial Up Successful", "Dial-Up Connection")
Else
MessageBox.Show ("UnSuccessF ull 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 4404
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("win inet.dll",
EntryPoint="Int ernetGetConnect edState", ExactSpelling=t rue,
CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
private static extern bool InternetGetConn ectedState(ref Int32 lpdwFlags,
Int32 dwReserved);

[System.Runtime. InteropServices .DllImport("Win inet.dll",
EntryPoint="Int ernetDial", ExactSpelling=t rue,
CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
private static extern Int32 InternetDial(In tPtr hwndParent, string
lpszConnectoid, Int32 dwFlags, ref Int32 lpdwConnection, Int32 dwReserved);

[System.Runtime. InteropServices .DllImport("Win inet.dll",
EntryPoint="Int ernetHangUp", ExactSpelling=t rue,
CharSet=System. Runtime.Interop Services.CharSe t.Ansi, SetLastError=tr ue)]
private static extern Int32 InternetHangUp( Int32 lpdwConnection, Int32
dwReserved);

private enum Flags: int
{
//Local system uses a LAN to connect to the Internet.
INTERNET_CONNEC TION_LAN = 0X2,
//Local system uses a modem to connect to the Internet.
INTERNET_CONNEC TION_MODEM = 0X1,
//Local system uses a proxy server to connect to the Internet.
INTERNET_CONNEC TION_PROXY = 0X4,
//Local system has RAS installed.
INTERNET_RAS_IN STALLED = 0X10
}

//Declaration Used For InternetDialUp.
private enum DialUpOptions: int
{
INTERNET_DIAL_U NATTENDED = 0X8000,
INTERNET_DIAL_S HOW_OFFLINE = 0X4000,
INTERNET_DIAL_F ORCE_PROMPT = 0X2000
}

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

if (InternetGetCon nectedState(ref lngFlags, 0))
{
//connected.
if (lngFlags & Flags.INTERNET_ CONNECTION_LAN)
{
//LAN connection.
MessageBox.Show ("LAN connection.");
}
else if (lngFlags & Flags.INTERNET_ CONNECTION_MODE M)
{
//Modem connection.
MessageBox.Show ("Modem connection.");
}
else if (lngFlags & Flags.INTERNET_ CONNECTION_PROX Y)
{
//Proxy connection.
MessageBox.Show ("Proxy connection.");
}
}
else
{
//not connected.
MessageBox.Show ("Not connected.");
}
// Code in Button2 click
Int32 DResult = 0;

DResult = InternetDial(th is.Handle, "My Connection",
DialUpOptions.I NTERNET_DIAL_FO RCE_PROMPT, ref mlConnection, 0);

if (DResult == ERROR_SUCCESS)
MessageBox.Show ("Dial Up Successful", "Dial-Up Connection");
else
MessageBox.Show ("UnSuccessF ull 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 "developfus ion"
web site but its of no luck.

Here is my code:

// Code in Form class
Private Declare Function InternetGetConn ectedState Lib "wininet.dl l" (ByRef
lpdwFlags As Int32, _
ByVal dwReserved As Int32) As Boolean

Private Declare Function InternetDial Lib "Wininet.dl l" (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.dl l" _
(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_CONNEC TION_LAN = &H2
'Local system uses a modem to connect to the Internet.
INTERNET_CONNEC TION_MODEM = &H1
'Local system uses a proxy server to connect to the Internet.
INTERNET_CONNEC TION_PROXY = &H4
'Local system has RAS installed.
INTERNET_RAS_IN STALLED = &H10
End Enum

'Declaration Used For InternetDialUp.
Private Enum DialUpOptions As Integer
INTERNET_DIAL_U NATTENDED = &H8000
INTERNET_DIAL_S HOW_OFFLINE = &H4000
INTERNET_DIAL_F ORCE_PROMPT = &H2000
End Enum

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

If InternetGetConn ectedState(lngF lags, 0) Then
'connected.
If lngFlags And Flags.INTERNET_ CONNECTION_LAN Then
'LAN connection.
MsgBox("LAN connection.")
ElseIf lngFlags And Flags.INTERNET_ CONNECTION_MODE M Then
'Modem connection.
MsgBox("Modem connection.")
ElseIf lngFlags And Flags.INTERNET_ CONNECTION_PROX Y 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.I NTERNET_DIAL_FO RCE_PROMPT, mlConnection, 0)

If (DResult = ERROR_SUCCESS) Then
MessageBox.Show ("Dial Up Successful", "Dial-Up Connection")
Else
MessageBox.Show ("UnSuccessF ull 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
2388
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 code page / character set conversion take place? I am particulary interested in insert/update from subqueries. eg: insert into t1(binarycol) select :HV1 from t2 versus
5
3131
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... except (for example) a = b + 10; needs to be a = b + (Angle) 10; Could some kind soul comment on my code and show me how it could be
13
1421
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> #include <fstream> #include <sstream> #include <string>
4
2048
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 compiler to make sure is not a compiler compatibility problem. #include<stdio.h> #include<math.h> char menu_action(void);
11
7623
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 Test. I expected the same error from the following line, but it compiles fine. The double is silently truncated to an int and then fed in to the implicit conversion operator. Why does this happen? Is there any way that I can keep the implicit...
2
6870
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 static explicit System.IntPtr (long);
3
12016
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 as ODBC, then i am getting
7
3278
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 the only thing I can't migrate is my Access databases. I'm looking to export them in a standard file format, then provide convert functionality into SWT, Flash, HTML, Native and/or some other formats.
6
3344
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 I discovered first a workaround, then the real cause of the problem. I would like to understand why what I am doing is frowned upon by Visual Studio and how to do this properly. My application is in one solution; supporting libraries including...
2
4625
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 5 #edit: not 4, mistake in the title // d3d_windowed program //header files to include #include <d3d9.h> #include <time.h>
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.