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\\D ebug\\Vte. exe";
// bstr="C:\\Microsoft Visual Studio\\MyProjects\\App1\\ temp.txt"; ****Didn't like this at all
bstr="C:\\temp.txt";
ShellExecute(NULL,"open",a str,bstr,N ULL,SW_SHO W );
}
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.....
(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\\D
// bstr="C:\\Microsoft Visual Studio\\MyProjects\\App1\\
bstr="C:\\temp.txt";
ShellExecute(NULL,"open",a
}
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.....
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.
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.
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( )
?
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?
If you supply bstr how do you read it? In InitInstance () you can read the command line from the CWinAppp::m_lpCommandLine.
ASKER
I just tried this,
astr="C:\\Microsoft Visual Studio\\MyProjects\\Vte\\D ebug\\Vte. exe";
// bstr="C:\\temp.txt";
bstr="C:\Documents and Settings\Me\My Documents\VirtuQ1.qjf";
ShellExecute(NULL,"open",a str,bstr,N ULL,SW_SHO W );
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 "
astr="C:\\Microsoft Visual Studio\\MyProjects\\Vte\\D
// bstr="C:\\temp.txt";
bstr="C:\Documents and Settings\Me\My Documents\VirtuQ1.qjf";
ShellExecute(NULL,"open",a
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 "
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
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
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
>>If you supply bstr how do you read it? In InitInstance () you can read the command >>line from the CWinAppp::m_lpCommandLine.
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\"";
"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\"";
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.
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.
ASKER
Sorry ,
What is the proper function to override to read in the file?
and where do you get the file pathname.
What is the proper function to override to read in the file?
and where do you get the file pathname.
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)
(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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank SteH, that worked out quite nicely! :)