CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: memcpy

  1. #1
    Join Date
    May 2007
    Posts
    2

    Cool memcpy

    Hello,

    I have a problem in porting a few code lines from C++ to C#.

    in C++:
    std::vector<char> vctNtwrkS;
    vctNtwrkS.resize(4);
    int nCounterS = 224;
    nCounterS = htonl(nCounterS);
    memcpy (&vctNtwrkS[0], &nCounterS, 4);

    In C#:
    int nSequence = 224;
    nSequence = System.Net.IPAddress.HostToNetworkOrder(nSequence);
    byte[] mb = new byte[4];
    THIS IS THE MISSING PIECE: I need to do the memcpy. I know there isn't memcpy in C# and I looked for example on web and couldn't find this.
    In addition: in C# char type is a unicode so inorder to do the same I need to transfer char to byte, right ?

    Thanks, Yariv

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: memcpy

    See the BitConverter class.
    Code:
    byte [] mb = BitConverter.GetBytes(nSequence);
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    May 2007
    Posts
    2

    Re: memcpy

    Thanks

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

Featured