Results 1 to 12 of 12

Thread: Need help migrating c++ .net to vb 6

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Need help migrating c++ .net to vb 6

    this is the function
    public string Send (string strSendData, int num1)
    {
    string text1 = null;
    byte[] buffer1 = new byte[0xc350];
    IPAddress address1 = IPAddress.Parse(this.strIPAddress);
    IPEndPoint point1 = new IPEndPoint(address1, 0x2724);
    Socket socket1 = new Socket(2, 1, 6);
    try
    {
    int num4;
    byte[] buffer2 = Encoding.get_Default().GetBytes(strSendData);
    int num2 = buffer2.Length;
    byte[] buffer3 = BitConverter.GetBytes(num2 + 1);
    byte[] buffer4 = new byte[num2 + 5];
    socket1.Connect(point1);
    buffer4[0] = buffer3[3];
    buffer4[1] = buffer3[2];
    buffer4[2] = buffer3[1];
    buffer4[3] = buffer3[0];
    buffer4[4] = (byte) num1;
    for (int num3 = 5;num3 < (num2 + 5); num3++)
    {
    buffer4[num3] = buffer2[num3 - 5];
    }
    socket1.Send(buffer4);
    goto Label_00B2;
    Label_00B2:
    num4 = socket1.Receive(buffer1);
    int num5 = (((((buffer1[0] << 0x18) | buffer1[1]) << 0x10) | buffer1[2]) << 8) | (buffer1[3] + 4);
    if (num5 != num4)
    {
    goto Label_00B2;
    }
    text1 = Encoding.get_Default().GetString(buffer1, 5, num4);
    }
    catch (Exception)
    {
    text1 = "Error";
    }
    finally
    {
    socket1.Shutdown(2);
    socket1.Close();

    }
    return text1;

    i dun have much experience in c++ .net , can anyone translate this to vb equivalent or at least english ?
    Thx a lot

  2. #2
    Frenzied Member vbNeo's Avatar
    Join Date
    May 2002
    Location
    Jutland, Denmark
    Posts
    1,994

    Re: Need help migrating c++ .net to vb 6

    Looks pretty messy with all the spaghetti goto's. What exactly are you trying to achieve? I think it'd be easier to just write something new in VB.Net than trying to convert that.
    "Lies, sanctions, and cruise missiles have never created a free and just society. Only everyday people can do that."
    - Zack de la Rocha


    Hear me roar.

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: Need help migrating c++ .net to vb 6

    (via Instant VB):
    (by the way, the original code was C#, not C++)

    Code:
    Public Function Send(ByVal strSendData As String, ByVal num1 As Integer) As String
    	Dim text1 As String = Nothing
    	Dim buffer1 As Byte() = New Byte(&Hc350 - 1){}
    	Dim address1 As IPAddress = IPAddress.Parse(Me.strIPAddress)
    	Dim point1 As IPEndPoint = New IPEndPoint(address1, &H2724)
    	Dim socket1 As Socket = New Socket(2, 1, 6)
    	Try
    		Dim num4 As Integer
    		Dim buffer2 As Byte() = Encoding.get_Default().GetBytes(strSendData)
    		Dim num2 As Integer = buffer2.Length
    		Dim buffer3 As Byte() = BitConverter.GetBytes(num2 + 1)
    		Dim buffer4 As Byte() = New Byte(num2 + 5 - 1){}
    		socket1.Connect(point1)
    		buffer4(0) = buffer3(3)
    		buffer4(1) = buffer3(2)
    		buffer4(2) = buffer3(1)
    		buffer4(3) = buffer3(0)
    		buffer4(4) = CByte(num1)
    		For num3 As Integer = 5 To (num2 + 5) - 1
    			buffer4(num3) = buffer2(num3 - 5)
    		Next num3
    		socket1.Send(buffer4)
    		GoTo Label_00B2
    Label_00B2:
    		num4 = socket1.Receive(buffer1)
    		Dim num5 As Integer = (((((buffer1(0) << &H18) Or buffer1(1)) << &H10) Or buffer1(2)) << 8) Or (buffer1(3) + 4)
    		If num5 <> num4 Then
    			GoTo Label_00B2
    		End If
    		text1 = Encoding.get_Default().GetString(buffer1, 5, num4)
    	Catch e1 As Exception
    		text1 = "Error"
    	Finally
    		socket1.Shutdown(2)
    		socket1.Close()
    	End Try
    	Return text1
    End Function
    Last edited by David Anton; Apr 15th, 2007 at 08:43 AM. Reason: added a note
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Re: Need help migrating c++ .net to vb 6

    thats vb.net ? hmm i am not familar wif that too . only vb6 , but i will try to understand it
    dun have such function in vb 6 lol
    Encoding.get_Default().GetBytes(strSendData)
    Last edited by quantumfusion; Apr 15th, 2007 at 09:33 AM.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help migrating c++ .net to vb 6

    If you aren't familiar with C# or VB.NET then trying to convert from one to the other is a bit of a waste of time. It's usually a better idea to work in terms of functionality than actual code, because we can all understand what we want our code to achieve, even if we don't know how to achieve it. What do YOU want YOUR code to achieve? Ask yourself that and then look for the best way to implement that in your language of choice.

    Were you hoping to be able to plug the resulting VB.NET code into a VB6 app? That's a complete pipe-dream I'm afraid.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Re: Need help migrating c++ .net to vb 6

    btw can anyone tell me
    Encoding.get_Default().GetBytes(strSendData)
    what does that do ? get num of bytes ?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help migrating c++ .net to vb 6

    It doesn't get the number of bytes. It gets the bytes, as the name GetBytes would suggest. It gets the array of bytes that represent that string in the default encoding.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Re: Need help migrating c++ .net to vb 6

    i see thats some great help over here
    how bout this ?
    BitConverter.GetBytes(num2 + 1)
    i cant seem to call bitconverter function in vb.net lol

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help migrating c++ .net to vb 6

    BitConverter is not a function. It's a class. Type bitconverter into the search box in the MSDN library and you can find out all about it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Need help migrating c++ .net to vb 6

    Encoding.get_Default() is usually written as Encoding.Default. The get_ and set_ prefixed functions are created by the compiler.

  11. #11

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Posts
    10

    Re: Need help migrating c++ .net to vb 6

    checked out msdn

    GetBytes Overloaded. Converts the specified data to an array of bytes.

    hmm what do they mean by overload ?
    and whats the difference wif Encoding.get_Default().GetBytes(strSendData)
    since they both convert to bytearray lol

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Need help migrating c++ .net to vb 6

    There's no rule that says there can't be two ways to do the same thing. There are plenty of things that can be done in more than two ways. Having said that, the BitConverter class converts all sorts of things to and from Byte arrays while the Encoding class only converts strings in specific encodings.

    If you want to know what anything means the first thing you should is search for it on MSDN. If you can't find what you need or you don't understand what you find then you need help, but MSDN can tell you what overloading is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width