• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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.....
0
ericcnc
Asked:
ericcnc
  • 7
  • 5
  • 2
1 Solution
 
SteHCommented:
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.
0
 
SteHCommented:
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.
0
 
Jaime OlivaresSoftware ArchitectCommented:
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.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ericcncAuthor Commented:
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( )

?
0
 
SteHCommented:
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?
0
 
ericcncAuthor Commented:
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   "
0
 
Jaime OlivaresSoftware ArchitectCommented:
About ShellExecute info, here is:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp

Also you can try with WinExec, it is simpler, but you have to construct all your command in a single string:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/winexec.asp
0
 
ericcncAuthor Commented:
>>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
0
 
SteHCommented:
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\"";
0
 
ericcncAuthor Commented:
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.
0
 
ericcncAuthor Commented:
Sorry ,

What is the proper function to override to read in the file?
 and where do you get the file pathname.
0
 
ericcncAuthor Commented:
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)
0
 
SteHCommented:
It might be done without any modifications. If you need to read it yourself you can access the command line and its parameters in CWinApp::InitInstance ()
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwinapp.3a3a.m_lpcmdline.asp
0
 
ericcncAuthor Commented:
Thank SteH, that worked out quite nicely! :)
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now