VC + + Basic class []---system access to various path information

Source: Internet
Author: User

VC + + Basic class []---system access to various path information------------------------------------------Begin-------------------------------------- -- ①, Windows, System32, TEMP and other directories get: TCHAR Szpath[max_path] = {0}; GetSystemDirectory (szpath, MAX_PATH); C:\WINDOWS\system32GetWindowsDirectory (szpath, MAX_PATH); C:\WINDOWSGetTempPath (MAX_PATH, szpath); C:\docume~1\syc\locals~1\temp\ ②, Desktop directory, My Documents and other directories get: Super-strong directory Get function: SHGetSpecialFolderPath, he is the shell API, specific explanation see msdn;/ /Get Desktop path: TCHAR Szpath[max_path] = {0}; SHGetSpecialFolderPath (M_hwnd, szpath, Csidl_desktop, FALSE); MessageBox (szpath);  //get my document path: SHGetSpecialFolderPath (M_hwnd, szpath, Csidl_personal, FALSE);  other CSIDL The value of:  csidl_flag_create ($8000)     Windows 2000: If the folder referenced by this CSIDL does not exist, create this folder!.    csidl_flag_dont_verify ($4000)     WINDOWS 2000: Use it regardless of whether the folder referenced by this CSIDL is present!   Csidl_ AdminTools     Represents the current user's Administrative Tools system folder   Csidl_appdata ($1a)     represents the specific application data store folder for the current user, for example, C: \ Documents and Settings\username\application data  Csidl_bitbucket ($A)     means Recycle Bin   Csidl_common_admintools ($2f)     means "Administrative tools for all users" System folders   Csidl_common_altstartup ($1d)     for all users (Windows NT system only)   Csidl_common_appdata ($23)     represents a specific application data store folder for all users, for example: C:\Documents and Settings\All Users\Application data  Csidl_common_ Desktopdirectory ($19)     represents the "desktop" folder for all users, for example: C:\Documents and Settings\All Users\Desktop.   Csidl_common_documents ($2e)     represents the My Documents folder for all users, for example: C:\Documents and Settings\All Users\Documents   Csidl_common_favorites ($1f)     represents the My Favorites folder for all users.   Csidl_common_programs ($17)     represents all users ' Programs folder, for example: C:\Documents and Settings\All Users\Start Menu\ programs  Csidl_common_startmenu ($16)     Represents the Start Menu folder for all users, for example: C:\Documents and Settings\All Users\ Start menu  Csidl_common_startup ($18)     represents the Startup folder for all users, for example: C:\Documents and Settings\All Users\Start menu\programs\startup  Csidl_common_teMplates ($2d)     represents the "modules" folder for all users, for example: C:\Documents and Settings\All users\templates  Csidl_controls ($ $)     represents the Control Panel folder   Csidl_cookies ($21)     represents the cookie folder for the current user's Internet Explorer, for example: C:\Documents and settings\username\cookies  Csidl_desktop ($)     represents the desktop virtual folder, which contains all the contents of the computer   Csidl_ Desktopdirectory ($ $)     represents the current user's desktop folder, for example: C:\Documents and settings\username\desktop  csidl_drives ( $11)     represents the "My Computer" virtual folder, which contains all the drives in the computer   csidl_favorites ($6)     represents the current user's Favorites folder, for example, C: \ Documents and settings\username\favorites  csidl_fonts ($14)     represents the system Fonts folder, such as:c:\winnt\fonts  Csidl_history ($22)     represents inernet Explorer's History folder   Csidl_internet ($)     Represents this virtual folder for the Internet   Csidl_internet_cache     represents the "CACHE" folder for the current user's Internet Explorer, for example, C: \ Documents and Settings\username\temporary Internet files  csidl_local_appdata ($1c)     represents the current user's Application Data folder , for example: C:\DoCuments and Settings\username\Local Settings\Application data  csidl_mymusic    represents the folder where the current user stores music files, for example: C : \documents and Settings\User\My Documents\My music  csidl_mypictures ($27)     represents the folder where the current user stores image files, for example, C: \ Documents and Settings\UserName\My Documents\My pictures  Csidl_nethood ($13)     folders that represent network connections that exist for the current user, for example: C : \documents and settings\username\nethood  Csidl_network ($)     means "My Network Places" This virtual folder   Csidl_personal     represents the current user's My Documents folder, for example: C:\Documents and Settings\UserName\My documents  csidl_printers ($4)     Point to "printer" This virtual folder   Csidl_printhood ($1b)     The virtual folder that represents the network printer that the current user exists for, such as: C:\Documents and Settings\ username\printhood  Csidl_profile ($28)     represents the current folder with user Profiles   Csidl_program_files ($26)     The folder that represents the program files, for example: C:\Program files  Csidl_program_files_common ($2b)     indicates that the System program shared Components folder, for example, C: \ Program files\common  Csidl_programs ($)     represents the current user's Programs menu folder, for example: C:\DocumEnts and Settings\username\start menu\programs  csidl_recent ($8)     Represents the Document menu folder for the current user, for example: C:\Documents and Settings\username\start menu\programs  csidl_sendto ($9)     represents the "Send to" folder for the current user, for example: C:\Documents and settings\username\sendto  Csidl_startmenu ($B)     Represents the Start Menu folder for the current user, for example: C:\Documents and Settings\ Username\start menu  Csidl_startup ($7)     Represents the Startup Menu folder for the current user, for example: C:\Documents and Settings\username\ Start menu\programs\startup  Csidl_system     represents a system folder for Windows systems, such as:c:\winnt\system32  CSIDL _templates     Represents the folder in the system where the document module is stored   csidl_windows ($24)     represents the file of the WINDOWS directory in the system Jane, for example, C: \ Winnt ③, getting and setting the current directory of the application and the problem: getting the current directory of the current process: GetCurrentDirectory sets the current directory for the current process: setcurrentdirectory※※※ Note: Just get or set the current directory of the current process, not the directory where the process's image file (. exe) resides! So, here to remind you, although in general by default, the current EXE directory is the same as the EXE process's current directory, but it is best not to use the GetCurrentDirectory function to get the current EXE directory, there are potential problems, such as: TCHAR szpath [MAX_PATH] = {0}; GetCurrentDirectory (MAX_PATH, szpath); MessageBox (szpath);  cfiledialog dlg (FALSE);d Lg. DoModal ();  getcurrentdirectory (MAX_PATH, szpath); MessageBox (szpath);  ④, executable directory [includes EXE and Dll];dword getcurrentfolder (DWORD nbufferlength, LPTSTR lpbuffer) {  dword Dwret = 0; cstring strpath; getmodulefilename (AfxGetInstanceHandle (), Strpath.getbuffersetlength (MAX_PATH), MAX_PATH);  strpath.releasebuffer ();   int idx = Strpath.reversefind (' \ \ ');  if (idx >= 0) {  strpath = strpath.left (idx);  } else {  return 0;  }  dwret = Strpath.getlength ();  _tcsncpy_s (lpbuffer, Nbufferlength, strpath, dwRet);  dwRet = ( Nbufferlength >= dwret)? Dwret:nbufferlength;  return Dwret;}  ⑤, the project current directory and debug debug directory different: The VC Start Program and mouse double-click Start Program, observe the call getcurrentdirectory function to obtain the results of the difference! So: Sometimes you will be prompted not to find the DLL and other errors!  ⑥⑦⑧⑨⑩ System Information Acquisition    ①, current user name, computer name acquisition;   ②, CPU, memory, hard disk information acquisition. ★-------------------------------------End-------------------------------------------

VC + + Basic class []---system access to various path information

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.