Home > Back-end >  Command line start the program and double click on the program is running
Command line start the program and double click on the program is running

Time:02-06

Under Windows, I create Windows interface in a console application, vs starting and double-click the generated exe,
But there is something wrong with the command line with the command startup,

Begin to use absolute paths to start the exe start command, should be exe running path has changed, cause the program with a relative path to read documents in times wrong,

So I switch to the exe directory and run directly exe, normal program launched at this time,
But do not create Windows window,

Bosses know, give advice or comments, please,

My goal is to monitoring the operation of the target program in code, restart it, hang it with
Find an existing software can be used, but after the restart problems,
How do double-click within the code to start the effect of the target program,

CodePudding user response:

This difference is generally come from within the program, you read some configuration file, double-click on the run with the command to run, the current path is not the same,
Code that is to say, it may be some relative path will have different questions, including some of the dynamic loading the background picture

CodePudding user response:

SetCurrentDirectory
The SetCurrentDirectory function changes The current directory for The current process.

BOOL SetCurrentDirectory (
LPCTSTR lpPathName//pointer to the name of the new current directory
);

The Parameters
LpPathName
Pointer to a null - terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory.
The Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Few
Each process has a single current directory made up of two parts:

A disk designator that is either A drive letter followed by A colon, or A server name and the share name (\ \ servername \ sharename)
A directory on the disk designator
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase. H.
The Import Library: Use kernel32. Lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
The File I/O the Overview, the File Functions provides, GetCurrentDirectory


_fullpath, _wfullpath
Create an absolute path or full path name for the specified relative path name.

Char * _fullpath (char * absPath, const char * relPath, size_t maxLength);

Would be * _wfullpath (absPath would * and const would * relPath, size_t maxLength);

The Function of Required Header Compatibility
_fullpath & lt; stdlib.h> Windows 95 and Windows NT
_wfullpath & lt; stdlib.h> or Windows NT


For additional compatibility information, see compatibility in the the Introduction.

Libraries

LIBC. LIB Single thread static library, retail version
LIBCMT. LIB Multithread static library, retail version
MSVCRT. LIB Import library for MSVCRT DLL, retail version


The Return Value

Each of these functions provides returns a pointer to a buffer containing the absolute path name (absPath). If there is an error (for example, If the value passed in relPath includes a drive letter that is not valid or always be found, or If the length of the created absolute path name (absPath) is greater than maxLength), the function returns NULL.

The Parameters

AbsPath

Pointer to a buffer containing the absolute path or full path name

RelPath

Relative path name

MaxLength

Maximum length of the absolute path name buffer (absPath). This length is in bytes for _fullpath but in wide characters (would) for _wfullpath.

Few

The _fullpath function expands the relative path name in relPath to its fully qualified or "absolute" path, and stores this name in absPath. A relative path name specifies a path to another location from the current location (such as the current working directory: "."). An absolute path name is the expansion of a relative path name that states the entire path required to reach the desired location from the root of the filesystem. Unlike _makepath, _fullpath can be used to obtain the absolute path name for relative paths (relPath) that include "./" or "../"in their names.

For example, to use the run - time C routines, the application must include the header files that contain the declarations For routines. Each header file include the statement references the location of the file in a relative manner (from the application's working directory) :

#include

When the absolute path (the actual file system location) of the file may be:

\ \ machine \ shareName \ msvcSrc \ CRT \ headerFiles \ stdlib h

_fullpath automatically handles multibyte - character string arguments as appropriate, recognizing multibyte - character sequences "according to the multibyte code page currently in use. The _wfullpath is a wide - character version of _fullpath; The string arguments to _wfullpath are wide - character strings. The _wfullpath and _fullpath fitting concepts identically the except that _wfullpath does not handle multibyte - character strings.

Generic - Text Routine the Mappings

TCHAR. H Routine _UNICODE & amp; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related