The GetCurrentDirectory function retrieves the current directory for the current process. DWORD GetCurrentDirectory( DWORD nBufferLength, // size, in characters, of directory buffer LPTSTR lpBuffer // address of buffer for current directory ); ParametersnBufferLengthSpecifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character. lpBufferPoints to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. Return ValuesIf the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character. If the function fails, the return value is zero. To get extended error information, call GetLastError. If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.
The GetSystemDirectory function retrieves the path of the Windows system directory. The system directory contains such files as Windows libraries, drivers, and font files. UINT GetSystemDirectory( LPTSTR lpBuffer, // address of buffer for system directory UINT uSize // size of directory buffer ); ParameterslpBufferPoints to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WINDOWS\SYSTEM on drive C, the path of the system directory retrieved by this function is C:\WINDOWS\SYSTEM. uSizeSpecifies the maximum size of the buffer, in characters. This value should be set to at least MAX_PATH. Return ValuesIf the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path. If the function fails, the return value is zero. To get extended error information, call GetLastError. ResApplications should not create files in the system directory. If the user is running a shared version of Windows, the application does not have write access to the system directory. Applications should create files only in the directory returned by the GetWindowsDirectory function.
var CDir:String; begin setLength(CDir,144); if GetCurrentDirectory(144,PChar(CDir))<>0 then begin SetLength(CDir,StrLen(PChar(CDir))); ShowMessage(CDir); end else RaiseLasWin32Error; end;
LPTSTR lpBuffer // address of buffer for current directory
);
ParametersnBufferLengthSpecifies the length, in characters, of the buffer for the current directory string. The buffer length must include room for a terminating null character. lpBufferPoints to the buffer for the current directory string. This null-terminated string specifies the absolute path to the current directory. Return ValuesIf the function succeeds, the return value specifies the number of characters written to the buffer, not including the terminating null character.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the buffer pointed to by lpBuffer is not large enough, the return value specifies the required size of the buffer, including the number of bytes necessary for a terminating null character.
UINT uSize // size of directory buffer
);
ParameterslpBufferPoints to the buffer to receive the null-terminated string containing the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named WINDOWS\SYSTEM on drive C, the path of the system directory retrieved by this function is C:\WINDOWS\SYSTEM. uSizeSpecifies the maximum size of the buffer, in characters. This value should be set to at least MAX_PATH. Return ValuesIf the function succeeds, the return value is the length, in characters, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path.
If the function fails, the return value is zero. To get extended error information, call GetLastError. ResApplications should not create files in the system directory. If the user is running a shared version of Windows, the application does not have write access to the system directory. Applications should create files only in the directory returned by the GetWindowsDirectory function.
CDir:String;
begin
setLength(CDir,144);
if GetCurrentDirectory(144,PChar(CDir))<>0 then
begin
SetLength(CDir,StrLen(PChar(CDir)));
ShowMessage(CDir);
end
else
RaiseLasWin32Error;
end;
system单元里面定义的
ParamCount; 参数个数
exefilename := ParamStr[0];