convert System::String to char *
-
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
-
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
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 ^)
-
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
this is not C++, it is C++/CLI. so it belongs to the Managed C++ forum
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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
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
-
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