Link to home
Start Free TrialLog in
Avatar of ericcnc
ericcnc

asked on

Calling a application App2 from inside another (App1) and getting App2 to read a custom file

I have a application(App2) I want to call from inside another, but I also want it to read a custom file I wrote inside app1.

(BIG PICTURE, I WANT TO CALL APP2 FROM APP1 AND FEED IT INFORMATION APP1 MADE FOR IT, IT DOESN'T HAVE TO READ A FILE IF THERE IS A BETTER OPTION, A FILE IS ALL I CAN THINK OF THAT WILL WORK)

void CMainFrame::OnButtonAPP2()
{
      // TODO: Add your command handler code here
      CString astr, bstr;
      astr="C:\\Microsoft Visual Studio\\MyProjects\\Vte\\Debug\\Vte.exe";
//      bstr="C:\\Microsoft Visual Studio\\MyProjects\\App1\\temp.txt";  ****Didn't like this at all
      bstr="C:\\temp.txt";
      ShellExecute(NULL,"open",astr,bstr,NULL,SW_SHOW );
}

This calls up app2 but it doesn't load the file, or I don't know of any other way to give app2 the infromation it needs to populate its dialogs.....
Avatar of Member_2_1001466
Member_2_1001466

You can use always the same filename. In that case app1 creates the file and calls app2. Latter opens that file in OnInitDialog (). The file name could contain a GUID to be sure that no other application creates accidently a file with the same name. (temp.txt is too likely to exist). On termination app2 should remove the file.
Or you could open a memory mapped file in app1 and read it from app2 if you want to avoid creating a file on disk. Depends a bit on what exatcly you want to achieve.
There are many factor that can affect second app.

Check if you have closed your file in your first app before trying to open it with second app
Check if your second app is really able to open a file, try with window explorer, locate the file, and press right button, choose "Open with..." and select manually your second app.
Also try to open the file by manually launching your second app and use "Open..." option.
Avatar of ericcnc

ASKER

What function do you have to overide in App2 to get it to read the file that App1 tells it to read.?

Is there a name that is passed to it?    Where do you get it from when you ShellExecute( )

?
Do you need to tell? It could be a hardcoded name.

If you supply bstr how do you read it? In InitInstance () you can read the command line from the CWinAppp::m_lpCommandLine. Do you find bstr there?
Avatar of ericcnc

ASKER

I just tried this,

                astr="C:\\Microsoft Visual Studio\\MyProjects\\Vte\\Debug\\Vte.exe";
//      bstr="C:\\temp.txt";
      bstr="C:\Documents and Settings\Me\My Documents\VirtuQ1.qjf";
      ShellExecute(NULL,"open",astr,bstr,NULL,SW_SHOW );


It says ,   "  C:\Documents and Settings\Me\My Documents was not found  "



if I do this

      bstr="C:\\Documents and Settings\\Me\\My Documents\\VirtuQ1.qjf";

It says ,   "  C:\Documents was not found   "
Avatar of ericcnc

ASKER

>>Do you need to tell? It could be a hardcoded name.

>>If you supply bstr how do you read it? In InitInstance () you can read the command >>line from the CWinAppp::m_lpCommandLine. Do you find bstr there?

It most likely will not be hardcoded, because it depends on where this is installed, but can be directed to anywhere, so it must be soft

>>If you supply bstr how do you read it?

This is what I'm not sure of, I dont know, I will check
You need to get it to appear as
"C:\Documents and Settings\Me\My Documents\VirtuQ1.qjf"
in the call. So you need to add one layer of quotation marks"
 bstr="\"C:\\Documents and Settings\\Me\\My Documents\\VirtuQ1.qjf\"";
Avatar of ericcnc

ASKER

That fixed the bstr,  :)

Now for the final thing, what do you need to overide to read in the file? When you call execute?

So...

What is the proper function to override to read in the file?)
and where do you get the file name.
Avatar of ericcnc

ASKER

Sorry ,

What is the proper function to override to read in the file?
 and where do you get the file pathname.
Avatar of ericcnc

ASKER

I assume it is the same function that handles if you drag the file onto the application.

(I also noticed that when I call it now, the top of the title bar shows the file in the header which is good)
ASKER CERTIFIED SOLUTION
Avatar of Member_2_1001466
Member_2_1001466

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ericcnc

ASKER

Thank SteH, that worked out quite nicely! :)