c++写配置⽂件1. 类定义
// ini.h: interface for the Cini class.
#if !defined(AFX_INI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
#define AFX_INI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_
#if _MSC_VER > 1000
#pragma once
//#include <afxwin.h>
class __declspec(dllexport)Cini
{
public:
static DWORD ReadString (char *section, char * key, char* stringtoread , char * filename);
static BOOL WriteString(LPCTSTR section, LPCTSTR key,char* stringtoadd, char *filename);
Cini();
virtual ~Cini();
};
#endif // !defined(AFX_OPINI_H__CE3F8B7B_1ACA_46CC_A91C_F8E23FA9B063__INCLUDED_)
1. 类实现
// ini.cpp: implementation of the Cini class.
#include "stdafx.h"下雨天的心情经典句子
苏q是江苏省哪里的车牌#include "ini.h"
//#include "vld.h"
女儿生日简短朋友圈/
//Cini类的构造函数和析构函数
Cini::Cini()
{
}
Cini::~Cini()
{
}
/
//写字符串到INI⽂件,GetLastError()函数⽤于返回写⼊失败
void error(LPSTR lpszFunction)
{
CHAR szBuf [80] ;
DWORD dw = GetLastError();
sprintf_s(szBuf, 80, "%s failed: GetLastError returned %u\n",lpszFunction, dw);
MessageBox(NULL, szBuf, "Error", MB_OK);
ExitProcess(dw);
}
BOOL Cini::WriteString(LPCTSTR section, LPCTSTR key, char *stringtoadd, char *filename) {
CHAR FilePath[255];
memset(FilePath, 0 ,255);
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
::GetModuleFileName(hModule,FilePath,255);
//GetProccessImageFileName(PROCESS_QUERY_INFORMATION ,FilePath,255);
(strrchr(FilePath,'\\'))[1] = 0;
strcat(FilePath,filename);
}
return ::WritePrivateProfileString(section,key,stringtoadd,FilePath);邓伦金晨是做完后出来的吗
}
/
//从INI⽂件中读取字符串
DWORD Cini::ReadString(char *section, char * key, char* stringtoread , char * filename) {
百家姓人口排名
CHAR FilePath[255];
memset(FilePath, 0 ,255);
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL)
{
::GetModuleFileName(hModule,FilePath,255);
//GetProccessImageFileName(PROCESS_QUERY_INFORMATION ,FilePath,255);
(strrchr(FilePath,'\\'))[1] = 0;
strcat(FilePath,filename);
}
return ::GetPrivateProfileString(section, key,NULL,stringtoread,255,FilePath);
}
发布评论