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. Type conversion

Type conversion

Scheduled Pinned Locked Moved C / C++ / MFC
c++hardwareperformancehelptutorial
4 Posts 3 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.
  • C Offline
    C Offline
    CarpenterJim
    wrote on last edited by
    #1

    Hi all, am writing a program in embedded VC++... am new to programming so i need some help with a little thing.. i have a form that the user will input a hex value (memory address) and my program will copy this value to a pointer.. but it just isn't working. here is my code DWORD *pDUMMY; TCHAR sztTmp[10]; GetDlgItemText(hwndDlg, IDC_EDT_NAME,sztTmp, 10); pDUMMY=(DWORD *)(sztTmp); //this line needs some editing example: user enters 0x8fff42a2 should equal pDUMMY = (DWORD *) (0x8fff42a2) sorry for the stupid question.. i'm helpless...

    R 1 Reply Last reply
    0
    • C CarpenterJim

      Hi all, am writing a program in embedded VC++... am new to programming so i need some help with a little thing.. i have a form that the user will input a hex value (memory address) and my program will copy this value to a pointer.. but it just isn't working. here is my code DWORD *pDUMMY; TCHAR sztTmp[10]; GetDlgItemText(hwndDlg, IDC_EDT_NAME,sztTmp, 10); pDUMMY=(DWORD *)(sztTmp); //this line needs some editing example: user enters 0x8fff42a2 should equal pDUMMY = (DWORD *) (0x8fff42a2) sorry for the stupid question.. i'm helpless...

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #2

      pDUMMY = _tcstoul( sztTmp, NULL, 0 ); passing the 0 means that if the string starts with 0x then it's assumed to be hex, if it starts with 0 and not an x then it's assumed to be octal, and otherwise it's assumed to be a decimal value so it's rather flexible. you can pass 16 instead if you always assume the value is hexadecimal.

      C 1 Reply Last reply
      0
      • R Rick York

        pDUMMY = _tcstoul( sztTmp, NULL, 0 ); passing the 0 means that if the string starts with 0x then it's assumed to be hex, if it starts with 0 and not an x then it's assumed to be octal, and otherwise it's assumed to be a decimal value so it's rather flexible. you can pass 16 instead if you always assume the value is hexadecimal.

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Rick York wrote:

        pDUMMY = _tcstoul( sztTmp, NULL, 0 );

        actually you have to do

        *pDUMMY = _tcstoul( sztTmp, NULL, 0 );

        note the pointer dereference operator. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        C 1 Reply Last reply
        0
        • C CPallini

          Rick York wrote:

          pDUMMY = _tcstoul( sztTmp, NULL, 0 );

          actually you have to do

          *pDUMMY = _tcstoul( sztTmp, NULL, 0 );

          note the pointer dereference operator. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          C Offline
          C Offline
          CarpenterJim
          wrote on last edited by
          #4

          It works.... haha!... thank you guys, you saved me!!!

          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