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
6 Posts 4 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.
  • U Offline
    U Offline
    User 2070738
    wrote on last edited by
    #1

    Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.

    T C J 3 Replies Last reply
    0
    • U User 2070738

      Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      titi@yahoo.com wrote: OCTETSTR(octant string) How many Byte One character take in OCTETSTR?

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV

      1 Reply Last reply
      0
      • U User 2070738

        Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        What on earth is an OCTETSTR ? It's obviously a different format entirely, and so needs some sort of conversion class. Christian Graus - Microsoft MVP - C++

        1 Reply Last reply
        0
        • U User 2070738

          Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.

          J Offline
          J Offline
          Jose Lamas Rios
          wrote on last edited by
          #4

          HexEncoder doesn't provide a direct conversion to char* or CString. It only offers the possibility to output its content to an std::ostream. You could use an stringstream for that and then extract the string from it. On the other hand, OCTETSTR is just a typedef for std::vector<unsigned char>, so you could iterate through each element and convert it to hexadecimal notation using sprintf like this:

          // [UPDATE]
          // void OctetStrToHexString(OCTETSTR str, CString& sResult)
          void OctetStrToHexString(const OCTETSTR& v, CString& sResult)
          {
            // [update] some minor errors corrected
            LPTSTR p = sResult.GetBuffer(v.size()*2);
            for (OCTETSTR::size_type i = 0; i < v.size(); i++)
            p += _stprintf(p, _T("%02X"), (int)v[i]);
            *p = _T('\0');
            sResult.ReleaseBuffer(v.size()*2);
          }

          Then your code could be written as follows:

          OCTETSTR str;
            CString sBuffer;
            OctetStrToHexString(str, sBuffer);
            poEdit->SetWindowText(sBuffer);

          Note I haven't actually compiled nor tested the code shown above, so it may contain errors. -- jlr http://jlamas.blogspot.com/[^]

          U 1 Reply Last reply
          0
          • J Jose Lamas Rios

            HexEncoder doesn't provide a direct conversion to char* or CString. It only offers the possibility to output its content to an std::ostream. You could use an stringstream for that and then extract the string from it. On the other hand, OCTETSTR is just a typedef for std::vector<unsigned char>, so you could iterate through each element and convert it to hexadecimal notation using sprintf like this:

            // [UPDATE]
            // void OctetStrToHexString(OCTETSTR str, CString& sResult)
            void OctetStrToHexString(const OCTETSTR& v, CString& sResult)
            {
              // [update] some minor errors corrected
              LPTSTR p = sResult.GetBuffer(v.size()*2);
              for (OCTETSTR::size_type i = 0; i < v.size(); i++)
              p += _stprintf(p, _T("%02X"), (int)v[i]);
              *p = _T('\0');
              sResult.ReleaseBuffer(v.size()*2);
            }

            Then your code could be written as follows:

            OCTETSTR str;
              CString sBuffer;
              OctetStrToHexString(str, sBuffer);
              poEdit->SetWindowText(sBuffer);

            Note I haven't actually compiled nor tested the code shown above, so it may contain errors. -- jlr http://jlamas.blogspot.com/[^]

            U Offline
            U Offline
            User 2070738
            wrote on last edited by
            #5

            Ive used this code but the compiler gives v as undeclared identifier.whas v?? Thanx for ur help

            J 1 Reply Last reply
            0
            • U User 2070738

              Ive used this code but the compiler gives v as undeclared identifier.whas v?? Thanx for ur help

              J Offline
              J Offline
              Jose Lamas Rios
              wrote on last edited by
              #6

              Oops! v was meant to be the OCTETSTR parm, sorry. Change the function header to this:

              void OctetStrToHexString(OCTETSTR v, CString& sResult)

              -- jlr http://jlamas.blogspot.com/[^]

              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