// rwini.cpp: implementation of the CIniEditor class.
//
//////////////////////////////////////////////////////////////////////
#include "windows.h"
//#include "stdafx.h"
#include <stdlib.h>
#include "inieditor.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIniEditor::CIniEditor(WCHAR *filename)
{
//WCHAR FilePath[255];
GetModuleFileName(GetModuleHandle(DLL_MODULENAME),m_filename,255);
(wcsrchr(m_filename,'\\'))[1] = 0;
wcscat(m_filename,filename);
}
CIniEditor::CIniEditor()
{
}
CIniEditor::~CIniEditor()
{
}
//写整型
void CIniEditor::WriteInt(WCHAR *appname, WCHAR *keyname, int i) //fn = file name
{
WCHAR r[10];
_itow(i,r,10);
WritePrivateProfileString(appname,keyname,r,m_filename);
}
//写字符串
bool CIniEditor::WriteString(LPCTSTR appname,LPCTSTR keyname,WCHAR* s)
{
WritePrivateProfileString(appname,keyname,s,m_filename);
return 1;
}
//读字符串
void CIniEditor::ReadString(WCHAR* appname,WCHAR* keyname, WCHAR str[])
{
::GetPrivateProfileString(appname,keyname,NULL,str,255,m_filename);
}
//读整型
int CIniEditor::GetInt(LPCTSTR appname, LPCTSTR keyname)
{
return GetPrivateProfileInt(appname,keyname,1,m_filename);
}
//写字符串
bool CIniEditor::WriteStringW(LPCTSTR appname, LPCTSTR keyname,WCHAR* s, WCHAR *fn)
{
WCHAR FilePath[255];
GetModuleFileName(NULL,FilePath,255);
(wcsrchr(FilePath,'\\'))[1] = 0;
wcscat(FilePath,fn);
//MessageBox(hWnd,FilePath,"a",0);
WritePrivateProfileString(appname,keyname,s,FilePath);
return 1;
}
int CIniEditor::GetIntW(LPCTSTR appname, LPCTSTR keyname, WCHAR *fn)
{
WCHAR FilePath[255];
GetModuleFileName(NULL,FilePath,255);
(wcsrchr(FilePath,'\\'))[1] = 0;
wcscat(FilePath,fn);
//MessageBox(hWnd,FilePath,"a",0);
return GetPrivateProfileInt(appname,keyname,1,FilePath);
}
void CIniEditor::ReadStringW(WCHAR *appname, WCHAR *keyname, WCHAR *fn,WCHAR str[])
{
WCHAR FilePath[255];
GetModuleFileName(NULL,FilePath,255);
(wcsrchr(FilePath,'\\'))[1] = 0;
wcscat(FilePath,fn);
::GetPrivateProfileString(appname,keyname,NULL,str,255,FilePath);
}
void CIniEditor::WriteIntW(WCHAR *appname, WCHAR *keyname, WCHAR *fn, int i)
{WCHAR FilePath[255];
GetModuleFileName(NULL,FilePath,255);
(wcsrchr(FilePath,'\\'))[1] = 0;
wcscat(FilePath,fn);
WCHAR r[10];
_itow(i,r,10);
WritePrivateProfileString(appname,keyname,r,FilePath);
}