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. CreateProcess problem and CString to char* conversion

CreateProcess problem and CString to char* conversion

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionperformance
9 Posts 6 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.
  • W Offline
    W Offline
    will1383
    wrote on last edited by
    #1

    I'm trying to run a program using CreateProcess, but I am unable to run the program due to getting a 998 error, or an "Invalid access to memory location." error. I know the reason for this is because of how CreateProcess handles path names. Here's my call to CreateProcess: CreateProcess(appPath,cmdLineInfo,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); It should work like a charm, but the problem lies within the path specified in the appPath String. This is what is in the CString appPath: "C:\Directory_1\Directory secion 2\executable.exe" Create Process doesn't handle the seperated folder name properly. How can I correct this??? In addition: How do you convert a CString to a LPTSTR??? Any help is GREATLY appreciated. Thanks!

    P L J 3 Replies Last reply
    0
    • W will1383

      I'm trying to run a program using CreateProcess, but I am unable to run the program due to getting a 998 error, or an "Invalid access to memory location." error. I know the reason for this is because of how CreateProcess handles path names. Here's my call to CreateProcess: CreateProcess(appPath,cmdLineInfo,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); It should work like a charm, but the problem lies within the path specified in the appPath String. This is what is in the CString appPath: "C:\Directory_1\Directory secion 2\executable.exe" Create Process doesn't handle the seperated folder name properly. How can I correct this??? In addition: How do you convert a CString to a LPTSTR??? Any help is GREATLY appreciated. Thanks!

      P Offline
      P Offline
      PJ Arends
      wrote on last edited by
      #2

      will1383 wrote: Create Process doesn't handle the seperated folder name properly. How can I correct this??? Just a guess, but how about enclosing the file name in quotes. If that don't work, how about converting the path to 8.3 format using GetShortPathName(). will1383 wrote: How do you convert a CString to a LPTSTR??? CString::GetBuffer() will return an LPTSTR. Just be sure to call ReleaseBuffer() when you are done.


      [

      ](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!

      1 Reply Last reply
      0
      • W will1383

        I'm trying to run a program using CreateProcess, but I am unable to run the program due to getting a 998 error, or an "Invalid access to memory location." error. I know the reason for this is because of how CreateProcess handles path names. Here's my call to CreateProcess: CreateProcess(appPath,cmdLineInfo,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); It should work like a charm, but the problem lies within the path specified in the appPath String. This is what is in the CString appPath: "C:\Directory_1\Directory secion 2\executable.exe" Create Process doesn't handle the seperated folder name properly. How can I correct this??? In addition: How do you convert a CString to a LPTSTR??? Any help is GREATLY appreciated. Thanks!

        L Offline
        L Offline
        l a u r e n
        wrote on last edited by
        #3

        to convert the scstring just cast it: (LPTSTR)(LPTCSTR)myString; might be a klunk but it works :)


        "there is no spoon"
        biz stuff   about me

        P 1 Reply Last reply
        0
        • L l a u r e n

          to convert the scstring just cast it: (LPTSTR)(LPTCSTR)myString; might be a klunk but it works :)


          "there is no spoon"
          biz stuff   about me

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #4

          (LPTSTR)(LPTCSTR)myString; Works but not recommended or safe. I Touched Osama Bin Ladens Bushy Beard

          L 1 Reply Last reply
          0
          • P Prakash Nadar

            (LPTSTR)(LPTCSTR)myString; Works but not recommended or safe. I Touched Osama Bin Ladens Bushy Beard

            L Offline
            L Offline
            l a u r e n
            wrote on last edited by
            #5

            i only use it when i know im not going to change anything :rolleyes:


            "there is no spoon"
            biz stuff   about me

            P 1 Reply Last reply
            0
            • L l a u r e n

              i only use it when i know im not going to change anything :rolleyes:


              "there is no spoon"
              biz stuff   about me

              P Offline
              P Offline
              Prakash Nadar
              wrote on last edited by
              #6

              before i knew about getbuffer i have used this kind of type casting to modify the data also, never gave me any problem but not doing it now.:rolleyes: I Touched Osama Bin Ladens Bushy Beard

              L T 2 Replies Last reply
              0
              • P Prakash Nadar

                before i knew about getbuffer i have used this kind of type casting to modify the data also, never gave me any problem but not doing it now.:rolleyes: I Touched Osama Bin Ladens Bushy Beard

                L Offline
                L Offline
                l a u r e n
                wrote on last edited by
                #7

                *coughs and shuffles feet nervously* i sometimesam too lazy to do the GetBufferSetLength() thing :-O


                "there is no spoon"
                biz stuff   about me

                1 Reply Last reply
                0
                • W will1383

                  I'm trying to run a program using CreateProcess, but I am unable to run the program due to getting a 998 error, or an "Invalid access to memory location." error. I know the reason for this is because of how CreateProcess handles path names. Here's my call to CreateProcess: CreateProcess(appPath,cmdLineInfo,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi); It should work like a charm, but the problem lies within the path specified in the appPath String. This is what is in the CString appPath: "C:\Directory_1\Directory secion 2\executable.exe" Create Process doesn't handle the seperated folder name properly. How can I correct this??? In addition: How do you convert a CString to a LPTSTR??? Any help is GREATLY appreciated. Thanks!

                  J Offline
                  J Offline
                  Jijo Raj
                  wrote on last edited by
                  #8

                  Its very simple to convert a CString to LPTSTR, Just use CString str; str.operator LPCTSTR ( ); The "operator LPCTSTR ( )" will return a char pointer to the string data. ;) Best Regards, Jijo. Yesterday is history, Tomorrow is a mystery, But today is a present.

                  1 Reply Last reply
                  0
                  • P Prakash Nadar

                    before i knew about getbuffer i have used this kind of type casting to modify the data also, never gave me any problem but not doing it now.:rolleyes: I Touched Osama Bin Ladens Bushy Beard

                    T Offline
                    T Offline
                    Tim Smith
                    wrote on last edited by
                    #9

                    Well that is a BAD thing. However, casting to (LPTSTR) to deal with some MS API routines that can not or do not have the arguments defined as (LPCTSTR) works just find AS LONG AS you know the API will not write to the string. Many API's have arguments that have double duties and thus can not be defined as (LPCTSTR). Tim Smith I'm going to patent thought. I have yet to see any prior art.

                    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