Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how dialog base application calls dos base application?

how dialog base application calls dos base application?

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    how can i calling console app and passing an argument at the same time from the dialog based application??

    S 1 Reply Last reply
    0
    • P pnpfriend

      how can i calling console app and passing an argument at the same time from the dialog based application??

      S Offline
      S Offline
      S van Leent
      wrote on last edited by
      #2

      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 :-)"

      P 2 Replies Last reply
      0
      • S S van Leent

        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 :-)"

        P Offline
        P Offline
        pnpfriend
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • S S van Leent

          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 :-)"

          P Offline
          P Offline
          pnpfriend
          wrote on last edited by
          #4

          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 below int _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.

          A R S 3 Replies Last reply
          0
          • P pnpfriend

            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 below int _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.

            A Offline
            A Offline
            AlexMarbus
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • P pnpfriend

              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 below int _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.

              R Offline
              R Offline
              Rick York
              wrote on last edited by
              #6

              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.

              P 1 Reply Last reply
              0
              • P pnpfriend

                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 below int _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.

                S Offline
                S Offline
                S van Leent
                wrote on last edited by
                #7

                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 :-)"

                P 1 Reply Last reply
                0
                • R Rick York

                  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.

                  P Offline
                  P Offline
                  pnpfriend
                  wrote on last edited by
                  #8

                  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?

                  1 Reply Last reply
                  0
                  • S S van Leent

                    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 :-)"

                    P Offline
                    P Offline
                    pnpfriend
                    wrote on last edited by
                    #9

                    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 .

                    P 1 Reply Last reply
                    0
                    • P pnpfriend

                      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 .

                      P Offline
                      P Offline
                      pnpfriend
                      wrote on last edited by
                      #10

                      i got it .. thank you all..

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups