how dialog base application calls dos base application?
-
how can i calling console app and passing an argument at the same time from the dialog based application??
ShellExecute or ShellExecuteEx HINSTANCE ShellExecute( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd ); -- or -- BOOL ShellExecuteEx( LPSHELLEXECUTEINFO lpExecInfo ); typedef struct _SHELLEXECUTEINFO{ DWORD cbSize; ULONG fMask; HWND hwnd; LPCTSTR lpVerb; LPCTSTR lpFile; LPCTSTR lpParameters; LPCTSTR lpDirectory; int nShow; HINSTANCE hInstApp; // Optional members LPVOID lpIDList; LPCSTR lpClass; HKEY hkeyClass; DWORD dwHotKey; union { HANDLE hIcon; HANDLE hMonitor; }; HANDLE hProcess; } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; That will do it Sjoerd van Leent LPCSTR Dutch = "Double Dutch :-)"
-
ShellExecute or ShellExecuteEx HINSTANCE ShellExecute( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd ); -- or -- BOOL ShellExecuteEx( LPSHELLEXECUTEINFO lpExecInfo ); typedef struct _SHELLEXECUTEINFO{ DWORD cbSize; ULONG fMask; HWND hwnd; LPCTSTR lpVerb; LPCTSTR lpFile; LPCTSTR lpParameters; LPCTSTR lpDirectory; int nShow; HINSTANCE hInstApp; // Optional members LPVOID lpIDList; LPCSTR lpClass; HKEY hkeyClass; DWORD dwHotKey; union { HANDLE hIcon; HANDLE hMonitor; }; HANDLE hProcess; } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; That will do it Sjoerd van Leent LPCSTR Dutch = "Double Dutch :-)"
but how? for my dos based application, which takes 3 arguments,
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
is lpParameters will be the one i should set for my an argument? what about int argc and the third parameter envp in main? I dont' really understand because I have never call any applications from one applications. thanks -
ShellExecute or ShellExecuteEx HINSTANCE ShellExecute( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd ); -- or -- BOOL ShellExecuteEx( LPSHELLEXECUTEINFO lpExecInfo ); typedef struct _SHELLEXECUTEINFO{ DWORD cbSize; ULONG fMask; HWND hwnd; LPCTSTR lpVerb; LPCTSTR lpFile; LPCTSTR lpParameters; LPCTSTR lpDirectory; int nShow; HINSTANCE hInstApp; // Optional members LPVOID lpIDList; LPCSTR lpClass; HKEY hkeyClass; DWORD dwHotKey; union { HANDLE hIcon; HANDLE hMonitor; }; HANDLE hProcess; } SHELLEXECUTEINFO, *LPSHELLEXECUTEINFO; That will do it Sjoerd van Leent LPCSTR Dutch = "Double Dutch :-)"
This is how I had tried but it is not working!:(( the following code is in the dialog based application
void DialogBasedApp::OnTesting() { SHELLEXECUTEINFO lpExecInfo; const char* verb = "open"; lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); lpExecInfo.lpFile = "c:\\printExcel\\Debug\\printExcel.exe"; lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ; lpExecInfo.hwnd = NULL; lpExecInfo.lpVerb = verb; lpExecInfo.lpParameters = "c:\\testing.xls"; lpExecInfo.lpDirectory = NULL; lpExecInfo.nShow = SW_SHOW ; lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ; //WINSHELLAPI BOOL WINAPI result; ShellExecuteEx(&lpExecInfo); if(lpExecInfo.hProcess != NULL) { ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE); ::CloseHandle(lpExecInfo.hProcess); } MessageBox("Finished Printing Excel"); }
my dos based application, which is called printExcel.cpp, is right belowint _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { AfxMessageBox(argv[0]); return 1; }
Honestly, i don't even know how to get the argument so no doubt that i have no idea where the program got wrong. :(( can you tell me what and where it got wrong and how to fix it, please. -
This is how I had tried but it is not working!:(( the following code is in the dialog based application
void DialogBasedApp::OnTesting() { SHELLEXECUTEINFO lpExecInfo; const char* verb = "open"; lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); lpExecInfo.lpFile = "c:\\printExcel\\Debug\\printExcel.exe"; lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ; lpExecInfo.hwnd = NULL; lpExecInfo.lpVerb = verb; lpExecInfo.lpParameters = "c:\\testing.xls"; lpExecInfo.lpDirectory = NULL; lpExecInfo.nShow = SW_SHOW ; lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ; //WINSHELLAPI BOOL WINAPI result; ShellExecuteEx(&lpExecInfo); if(lpExecInfo.hProcess != NULL) { ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE); ::CloseHandle(lpExecInfo.hProcess); } MessageBox("Finished Printing Excel"); }
my dos based application, which is called printExcel.cpp, is right belowint _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { AfxMessageBox(argv[0]); return 1; }
Honestly, i don't even know how to get the argument so no doubt that i have no idea where the program got wrong. :(( can you tell me what and where it got wrong and how to fix it, please.Hi Win, In this line: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) is actually all you need. The 'argc' is the number of items specified on the commandline. The array argv are all commandline arguments (including the name of the executable itself, printExcel.exe). You can retrieve every argument by just using the index in the array: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { CString strArgument; for (int i = 0; i < argc; i++) strArgument = argv[i]; } // Not compiled, assuming it's correct -- Alex Marbus www.marbus.net But then again, I could be wrong.
-
This is how I had tried but it is not working!:(( the following code is in the dialog based application
void DialogBasedApp::OnTesting() { SHELLEXECUTEINFO lpExecInfo; const char* verb = "open"; lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); lpExecInfo.lpFile = "c:\\printExcel\\Debug\\printExcel.exe"; lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ; lpExecInfo.hwnd = NULL; lpExecInfo.lpVerb = verb; lpExecInfo.lpParameters = "c:\\testing.xls"; lpExecInfo.lpDirectory = NULL; lpExecInfo.nShow = SW_SHOW ; lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ; //WINSHELLAPI BOOL WINAPI result; ShellExecuteEx(&lpExecInfo); if(lpExecInfo.hProcess != NULL) { ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE); ::CloseHandle(lpExecInfo.hProcess); } MessageBox("Finished Printing Excel"); }
my dos based application, which is called printExcel.cpp, is right belowint _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { AfxMessageBox(argv[0]); return 1; }
Honestly, i don't even know how to get the argument so no doubt that i have no idea where the program got wrong. :(( can you tell me what and where it got wrong and how to fix it, please.I see two odd things here. First, how can you call AfxMessageBox in a DOS-based app ? If it is really a DOS app then shouldn't you use printf ? You can add a getch() to see what the console window says before it closes. FWIW, argv[0] will be the name of the executable always, regardless of what args are passed. argv[1] will be the first passed argument and argc will tell you how many were passed. I think this has been said already but I will reiterate. Here is a loop to print out all passed args except for the exe's name (which is why we start at 1) : for( int index = 1; index < argc; index += 1 ) fprintf( stdout, "arg %d is '%s'\n", index, argv[index] ); Second is a stylistic issue. You appear to be using Hungarian notation. Well, lp stands for long pointer and you have an instance of the structure so it is not a pointer.
-
This is how I had tried but it is not working!:(( the following code is in the dialog based application
void DialogBasedApp::OnTesting() { SHELLEXECUTEINFO lpExecInfo; const char* verb = "open"; lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); lpExecInfo.lpFile = "c:\\printExcel\\Debug\\printExcel.exe"; lpExecInfo.fMask=SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS ; lpExecInfo.hwnd = NULL; lpExecInfo.lpVerb = verb; lpExecInfo.lpParameters = "c:\\testing.xls"; lpExecInfo.lpDirectory = NULL; lpExecInfo.nShow = SW_SHOW ; lpExecInfo.hInstApp = (HINSTANCE) SE_ERR_DDEFAIL ; //WINSHELLAPI BOOL WINAPI result; ShellExecuteEx(&lpExecInfo); if(lpExecInfo.hProcess != NULL) { ::WaitForSingleObject(lpExecInfo.hProcess, INFINITE); ::CloseHandle(lpExecInfo.hProcess); } MessageBox("Finished Printing Excel"); }
my dos based application, which is called printExcel.cpp, is right belowint _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { AfxMessageBox(argv[0]); return 1; }
Honestly, i don't even know how to get the argument so no doubt that i have no idea where the program got wrong. :(( can you tell me what and where it got wrong and how to fix it, please.Do you need the extra params of ShellExecuteEx? Else, I would just use: ShellExecute(hInstance, //handle of the executing program*/ "open", // open the program "C:\\program.exe", //Windows register understands that this will be an executable "/?", // you don't know how to use program.exe, so typing a question mark NULL, // You can give up de directory, but is not necessary SW_SHOWNORMAL // show the damned console window ); LPCSTR Dutch = "Double Dutch :-)"
-
I see two odd things here. First, how can you call AfxMessageBox in a DOS-based app ? If it is really a DOS app then shouldn't you use printf ? You can add a getch() to see what the console window says before it closes. FWIW, argv[0] will be the name of the executable always, regardless of what args are passed. argv[1] will be the first passed argument and argc will tell you how many were passed. I think this has been said already but I will reiterate. Here is a loop to print out all passed args except for the exe's name (which is why we start at 1) : for( int index = 1; index < argc; index += 1 ) fprintf( stdout, "arg %d is '%s'\n", index, argv[index] ); Second is a stylistic issue. You appear to be using Hungarian notation. Well, lp stands for long pointer and you have an instance of the structure so it is not a pointer.
oh yeah.. my dos based application support MFC therefore i can call AfxMessageBox(). you know when you build the project, in first step, you choose win32 console application and in step 2, you choose hello world support MFC option instead of hello world and empty application. for second question i can't explain coz i don't know what is Hungarian notation.. ^_^ no clue at all. what is it?
-
Do you need the extra params of ShellExecuteEx? Else, I would just use: ShellExecute(hInstance, //handle of the executing program*/ "open", // open the program "C:\\program.exe", //Windows register understands that this will be an executable "/?", // you don't know how to use program.exe, so typing a question mark NULL, // You can give up de directory, but is not necessary SW_SHOWNORMAL // show the damned console window ); LPCSTR Dutch = "Double Dutch :-)"
Thanks.. but I need to pass an argument, which is going to be file name. the dos based program is basically opening excel files and format it like setting pagesetup like all pages in landscape, scaling 70%, fixing the margins.. and so on. the dialog based program, smpPrint, have files' names, including excel files. other files could be, .txt, .doc, .tif, etc. i want smpPrint to use the excelPrint, dos based program, will take a file name, and format it. that's what i want to do. and i have to know when the user closed Microsoft Excel application, so i have to use shellexecutex. shellexecuteex have a parameter that can tell the application is closed .
-
Thanks.. but I need to pass an argument, which is going to be file name. the dos based program is basically opening excel files and format it like setting pagesetup like all pages in landscape, scaling 70%, fixing the margins.. and so on. the dialog based program, smpPrint, have files' names, including excel files. other files could be, .txt, .doc, .tif, etc. i want smpPrint to use the excelPrint, dos based program, will take a file name, and format it. that's what i want to do. and i have to know when the user closed Microsoft Excel application, so i have to use shellexecutex. shellexecuteex have a parameter that can tell the application is closed .