Solved

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

Posted on 2004-08-24
14
355 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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 150 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now