1

i need to know how to use a variable in parameters PROCESS is initalized as string PROCESS in the class parameters.

Process::GetProcessesByName("")

which gives me an error when i replace the string with a variable

Process::GetProcessesByName(PROCESS)

The error i get back is: No instance of overloaded function "System::Diagnostics::Process::GetProcessByName" Matches the argument list argument types are (std::string)

John Dibling
  • 99,718
  • 31
  • 186
  • 324

1 Answers1

0

I think GetProcessesByName may take a parameter as LPSTR or char const *, but not a std::string,

try use

Process::GetProcessesByName(PROCESS.c_str());

or if your PROCESS is defined as std::string PROCESS;,

   String^ process_name = gcnew String(PROCESS.c_str());
   Process::GetProcessesByName(process_name);
CS Pei
  • 10,869
  • 1
  • 27
  • 46
  • "System::Diagnostics::Process::GetProcessByName" Matches the argument list argument types are (const char *) –  Oct 07 '13 at 18:54
  • If it needs a `char const *`, then `std::string::c_str()` should work. – CS Pei Oct 07 '13 at 18:56
  • Try `Process::GetProcessesByName(PROCESS.c_str());` . If it does not work, what's error message? – CS Pei Oct 07 '13 at 19:01
  • the error is "System::Diagnostics::Process::GetProcessByName" Matches the argument list argument types are (const char *) –  Oct 07 '13 at 19:06
  • The paramater takes datatype of string^ according to msdn http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1 –  Oct 07 '13 at 19:07
  • @RichardGrant You seem to be lacking in absolute basics. You should consider following a beginners' tutorial or a [good book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Angew is no longer proud of SO Oct 07 '13 at 19:07
  • If i am lacking in absolute basics then you should be able to answer the question rather then being pompous. –  Oct 07 '13 at 19:09
  • 1
    to get a `System::String^` from `std::string`, try `string str = "test"; String^ str2 = gcnew String(str.c_str());` – CS Pei Oct 07 '13 at 19:09
  • I think your on the right track but its giving me an error system::String str2^ expression must have a class type –  Oct 07 '13 at 19:18
  • @RichardGrant Sorry, I didn't mean to sound offensive (or pompous). But I do believe that at basic level, a good tutorial or book provides better learning material than separate questions about individual problems. – Angew is no longer proud of SO Oct 07 '13 at 19:34