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 to pass a Structure to CreateProcess as CommnadLine parameter?

How to pass a Structure to CreateProcess as CommnadLine parameter?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 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.
  • G Offline
    G Offline
    ginee
    wrote on last edited by
    #1

    Hi all, While i use CreateProcess( LPCWSTR pszImageName, LPCWSTR pszCmdLine, LPSECURITY_ATTRIBUTES psaProcess, LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, DWORD fdwCreate, LPVOID pvEnvironment, LPWSTR pszCurDir, LPSTARTUPINFOW psiStartInfo, LPPROCESS_INFORMATION pProcInfo ); I want to pass a structure as second parameter(pszCmdLine) in this function. But somehow child process can't correctly get the structure! Should i do anything like "cast" or.. before i pass it? thanks for any advice!

    R C B 3 Replies Last reply
    0
    • G ginee

      Hi all, While i use CreateProcess( LPCWSTR pszImageName, LPCWSTR pszCmdLine, LPSECURITY_ATTRIBUTES psaProcess, LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, DWORD fdwCreate, LPVOID pvEnvironment, LPWSTR pszCurDir, LPSTARTUPINFOW psiStartInfo, LPPROCESS_INFORMATION pProcInfo ); I want to pass a structure as second parameter(pszCmdLine) in this function. But somehow child process can't correctly get the structure! Should i do anything like "cast" or.. before i pass it? thanks for any advice!

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

      How do you plan to pass the data of the structure ? You can't just pass a pointer to the second process because the pointer is only valid in the context of the original process. I think you need to pass the value of each member of the structure as a text string to the second process and it must parse the values and "re-assemble" the data structure.

      C 1 Reply Last reply
      0
      • G ginee

        Hi all, While i use CreateProcess( LPCWSTR pszImageName, LPCWSTR pszCmdLine, LPSECURITY_ATTRIBUTES psaProcess, LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, DWORD fdwCreate, LPVOID pvEnvironment, LPWSTR pszCurDir, LPSTARTUPINFOW psiStartInfo, LPPROCESS_INFORMATION pProcInfo ); I want to pass a structure as second parameter(pszCmdLine) in this function. But somehow child process can't correctly get the structure! Should i do anything like "cast" or.. before i pass it? thanks for any advice!

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        The command line parameter is a string. Because it's a wide string, each character is two bytes. You should pass the parts of the struct as a comma seperated string and rebuild it in the process. Christian Graus - Microsoft MVP - C++

        1 Reply Last reply
        0
        • R Rick York

          How do you plan to pass the data of the structure ? You can't just pass a pointer to the second process because the pointer is only valid in the context of the original process. I think you need to pass the value of each member of the structure as a text string to the second process and it must parse the values and "re-assemble" the data structure.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          gosh - it didn't occur to me that he could be trying to pass a pointer :-) Christian Graus - Microsoft MVP - C++

          R 1 Reply Last reply
          0
          • C Christian Graus

            gosh - it didn't occur to me that he could be trying to pass a pointer :-) Christian Graus - Microsoft MVP - C++

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

            I don't know - I try to assume literal interpretations of questions. I could easily be wrong. ;) I guess another option for him is WM_COPYDATA.

            B 1 Reply Last reply
            0
            • R Rick York

              I don't know - I try to assume literal interpretations of questions. I could easily be wrong. ;) I guess another option for him is WM_COPYDATA.

              B Offline
              B Offline
              Blake V Miller
              wrote on last edited by
              #6

              I also assumed they wanted to pass data or a pointer to some data.

              1 Reply Last reply
              0
              • G ginee

                Hi all, While i use CreateProcess( LPCWSTR pszImageName, LPCWSTR pszCmdLine, LPSECURITY_ATTRIBUTES psaProcess, LPSECURITY_ATTRIBUTES psaThread, BOOL fInheritHandles, DWORD fdwCreate, LPVOID pvEnvironment, LPWSTR pszCurDir, LPSTARTUPINFOW psiStartInfo, LPPROCESS_INFORMATION pProcInfo ); I want to pass a structure as second parameter(pszCmdLine) in this function. But somehow child process can't correctly get the structure! Should i do anything like "cast" or.. before i pass it? thanks for any advice!

                B Offline
                B Offline
                Blake V Miller
                wrote on last edited by
                #7

                Generate a new GUID. Make a memory mapped file (MMF) using this GUID as its name. Pass this name as a command line argument to the new process. Open the MMF from the second process and read your data from the MMF.

                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