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. convert System::String to char *

convert System::String to char *

Scheduled Pinned Locked Moved C / C++ / MFC
helpalgorithmsquestion
5 Posts 4 Posters 1 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.
  • B Offline
    B Offline
    bubuzzz
    wrote on last edited by
    #1

    hi all, I am trying to convert from System::String to char *. After searching some forums and the msdn, i got these lines of code const char * convertStrToChar(System::String ^ str) { CString tmpStr (str); char* ConvToChar = new char[tmpStr.GetLength() + 2]; size_t Converted = 0; wcstombs_s(&Converted, ConvToChar, tmpStr.GetLength()+1, tmpStr, _TRUNCATE); return ConvToChar; } However, when i compilie it, these error messages appear : Error 1 error LNK2028: unresolved token (0A00023F) "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj Error 2 error LNK2019: unresolved external symbol "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj I know this is a simple problem, but i cannot figure out why this bug happens. Can you give me some suggestion? Thanks

    S T S B 4 Replies Last reply
    0
    • B bubuzzz

      hi all, I am trying to convert from System::String to char *. After searching some forums and the msdn, i got these lines of code const char * convertStrToChar(System::String ^ str) { CString tmpStr (str); char* ConvToChar = new char[tmpStr.GetLength() + 2]; size_t Converted = 0; wcstombs_s(&Converted, ConvToChar, tmpStr.GetLength()+1, tmpStr, _TRUNCATE); return ConvToChar; } However, when i compilie it, these error messages appear : Error 1 error LNK2028: unresolved token (0A00023F) "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj Error 2 error LNK2019: unresolved external symbol "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj I know this is a simple problem, but i cannot figure out why this bug happens. Can you give me some suggestion? Thanks

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      It looks to me (from the linker error) like the function signature you declared was:

      char * convertStrToChar(System::String ^)

      but you've actually implemented this function signature:

      const char * convertStrToChar(System::String ^)

      1 Reply Last reply
      0
      • B bubuzzz

        hi all, I am trying to convert from System::String to char *. After searching some forums and the msdn, i got these lines of code const char * convertStrToChar(System::String ^ str) { CString tmpStr (str); char* ConvToChar = new char[tmpStr.GetLength() + 2]; size_t Converted = 0; wcstombs_s(&Converted, ConvToChar, tmpStr.GetLength()+1, tmpStr, _TRUNCATE); return ConvToChar; } However, when i compilie it, these error messages appear : Error 1 error LNK2028: unresolved token (0A00023F) "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj Error 2 error LNK2019: unresolved external symbol "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj I know this is a simple problem, but i cannot figure out why this bug happens. Can you give me some suggestion? Thanks

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        this is not C++, it is C++/CLI. so it belongs to the Managed C++ forum

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        1 Reply Last reply
        0
        • B bubuzzz

          hi all, I am trying to convert from System::String to char *. After searching some forums and the msdn, i got these lines of code const char * convertStrToChar(System::String ^ str) { CString tmpStr (str); char* ConvToChar = new char[tmpStr.GetLength() + 2]; size_t Converted = 0; wcstombs_s(&Converted, ConvToChar, tmpStr.GetLength()+1, tmpStr, _TRUNCATE); return ConvToChar; } However, when i compilie it, these error messages appear : Error 1 error LNK2028: unresolved token (0A00023F) "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj Error 2 error LNK2019: unresolved external symbol "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj I know this is a simple problem, but i cannot figure out why this bug happens. Can you give me some suggestion? Thanks

          S Offline
          S Offline
          Sarath C
          wrote on last edited by
          #4

          See Nishanth Sivakumar's excellent StringConvertor class for managed unmanaged string conversion[^]

          -Sarath. "Great hopes make everything great possible" - Benjamin Franklin

          My blog - Sharing My Thoughts

          1 Reply Last reply
          0
          • B bubuzzz

            hi all, I am trying to convert from System::String to char *. After searching some forums and the msdn, i got these lines of code const char * convertStrToChar(System::String ^ str) { CString tmpStr (str); char* ConvToChar = new char[tmpStr.GetLength() + 2]; size_t Converted = 0; wcstombs_s(&Converted, ConvToChar, tmpStr.GetLength()+1, tmpStr, _TRUNCATE); return ConvToChar; } However, when i compilie it, these error messages appear : Error 1 error LNK2028: unresolved token (0A00023F) "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj Error 2 error LNK2019: unresolved external symbol "public: char * __clrcall Process::convertStrToChar(class System::String ^)" (?convertStrToChar@Process@@$$FQAMPADP$AAVString@System@@@Z) referenced in function "public: void __clrcall Process::showFaceDetect(class System::String ^,class System::String ^)" (?showFaceDetect@Process@@$$FQAMXP$AAVString@System@@0@Z) Process.obj I know this is a simple problem, but i cannot figure out why this bug happens. Can you give me some suggestion? Thanks

            B Offline
            B Offline
            bubuzzz
            wrote on last edited by
            #5

            thank all. i just find out the solution. It 's only a stupid mistake to toxcct: sorry. Will post in the right place next time

            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