Snowman288
Snowman288

Reputation: 107

How can I open a file inside of an exe inside of my c++ app

Question is I have this button that when clicked I would like it open a file for me inside of a specific executable.

I am a tad rusty on c++ and this is a legacy application using c++ 6.0 built on windows xp.....So any help would be greatly appreciated!

Here is my code cpp

void CJunkView::OnCadkeyButton() 

  {
   CString fileToOpen = "C:\\Documents and Settings\\Administrator\\Desktop\\x.prt";
   CString exePath = "C:\\CK19\\Ckwin.exe";
   system ("start (exePath), (fileToOpen)");
  }

When I click this button it returns this Windows cannot find 'exePath,'.Make sure you typed the name correctly and then try again.

Upvotes: 0

Views: 95

Answers (1)

NathanOliver
NathanOliver

Reputation: 180415

You need to build a string that contains the entire system call and the pass the buffer of that string to system()

Edit:

In response to the comment by IInspectable we could just use the implicit conversion operator operator LPCTSTR()

void CJunkView::OnCadkeyButton() 
{
   CString fileToOpen = "C:\\Documents and settings\\Administrator\\Desktop\\x.prt";
   CString exePath = "C:\\CK19\\Ckwin.exe";
   CString cmd = "start " + exePath + ", " + fileToOpen;
   system (cmd);
}

Upvotes: 3

Related Questions