"Display name" can only be used for "display"

Source: Internet
Author: User

Ight: pixel PX; width: 100%; ">

Many functions return strings called "display names. The only thing you can do with these display names is to display them. Do not assume that these strings have any practical significance, because they do not make sense.

Theoretically, a function similar to shgetfileinfo can be implemented as follows:

...
If (uflags & shgfi_displayname ){
Stringcchcopy (psfi-> szdisplayname, max_path, text ("booga! "));
}
...

 

Your program should still run normally.

(Of course, this is just a basic principle. Some specific functions may have exceptions. For example, the ishellfolder: getdisplaynameof call with the shgdn_forparsing flag explicitly indicates that the returned string is designed for program parsing purposes .)

"Display name" is used as a string suitable for display to users. For example, the file display name may be a file name, or remove the suffix, or even be translated into your preferred language! For example, if you try to obtain the display name of C:/Documents ents and settings/Raymond/My Documents ents on an English system that has installed and activated the German Language Pack, you will get eigene dateien, this is the name of my documents in German.

If your program assumes that the display name of C:/Documents and Settings/Raymond/my documents is "My documents, when it is run by me, it will encounter a big accident.

One of my colleagues once looked for bugs that cannot run a program. Although the CD-ROM is in the drive, this program still complained that the CD-Rom could not be found. Why can't this program find the CD-ROM it wants?

After several days of research, the colleague found the cause of the problem. The program needs to find its CD-ROM, so it traverses all 26 drive letters and passes the shgfi_displayname flag like below to call shgetfileinfo:

// The actual code is far more confusing than the code given here
Char lookforcd (lpctstr pszvolumelabel)
{
For (tchar chdrive = text ('A'); chdrive <= text ('Z'); chdrive ++ ){
Tchar szrot [4];
Wsprintf (szrot, text ("% C:/"), chdrive );

Shfileinfo SFI;
If (shgetfileinfo (szrot, 0, & SFI, sizeof (SFI), shgfi_displayname )){
Tchar szexpected [max_path];
Wsprintf (szexpected, text ("% s (% C :)"), pszvolumelabel, chdrive );

If (strcmp (szexpected, SFI. szdisplayname) = 0 ){
Return chdrive; // found
}
}
}
Return 0; // not found
}

 

The program queries the display name of each drive and tries to find a drive named "label (d. Here the label is the expected volume label, and D is the drive letter.

In other words, they are trying to understand the display name.

Do not do similar things. There is no guarantee that the display name of a CD-ROM must be a specific form. In Windows XP, the default format is "label (d :)", but there are a variety of system policies that can be changed, any of these policies for the first time, this program will not find the CD-ROM it wants and refuse to work.

(In fact, the correct way to do this is to pass each drive letter to the getdrivetype function to determine whether the drive is a drive_cdrom; for each such drive, get the CD-ROM's volume tag by calling getvolumeinformation)

Therefore, keep in mind that the display name is only used for display purposes.

 

Source: http://blogs.msdn.com/oldnewthing/archive/2007/03/13/1868542.aspx

 

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.