gpt4 book ai didi

windows - CGI DLL(Delphi内置)物理路径

转载 作者:可可西里 更新时间:2023-11-01 09:34:50 26 4
gpt4 key购买 nike

我在 Windows 2008 服务器上部署了一个使用 Delphi 2007 构建的 CGI DLL。在内部我需要使用当前的 DLL 路径。

通常我可以使用 GetModuleFileNameGetModuleName,但在服务器上它们都返回:

\\?\c:\my\correct\path

为什么是前 4 个字符?它看起来像一个网络路径?有什么方法可以排除前 4 个字符吗?

最佳答案

相关documentation这是:

Maximum Path Length Limitation

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

Note File I/O functions in the Windows API convert "/" to "\" as part of converting the name to an NT-style name, except when using the "\\?\" prefix as detailed in the following sections.

The Windows API has many functions that also have Unicode versions to permit an extended-length path for a maximum total path length of 32,767 characters. This type of path is composed of components separated by backslashes, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function (this value is commonly 255 characters). To specify an extended-length path, use the "\\?\" prefix. For example, "\\?\D:\very long path".

Note The maximum path of 32,767 characters is approximate, because the "\\?\" prefix may be expanded to a longer string by the system at run time, and this expansion applies to the total length.

The "\\?\" prefix can also be used with paths constructed according to the universal naming convention (UNC). To specify such a path using UNC, use the "\\?\UNC\" prefix. For example, "\\?\UNC\server\share", where "server" is the name of the computer and "share" is the name of the shared folder. These prefixes are not used as part of the path itself. They indicate that the path should be passed to the system with minimal modification, which means that you cannot use forward slashes to represent path separators, or a period to represent the current directory, or double dots to represent the parent directory. Because you cannot use the "\\?\" prefix with a relative path, relative paths are always limited to a total of MAX_PATH characters.

只要您调用的是 Unicode 版本的 Windows API 函数,就没有必要去掉 "\\?\" 前缀。因为交给你的路径是一条有效的路径。

正如我们在评论中发现的那样,您正在调用 API 函数的 ANSI 版本。当您这样做时,"\\?\" 前缀无效。所以,坚持使用 Unicode API 函数,一切都很好!

关于windows - CGI DLL(Delphi内置)物理路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573712/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com