Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# Long to C++ Long

C# Long to C++ Long

Scheduled Pinned Locked Moved C#
csharpc++question
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tristan Rhodes
    wrote on last edited by
    #1

    What do I use to represent a C++ Long in C#? I know DWORD is int, and C# Long is not the same as C++ LONG. C# uses 8 bytes, C++ uses 4. So what do I do to wrap one to the other? Thanks Cata

    U A 2 Replies Last reply
    0
    • T Tristan Rhodes

      What do I use to represent a C++ Long in C#? I know DWORD is int, and C# Long is not the same as C++ LONG. C# uses 8 bytes, C++ uses 4. So what do I do to wrap one to the other? Thanks Cata

      U Offline
      U Offline
      User 260964
      wrote on last edited by
      #2

      In Visual Basic 6, Integer equals C#'s short, so I think that this may be the case with C++ too (I don't know C++, you see). Thus, int should do the trick. - Daniël Pelsmaeker

      "To survive it is often necessary to fight, and to fight you have to dirty yourself." - George Orwell

      1 Reply Last reply
      0
      • T Tristan Rhodes

        What do I use to represent a C++ Long in C#? I know DWORD is int, and C# Long is not the same as C++ LONG. C# uses 8 bytes, C++ uses 4. So what do I do to wrap one to the other? Thanks Cata

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        C++ - C# (Win32) ---------------- int = int long = int __int64 = long DWORD = uint Regards, Alvaro


        He who laughs last, thinks slowest.

        H 1 Reply Last reply
        0
        • A Alvaro Mendez

          C++ - C# (Win32) ---------------- int = int long = int __int64 = long DWORD = uint Regards, Alvaro


          He who laughs last, thinks slowest.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Actually, be careful with uint. It's not CLS-compliant and you should try to avoid those. I have almost always used int for DWORD with absolutely no problems. Microsoft does the same throughout the BCL, too. While DWORD's can't be negative, the bit representation is still the same so even passing a negative int to a DWORD in some native function works.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          L 1 Reply Last reply
          0
          • H Heath Stewart

            Actually, be careful with uint. It's not CLS-compliant and you should try to avoid those. I have almost always used int for DWORD with absolutely no problems. Microsoft does the same throughout the BCL, too. While DWORD's can't be negative, the bit representation is still the same so even passing a negative int to a DWORD in some native function works.

            -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Heath Stewart wrote: It's not CLS-compliant and you should try to avoid those. as long as it is not publicly accessable, iow locals, private fields. one should always use the correct type though, although int will probably work 31/32 times :) leppie::AllocCPArticle("Zee blog");
            Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

            H 1 Reply Last reply
            0
            • L leppie

              Heath Stewart wrote: It's not CLS-compliant and you should try to avoid those. as long as it is not publicly accessable, iow locals, private fields. one should always use the correct type though, although int will probably work 31/32 times :) leppie::AllocCPArticle("Zee blog");
              Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

              H Offline
              H Offline
              Heath Stewart
              wrote on last edited by
              #6

              leppie wrote: although int will probably work 31/32 times Exactly! :) As I was saying, though, this usually isn't a problem. The biggest reason I typically use int is because Microsoft does in their BCL. Since they wrote the .NET Framework, seems reasonable to me. Of course, I guess worrying about CLS-compliancy is pretty moot if you're using a uint to P/Invoke a native call, huh? ;P

              -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups