SPDL--Shgetfileinfo

Source: Internet
Author: User

This article from a few methods to introduce:
  • definition of Shgetfileinfo
  • Shgetfileinfo () How the function works
  • The return value of the shgetfileinfo () function
  • A simple example of the shgetfileinfo () function

definition of shgetfileinfo

Shgetfileinfo is defined on MSDN as:

retrieves information about a object in the file system,

    1. such as a file, folder, directory, or drive root.

It is defined in shellapi.h . This function has five variables, which are defined as follows:

Dword_ptr Shgetfileinfo (
__in LPCTSTR Pszpath, DWORD dwfileattributes, __inout shfileinfo *PSFI,
UINT Cbfileinfo,
UINT uflags
);

Basically, the Shgetfileinfo () function provides information about the file system object. As explained earlier, this object can be a file, folder, directory, or drive root. The return of a DWORD means that there may be quite a number of return states, which are related to the setting of the uflags variable. To put it simply, using this function, you can expect:

    1. Determine the target platform (Win32,win16,ms-dos) of the executable file
    2. Get a variety of featured file icons (small, large, related overlapping, selected, open)
    3. Read other display properties, such as file type (a short description displayed on the Probe Type column) and display name (appearing on the Name column)
    4. read out any other properties that can be file-specific, such as whether it can be copied, moved, deleted or renamed, whether it can form a shortcut, whether it has subfolders, whether it is shared, is a drag target, or has an attached property page, and so on.
     Note:It should be noted that before calling Shgetfileinfo (), COM must be initialized with CoInitialize or oleinitialize, otherwise it can be used on the surface, but will cause unsafe or partial loss of functionality. how the shgetfileinfo () function works

in order to correctly understand the functions that a function has, it is necessary to force the invocation of this function using all possible methods. First, let's take a look at the variables he requires:

Variable name

Describe

Pszpath

A buffer that contains the relative or absolute path of the file to get information. It can handle long or short filenames. (That is, the specified file path) Note [1]

dwFileAttributes

The data stated that this parameter is only used in cases where the Shgfi_usefileattributes flag is included in the uflags (generally not used). So, it should be a combination of file attributes: Archive, read-only, directory, system, etc.

Psfi

A pointer to a SHFILEINFO structure that receives data. Note [2]

Cbfileinfo

Simply give the size of the upper structure.

Uflags

The core variables of the function, through all possible flags, you can harness the behavior of the function and actually get the information.

Note [1]: when the value of Uflags does not include shgfi_pidl, it can be specified directly;

when the value of Uflags contains shgfi_pidl Pszpath to be obtained by calculation, can not be directly specified;

Uflags parameter: Indicates the file information identifier that needs to be returned, often with the following constants:
Shgfi_icon; Get icon
Shgfi_displayname; Get Display Name
Shgfi_typename; Get type name
Shgfi_attributes; Get Properties
Shgfi_largeicon; Get Large Icons
Shgfi_smallicon; Get Small Icons
Shgfi_pidl; Pszpath is an identifier
The return value of the function shgetfileinfo () also varies depending on the value of the uflags.

Visible by calling Shgetfileinfo () the icon handle of the file can be obtained by the PSFI parameter. Note, however, that shgetfileinfo () cannot get information like a virtual folder such as My computer when SHGFI_PIDL is not used in the Uflags parameter.

Note [2]: The shfileinfo structure is defined as follows:

typedef struct _shfileinfo {

Hicon  Hicon; Icon handle for file

int  Iicon; System index number of the icon

DWORD  dwattributes; Property value of the file

TCHAR Szdisplayname[max_path];//The display name of the file

TCHAR  sztypename[80]; Type name of the file

} Shfileinfo;

In addition, this structure is always used to return data to the calling program, and it never needs to be initialized. The only thing that can contain information to affect function behavior is the Dwattributes member, which is further explained later. Obviously, all interest in the various behaviors using the Shgetfileinfo () function is focused on setting the value of the uflags variable. In most cases, the information is returned through the PSFI buffer, but there are some cases that can be effectively included in the DWORD return of the function. The return value of the shgetfileinfo () function

Returns A value whose meaning depends on the uflags parameter.
    1. If uflags contains the SHGFI_EXETYPE flag, the return value specifies
    2. The type of the executable file. It would be one of the following values:
Value Executable File Type
0 nonexecutable file or an error condition
LoWord = NE or PE and HiWord = 3.0, 3.5, or 4.0 Windows Application
LoWord = MZ and HiWord = 0 MS-DOS. exe,. com, or. bat file
LoWord = PE and HiWord = 0 Win32 Console Application

If the function returns 0, an error occurs somewhere. In most cases, an unreasonable file name or PIDLis passed, or a conflicting combination of flags is specified. The latter is more likely than the first two. This function returns 1 unless the specified flag tells it to do the specified action, and if each operation is completed successfully . One exception is when the SHGFI_EXETYPE flag is set,

Shgetfileinfo () returns the DWORD value, at which point the low word represents the signature of the executable file, as explained in the following table:

File signature

Hex Code

Significance

PE

0x4550

Win32 executable format, adopted by all Microsoft OS.

NE

0x454e

Windows 3.x new executable format, typically in a Windows program

Mz

0x5a4d

DOS executable format, if queried. com or . bat also returns this value.

The corresponding Hex code is actually the character code of the file signature column. For example 0x50 corresponds to P ,0x45 corresponds to E and so on. The two bytes of the high word contain the minimum operating system version number required for the operation.

Another case in which the return code contains more meaning is that the SHGFI_SYSICONINDEX flag is set. At this point, the function returns a system image list handle that contains the icon for the specified file or folder.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

SPDL--Shgetfileinfo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.