The problem that happened to be discovered today is that the Win32 program installed in the C-Drive programs files (x86) folder will produce an exception, and the program can be run perfectly even if it is installed in a different folder (x86).
This, of course, is a matter of authority. When this software runs, it needs to read and write the database, as well as various cache data.
This is a hole I dug for myself, I believe many people will encounter this problem.
That is, when developing programs, VS debugging, you always prefer to use the current path, or a relative path. That is to put some data together with the. exe file.
However, when the installation, the choice is the C-disk program Files (x86) folder, then it means that the database, as well as all kinds of cache data read and write in the folder Program Files (x86), so that there is a time to generate permissions problems.
Calm down and meditate a bit. Look at QQ, even if the QQ installed in the Program Files (x86) folder, you will find that "documents" (XP is "My Documents") will produce a Tencent Files folder, for storing various data.
We know that there is no need for permission to read and write content under "documents."
This guides us in the presence of a cache file such as a database, preferably under "documents."
Then the question is, how do you get the Documents folder in your program?
Use the function SHGetFolderPath:
STD: : wstring getdocumentspath () {tchar My_documents[max_path ]; hresult result = shgetfolderpath (null , csidl_personal , NULL , shgfp_type_current , my_documents); return STD: :wstring (my_documents);}
HRESULT SHGetFolderPath (
HWND hWndOwner,
int Nfolder,
HANDLE Htoken,
DWORD DwFlags,
LPTSTR Pszpath
);
The above is a function prototype, where nfolder specifies the directory to get (refer to the MSDN Note for details)
Csidl_bitbucket Recycling Station
Csidl_controls Control Panel
Csidl_desktop Windows Desktop Desk Desktop
Directory of Csidl_desktopdirectory Desktop
Csidl_drives My Computer.
Csidl_fonts Font Directory
Csidl_nethood Network Neighborhood
Csidl_network Network Places virtual directory
csidl_personal My Documents
Csidl_printers Printer
Csidl_programs program Group
Csidl_recent recently opened documents
Csidl_sendto "Send to" menu item
Csidl_startmenu task bar Start menu item
Csidl_startup Startup directory
Csidl_templates Document Templates
No escaping pits--the software you developed is installed under C-Drive program Files (x86) to produce exceptions