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 / C++ / MFC
  4. conversions in 64 bit mode

conversions in 64 bit mode

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++visual-studioquestion
5 Posts 3 Posters 21 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.
  • U Offline
    U Offline
    utcode
    wrote on last edited by
    #1

    in visual studio c++ / x64: what are way safest to convert from: 1.INT_PTR to int? 2.LRESULT to BOOL? 3.LRESULT to int?

    CPalliniC L 2 Replies Last reply
    0
    • U utcode

      in visual studio c++ / x64: what are way safest to convert from: 1.INT_PTR to int? 2.LRESULT to BOOL? 3.LRESULT to int?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      There is no 'safe way' to do those 'conversions'. On x64 the int data type is a 32-bit integer, while both INT_PTR and LRESULT are 64-bit integers (long long, see Windows Data Types (BaseTsd.h) - Win32 apps | Microsoft Learn[^]), hence such conversions would 'narrow'. Also, I believe there is no 'safe way' to convert a LRESULT to a BOOL, because the former value depends on context (see, for instance, Writing the Window Procedure - Win32 apps | Microsoft Learn[^]).

      "In testa che avete, Signor di Ceprano?" -- Rigoletto

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • U utcode

        in visual studio c++ / x64: what are way safest to convert from: 1.INT_PTR to int? 2.LRESULT to BOOL? 3.LRESULT to int?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Hi, If you want to detect overflows, underflows, truncation. The Shell team provided the [intsafe.h header](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/).

        wizQ wrote:

        1.INT_PTR to int?

        The [IntPtrToInt function](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-intptrtoint) will at least warn you if the pointer was truncated. CPallini gave great advice, there really isn't a "safe" conversion. But you can at least detect overflows and underflows.

        U 1 Reply Last reply
        0
        • L Lost User

          Hi, If you want to detect overflows, underflows, truncation. The Shell team provided the [intsafe.h header](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/).

          wizQ wrote:

          1.INT_PTR to int?

          The [IntPtrToInt function](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-intptrtoint) will at least warn you if the pointer was truncated. CPallini gave great advice, there really isn't a "safe" conversion. But you can at least detect overflows and underflows.

          U Offline
          U Offline
          utcode
          wrote on last edited by
          #4

          can one change int to LRESULT?. change from int c = ... to LRESULT c = ... also change from void func(int p,.. to void func(LRESULT p,... :java:

          L 1 Reply Last reply
          0
          • U utcode

            can one change int to LRESULT?. change from int c = ... to LRESULT c = ... also change from void func(int p,.. to void func(LRESULT p,... :java:

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            The question is, why would you want to do such a thing? The LRESULT type has a specific meaning and purpose, which is not the same as an int, or any other basic, type.

            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