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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to pass parameters to a Exe file

How to pass parameters to a Exe file

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
6 Posts 4 Posters 0 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
    poda
    wrote on last edited by
    #1

    In a DLL function,I need to call a exe and pass parameters to that exe. Actually the parameters are to be used in a function of the exe file. In Dll function extern "C" __declspec(dllexport) PlotWave(double *Data,int nData,int mode) { HWND hExeWnd=FindWindow(NULL,"WFP"); if(hExeWnd) { SetForegroundWindow(hExeWnd); ShowWindow(hExeWnd,SW_SHOW); } else ShellExecute(NULL,"open","C:\\wfp.exe",NULL,NULL,SW_SHOW); } Now I have to pass those parameters(double*,int,int) to the wfp.exe. I know in ShellExecute we can pass parameter to the file we want to open. But how can my wfp.exe accept that parameters. What should I write in my wfp.exe to do so. I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

    N P L 3 Replies Last reply
    0
    • P poda

      In a DLL function,I need to call a exe and pass parameters to that exe. Actually the parameters are to be used in a function of the exe file. In Dll function extern "C" __declspec(dllexport) PlotWave(double *Data,int nData,int mode) { HWND hExeWnd=FindWindow(NULL,"WFP"); if(hExeWnd) { SetForegroundWindow(hExeWnd); ShowWindow(hExeWnd,SW_SHOW); } else ShellExecute(NULL,"open","C:\\wfp.exe",NULL,NULL,SW_SHOW); } Now I have to pass those parameters(double*,int,int) to the wfp.exe. I know in ShellExecute we can pass parameter to the file we want to open. But how can my wfp.exe accept that parameters. What should I write in my wfp.exe to do so. I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      poda123 wrote:

      But how can my wfp.exe accept that parameters. What should I write in my wfp.exe to do so.

      Look up GetCommandLine and CommandLineToArgv.


      Nibu thomas A Developer Programming tips[^]  My site[^]

      1 Reply Last reply
      0
      • P poda

        In a DLL function,I need to call a exe and pass parameters to that exe. Actually the parameters are to be used in a function of the exe file. In Dll function extern "C" __declspec(dllexport) PlotWave(double *Data,int nData,int mode) { HWND hExeWnd=FindWindow(NULL,"WFP"); if(hExeWnd) { SetForegroundWindow(hExeWnd); ShowWindow(hExeWnd,SW_SHOW); } else ShellExecute(NULL,"open","C:\\wfp.exe",NULL,NULL,SW_SHOW); } Now I have to pass those parameters(double*,int,int) to the wfp.exe. I know in ShellExecute we can pass parameter to the file we want to open. But how can my wfp.exe accept that parameters. What should I write in my wfp.exe to do so. I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

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

        poda123 wrote:

        What should I write in my wfp.exe to do so

        Entry point function of your exe(main,winmain etc.) will take care of that. You need to Parse its parameters. In case of windows application you can use GetCommandLine, as suggested earlier.

        poda123 wrote:

        I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

        In this case, you can wrap required information in structure. i.e.

        class myInfo
        {
        double *m_pDouble;
        int m_iFirst;
        int m_iSecond;
        public:
        myInfo():m_pDouble(NULL),m_iFirst(0),m_iSecond(0)
        {
        }
        };

        myInfo *pSendInfo = new myInfo;
        SendMessage(hExeWnd,WM_PLOTWAVE,(WPARAM)pSendInfo,0);

        Now, in command handler you can unwrap the information.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        P 1 Reply Last reply
        0
        • P poda

          In a DLL function,I need to call a exe and pass parameters to that exe. Actually the parameters are to be used in a function of the exe file. In Dll function extern "C" __declspec(dllexport) PlotWave(double *Data,int nData,int mode) { HWND hExeWnd=FindWindow(NULL,"WFP"); if(hExeWnd) { SetForegroundWindow(hExeWnd); ShowWindow(hExeWnd,SW_SHOW); } else ShellExecute(NULL,"open","C:\\wfp.exe",NULL,NULL,SW_SHOW); } Now I have to pass those parameters(double*,int,int) to the wfp.exe. I know in ShellExecute we can pass parameter to the file we want to open. But how can my wfp.exe accept that parameters. What should I write in my wfp.exe to do so. I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

          L Offline
          L Offline
          LOUIS Christian
          wrote on last edited by
          #4

          You can also use WM_COPY message during execution or use shared memory

          1 Reply Last reply
          0
          • P prasad_som

            poda123 wrote:

            What should I write in my wfp.exe to do so

            Entry point function of your exe(main,winmain etc.) will take care of that. You need to Parse its parameters. In case of windows application you can use GetCommandLine, as suggested earlier.

            poda123 wrote:

            I tried using SendMessage(hExeWnd,WM_PLOTWAVE,0,0). My wfp.exe only can recieve the message but how to get the parameters because SendMessages() accepts only WPARAM and LPARAM. Help please!

            In this case, you can wrap required information in structure. i.e.

            class myInfo
            {
            double *m_pDouble;
            int m_iFirst;
            int m_iSecond;
            public:
            myInfo():m_pDouble(NULL),m_iFirst(0),m_iSecond(0)
            {
            }
            };

            myInfo *pSendInfo = new myInfo;
            SendMessage(hExeWnd,WM_PLOTWAVE,(WPARAM)pSendInfo,0);

            Now, in command handler you can unwrap the information.

            Prasad Notifier using ATL | Operator new[],delete[][^]

            P Offline
            P Offline
            poda
            wrote on last edited by
            #5

            Thanks for your replies. As I need to pass a double pointer as a parameter, ShellExecute would not be working. As suggested by prasad,I used SendMessage() function. In the DLL function extern "C" __declspec(dllexport) void __stdcall PlotWaveForm(double *Data,int nData,int Mode) { double *pData=new double;//just checked for one parameter SendMessage(hExeWnd,WM_PLOTWAVE,(WPARAM)pData,0); delete pData; } In the recieving application(.exe),I cast the pData to double* as void CWFPDlg::PlotWave(UINT Msg,WPARAM wparam,LPARAM lparam) { double *WaveData=NULL; WaveData=(double*)wparam; } Since wparam is a pointer to double array, I used WaveData[i] to get values to plot the wave,but the values in the array are not correct.What's the problem.

            P 1 Reply Last reply
            0
            • P poda

              Thanks for your replies. As I need to pass a double pointer as a parameter, ShellExecute would not be working. As suggested by prasad,I used SendMessage() function. In the DLL function extern "C" __declspec(dllexport) void __stdcall PlotWaveForm(double *Data,int nData,int Mode) { double *pData=new double;//just checked for one parameter SendMessage(hExeWnd,WM_PLOTWAVE,(WPARAM)pData,0); delete pData; } In the recieving application(.exe),I cast the pData to double* as void CWFPDlg::PlotWave(UINT Msg,WPARAM wparam,LPARAM lparam) { double *WaveData=NULL; WaveData=(double*)wparam; } Since wparam is a pointer to double array, I used WaveData[i] to get values to plot the wave,but the values in the array are not correct.What's the problem.

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              There should not be any problem.

              poda123 wrote:

              double *pData=new double;//just checked for one parameter SendMessage(hExeWnd,WM_PLOTWAVE,(WPARAM)pData,0); delete pData;

              I hope you have passed some value in array.

              poda123 wrote:

              double *WaveData=NULL; WaveData=(double*)wparam;

              Does WaveData showing some garbage or showing just NULL. If its showing garbage value; try commenting delete pData; statement after SendMessage.

              Prasad Notifier using ATL | Operator new[],delete[][^]

              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