读写ini

// rwini.h: interface for the Crwini class.
//
//

#if !defined(AFX_RWINI_H__7D3FE520_41BD_41E6_A155_5DE0DE3B4625__INCLUDED_)
#define AFX_RWINI_H__7D3FE520_41BD_41E6_A155_5DE0DE3B4625__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class Crwini  
{
public:
	void WriteInt(char* keyname,char* appname,char *fn,int i);
	void ReadString(char* keyname,char* s,char *fn,char str[]);
	int GetInt(LPCTSTR appname, LPCTSTR kn, char *fn);
	bool WriteString(LPCTSTR appname,LPCTSTR keyname,char* s,char* fn);


	Crwini();
	virtual ~Crwini();

};

#endif // !defined(AFX_RWINI_H__7D3FE520_41BD_41E6_A155_5DE0DE3B4625__INCLUDED_)

 // rwini.cpp: implementation of the Crwini class.
//
//

#include "stdafx.h"
#include <stdlib.h>
#include "rwini.h"

//
// Construction/Destruction
//

Crwini::Crwini()
{

}

Crwini::~Crwini()
{

}

bool Crwini::WriteString(LPCTSTR appname, LPCTSTR keyname,char* s, char *fn)
{
CHAR FilePath[255]; 
    GetModuleFileName(NULL,FilePath,255); 
(strrchr(FilePath,'\\'))[1] = 0; 
   strcat(FilePath,fn);
   //MessageBox(hWnd,FilePath,"a",0);
 WritePrivateProfileString(appname,keyname,s,FilePath);
 return 1;
}

 

 

void Crwini::ReadString(char *key, char *s, char *fn,char str[])
{
 CHAR FilePath[255]; 
    GetModuleFileName(NULL,FilePath,255); 
 (strrchr(FilePath,'\\'))[1] = 0; 
 strcat(FilePath,fn);
 
 ::GetPrivateProfileString(key,s,NULL,str,255,FilePath);
 
 
}

void Crwini::WriteInt(char *keyname, char *appname, char *fn, int i)
{CHAR FilePath[255]; 
    GetModuleFileName(NULL,FilePath,255); 
 (strrchr(FilePath,'\\'))[1] = 0; 
 strcat(FilePath,fn);
 char r[10];
 _itoa(i,r,10);
WritePrivateProfileString(appname,keyname,r,FilePath);
}
int Crwini::GetInt(LPCTSTR appname, LPCTSTR keyname, char *fn)
{
CHAR FilePath[255]; 
    GetModuleFileName(NULL,FilePath,255); 
(strrchr(FilePath,'\\'))[1] = 0; 
   strcat(FilePath,fn);
   //MessageBox(hWnd,FilePath,"a",0);
   return GetPrivateProfileInt(appname,keyname,1,FilePath);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值