Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-24
14
Medium Priority
?
373 Views
Last Modified: 2013-11-20
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
Comment
Question by:ericcnc
  • 7
  • 5
  • 2
14 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 11881536
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
 
LVL 13

Expert Comment

by:SteH
ID: 11881547
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11881569
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ericcnc
ID: 11881655
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
 
LVL 13

Expert Comment

by:SteH
ID: 11881786
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
 

Author Comment

by:ericcnc
ID: 11881800
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
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11881817
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
 

Author Comment

by:ericcnc
ID: 11881829
>>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
 
LVL 13

Expert Comment

by:SteH
ID: 11881837
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
 

Author Comment

by:ericcnc
ID: 11882002
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
 

Author Comment

by:ericcnc
ID: 11882017
Sorry ,

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

Author Comment

by:ericcnc
ID: 11882062
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
 
LVL 13

Accepted Solution

by:
SteH earned 600 total points
ID: 11882595
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
 

Author Comment

by:ericcnc
ID: 11889061
Thank SteH, that worked out quite nicely! :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question