Configure file like format of ini and read data from ini file or write data to ini file

本文介绍如何利用Win32 API中的函数来读取和写入配置文件,确保应用程序数据即使在内存释放后也能持久保存。通过具体代码示例展示了如何将登录信息和语言设置等数据存储到INI文件中。

    Sometimes,It's not that always store data in memory, you should store data to disk file,  because you release memory and destroy address of data  that

allocated to data previously when main thread procedure is destroyed.The data will be lost in memeroy.But you will use data that store in memory previously to do something.so what are you gonna do? here,I give you a method to store data to configure file as following description.

   First,Let me have a look format of ini file as soon as possible. 

     [section]

       key = value

     .........

     ; comment

  and then,how to use configure file to store data,please look the following win-32 main functions:

  

 BOOL WritePrivateProfileString(
  LPCTSTR lpAppName,   // section name
  LPCTSTR lpKeyName,   // key name
  LPCTSTR lpString,         // string to add
  LPCTSTR lpFileName     // initialization file
);

 DWORD GetPrivateProfileString(
  LPCTSTR lpAppName,        // section name
  LPCTSTR lpKeyName,        // key name
  LPCTSTR lpDefault,        // default string
  LPTSTR lpReturnedString,  // destination buffer
  DWORD nSize,              // size of destination buffer
  LPCTSTR lpFileName        // initialization file name
);

 

UINT GetPrivateProfileInt(
  LPCTSTR lpAppName,  // section name
  LPCTSTR lpKeyName,  // key name
  INT nDefault,       // return value if key name not found
  LPCTSTR lpFileName  // initialization file name
);

 

My code:

 

void CLoginDemoDlg::OnBnClickedConfirm()
{
 // TODO: Add your control notification handler code here
 m_UserID.GetWindowText(m_UserName);
 ::WritePrivateProfileString(_T("LoginInfo"),_T("UserID"),//将登录信息写入配置文件
  m_UserName,ConfigurePath+_T("LoginInfo.ini"));

}

    void CLoginDemoDlg::AddLanguageString()
{
 CString strTemp;
 CString nStr;
 CString SelString[3];
 int nCount = 3;
 SelString[0] = _T("简体中文");
 SelString[1] = _T("繁体中文");
 SelString[2] = _T("English");
 for (int i=0; i<3;i++)
 {
  strTemp.Format(_T("%d"),i);
  ::WritePrivateProfileString(_T("LanguageInfo"),_T("Language")+strTemp,
  SelString[i],ConfigurePath + _T("LanguageSel.ini"));
 }
 nStr.Format(_T("%d"),nCount);
 ::WritePrivateProfileString(_T("CountInfo"),_T("Count"),nStr,
  ConfigurePath + _T("LanguageSel.ini"));

}
void CLoginDemoDlg::GetLanguageFile()                                           

{
 CString buffer;
 CString nStr;
 int nIndex;
 nIndex = ::GetPrivateProfileInt(_T("CountInfo"),_T("Count"),0,
  ConfigurePath + _T("LanguageSel.ini"));
 for (int i=0; i<nIndex; i++)
 {
  nStr.Format(_T("%d"),i);
  ::GetPrivateProfileString(_T("LanguageInfo"),_T("Language")+nStr,NULL,
   buffer.GetBuffer(1024),1024,ConfigurePath + _T("LanguageSel.ini"));
  m_Language.AddString(buffer);
  buffer.ReleaseBuffer();
 }
 m_Language.SetCurSel(0);

}

void CLoginDemoDlg::GetLoginFromFile()
{
 CString  strTemp;
 int nIndex = 0;
 ::GetPrivateProfileString(_T("LoginInfo"),_T("UserID"),
  NULL,strTemp.GetBuffer(1024),1024,ConfigurePath + _T("LoginInfo.ini"));
 nIndex = m_UserID.AddString(strTemp);
 m_UserID.SetCurSel(nIndex);
 strTemp.ReleaseBuffer();
}

出现错误: ``` bash: ./configure: No such file or directory ``` 说明你当前所在的目录中 **没有 `configure` 文件**,也就是说你还没有准备好 PHP 的源码编译环境。 --- ### 🔍 原因分析 这个错误通常发生在你尝试编译安装 PHP 时,但你没有正确下载 PHP 的源码包,或者你误入了其他目录(比如你进入了 `curl` 的源码目录,却试图运行 PHP 的 `./configure`)。 --- ### ✅ 正确流程:从源码编译 PHP #### ✅ 1. 下载 PHP 源码包 你可以从 [PHP 官网](https://www.php.net/downloads) 下载你需要的版本,例如: ```bash cd /usr/src wget https://www.php.net/distributions/php-8.2.24.tar.gz tar -zxvf php-8.2.24.tar.gz cd php-8.2.24 ``` 此时你才进入 PHP 源码目录,才能看到 `configure` 文件。 ```bash ls -l configure ``` 输出应类似: ``` -rwxr-xr-x 1 root root 654321 Oct 1 10:00 configure ``` --- #### ✅ 2. 安装编译依赖(以 CentOS 为例) ```bash yum groupinstall "Development Tools" -y yum install libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel libmcrypt-devel oniguruma-devel -y ``` --- #### ✅ 3. 运行 `./configure` 确保你已经进入 PHP 源码目录,然后运行配置脚本: ```bash ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc/php \ --enable-fpm \ --with-fpm-user=nginx \ --with-fpm-group=nginx \ --enable-mbstring \ --enable-zip \ --enable-bcmath \ --enable-pcntl \ --enable-ftp \ --enable-exif \ --enable-calendar \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --with-curl=/usr/local/curl \ --with-zlib \ --with-openssl \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-gd \ --with-jpeg \ --with-freetype ``` > ⚠️ 注意:上面的 `--with-curl=/usr/local/curl` 是你之前手动编译安装的 `curl 8.15.0` 的路径。 --- #### ✅ 4. 编译并安装 ```bash make && make install ``` 这将编译并安装 PHP 到 `/usr/local/php`。 --- #### ✅ 5. 配置 PHP-FPM 复制默认配置文件: ```bash cp php.ini-production /etc/php/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf ``` 启动 PHP-FPM: ```bash /usr/local/php/sbin/php-fpm ``` --- ### 🧠 小结 | 操作 | 目的 | |------|------| | 下载 PHP 源码 | 获取 `configure` 文件 | | 安装依赖 | 确保编译环境完整 | | 使用 `./configure` | 配置编译参数 | | 指定 `--with-curl` | 强制 PHP 使用新版本的 cURL | | 编译安装 | 生成新的 PHP 二进制文件 | --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值