16,466
社区成员
发帖
与我相关
我的任务
分享
C++
DWORD WINAPI GetPrivateProfileString(
_In_ LPCTSTR lpAppName,
_In_ LPCTSTR lpKeyName,
_In_ LPCTSTR lpDefault,
_Out_ LPTSTR lpReturnedString,
_In_ DWORD nSize,
_In_ LPCTSTR lpFileName
);
CXXXXApp::InitInstance()
{
……
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
{
//SetRegistryKey(_T("Local AppWizard-Generated Applications"));
//First free the string allocated by MFC at CWinApp startup.
//The string is allocated before InitInstance is called.
free((void*)m_pszProfileName);
//Change the name of the .INI file.
//The CWinApp destructor will free the memory.
m_pszProfileName=_tcsdup(_T("d:\\somedir\\myini.ini"));
}
……
剩下的 就正常用了
AfxGetApp()->GetProfileXXXX
AfxGetApp()->WriteProfileXXXX
char s[20] = { 0 };
GetPrivateProfileStringA("MySection", "Close", "0", s, sizeof(s), "D:\\abc.txt");//读取ini的MySection节的Close字段的值到s字符串中,如果没有读取到值,则设置默认值为"0"
[sectoin1] //AppName
xxx = ... //KeyName
yyy = ....//KeyName
GetPrivateProfileString函数中AppName,KeyName两个参数都可以设置为NULL,不清楚你指的是哪一个参数。
这两个参数为NULL时如何处理,可以再仔细看下MSDN。
可以参考下面这篇文章(实现了一个读写INI文件的类)
https://vcpptips.wordpress.com/tag/getprivateprofilestring/