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. String Conversion

String Conversion

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
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.
  • F Offline
    F Offline
    Frank Deo
    wrote on last edited by
    #1

    I am converting a dos app to a windows app. The application changes passwords for given a given user. The dos application accepts servername, username, and password as cmd line arg's. They are defined as char username[50], password[128], etc. My dialog takes the username and password as CString's. How can I convert the CString to make it compatible with the char [50], etc above? Thanks! "Keyboard Error - Press F1 to Continue"

    D 1 Reply Last reply
    0
    • F Frank Deo

      I am converting a dos app to a windows app. The application changes passwords for given a given user. The dos application accepts servername, username, and password as cmd line arg's. They are defined as char username[50], password[128], etc. My dialog takes the username and password as CString's. How can I convert the CString to make it compatible with the char [50], etc above? Thanks! "Keyboard Error - Press F1 to Continue"

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      To make a CString from char[]:

      char username[50];
      // Fill username

      CString str;
      str = username;

      To make a char[] from CString:

      CString str;
      // Fill str

      char username[50];
      memset(username, 0, 50);
      strncpy(username, str.LockBuffer(), 50-1);
      str.UnlockBuffer();

      Hope that helps :-D Dominik


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

      D 1 Reply Last reply
      0
      • D Dominik Reichl

        To make a CString from char[]:

        char username[50];
        // Fill username

        CString str;
        str = username;

        To make a char[] from CString:

        CString str;
        // Fill str

        char username[50];
        memset(username, 0, 50);
        strncpy(username, str.LockBuffer(), 50-1);
        str.UnlockBuffer();

        Hope that helps :-D Dominik


        _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        The calls to LockBuffer() and UnlockBuffer() are not necessary as the second parameter to strncpy() is expecting a LPCSTR, which CString provides. The same is true for GetBuffer() and ReleaseBuffer().

        F 1 Reply Last reply
        0
        • D David Crow

          The calls to LockBuffer() and UnlockBuffer() are not necessary as the second parameter to strncpy() is expecting a LPCSTR, which CString provides. The same is true for GetBuffer() and ReleaseBuffer().

          F Offline
          F Offline
          Frank Deo
          wrote on last edited by
          #4

          Thanks! That worked great. Frank "Keyboard Error - Press F1 to Continue"

          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