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. Problem in SearchPath

Problem in SearchPath

Scheduled Pinned Locked Moved C / C++ / MFC
help
7 Posts 2 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.
  • S Offline
    S Offline
    SiddharthAtw
    wrote on last edited by
    #1

    I want to initialize a executable, making OS to search for the file. I am not able to resolve the error in 5th parameter. STARTUPINFO si = {sizeof(si)}; PROCESS_INFORMATION pi; TCHAR szCommandLine[1024] = {0},*pszCommandLine = 0; DWORD lFileName = SearchPathW(NULL,(LPCWSTR)"YPager",(LPCWSTR)".exe",(DWORD)sizeof(szCommandLine), szCommandLine, *pszCommandLine); BOOL bCreate = CreateProcessNULL,szCommandLine,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); The error is: 'SearchPathW' : cannot convert parameter 5 from 'char [1024]' to 'unsigned short *'. Cheers! Siddharth

    M 1 Reply Last reply
    0
    • S SiddharthAtw

      I want to initialize a executable, making OS to search for the file. I am not able to resolve the error in 5th parameter. STARTUPINFO si = {sizeof(si)}; PROCESS_INFORMATION pi; TCHAR szCommandLine[1024] = {0},*pszCommandLine = 0; DWORD lFileName = SearchPathW(NULL,(LPCWSTR)"YPager",(LPCWSTR)".exe",(DWORD)sizeof(szCommandLine), szCommandLine, *pszCommandLine); BOOL bCreate = CreateProcessNULL,szCommandLine,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); The error is: 'SearchPathW' : cannot convert parameter 5 from 'char [1024]' to 'unsigned short *'. Cheers! Siddharth

      M Offline
      M Offline
      Mukkie
      wrote on last edited by
      #2

      Hello! This is because you are calling Unicode version (SearchPathW). Use SearchPath or SearchPathA for non-Unicode version. If parameter 5 is 'char [1024]' then TCHAR is defined as char, so _UNICODE is not defined. Have a nice day or night

      S 1 Reply Last reply
      0
      • M Mukkie

        Hello! This is because you are calling Unicode version (SearchPathW). Use SearchPath or SearchPathA for non-Unicode version. If parameter 5 is 'char [1024]' then TCHAR is defined as char, so _UNICODE is not defined. Have a nice day or night

        S Offline
        S Offline
        SiddharthAtw
        wrote on last edited by
        #3

        It's not working even with SearchPath(). There is no compiler error as such but the thing is not execeuting. Any other suggestion for solving the problem

        M 1 Reply Last reply
        0
        • S SiddharthAtw

          It's not working even with SearchPath(). There is no compiler error as such but the thing is not execeuting. Any other suggestion for solving the problem

          M Offline
          M Offline
          Mukkie
          wrote on last edited by
          #4

          Tell me exactly what you want to do. You want to locate executable file which is on system path? Or acquire path to executable which is currently running under the debugger?

          S 1 Reply Last reply
          0
          • M Mukkie

            Tell me exactly what you want to do. You want to locate executable file which is on system path? Or acquire path to executable which is currently running under the debugger?

            S Offline
            S Offline
            SiddharthAtw
            wrote on last edited by
            #5

            I want to loacte executable where ever it is on the Harddisk. Thing is I am not sure whether exe will be in System Directory or Program Files. Hence Search for the file on My Computer kind of thing. Waiting for reply. Cheers!!! Siddharth

            M 1 Reply Last reply
            0
            • S SiddharthAtw

              I want to loacte executable where ever it is on the Harddisk. Thing is I am not sure whether exe will be in System Directory or Program Files. Hence Search for the file on My Computer kind of thing. Waiting for reply. Cheers!!! Siddharth

              M Offline
              M Offline
              Mukkie
              wrote on last edited by
              #6

              So you should not use SearchPath() Use either SHFindFiles or locate the file by yourself, by traversing directories, and using FindFirstFile, FindNextFile. Search path searches for file in: 1) The directory from which the application loaded. 2) The current directory. 3) The system directory. Use the GetSystemDirectory function to get the path of this directory. 4) The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched. 5) The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6) The directories that are listed in the PATH environment variable. These are not all directories for sure :)

              S 1 Reply Last reply
              0
              • M Mukkie

                So you should not use SearchPath() Use either SHFindFiles or locate the file by yourself, by traversing directories, and using FindFirstFile, FindNextFile. Search path searches for file in: 1) The directory from which the application loaded. 2) The current directory. 3) The system directory. Use the GetSystemDirectory function to get the path of this directory. 4) The 16-bit system directory. There is no function that retrieves the path of this directory, but it is searched. 5) The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6) The directories that are listed in the PATH environment variable. These are not all directories for sure :)

                S Offline
                S Offline
                SiddharthAtw
                wrote on last edited by
                #7

                That's very nice of you. These are very valuable suggestions. But do U agree with my thinking? Or can U suggest something better then that.

                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