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