求助:在vc++。NET 2005 中读写ini文件
ini文件文件格式:
#【通信制御】
[COM]
#端口号
portno=2000
问题:
GetPrivateProfileInt/GetPrivateProfileString/WritePrivateProfileInt/WritePrivateProfileString
使用的是以上4个函数
1 所需要的头文件是????(在2005 中好像不能够直接使用这些函数)
2 文件格式中#【通信制御】和 #端口号 怎么写进去
3 在2005中,4个函数的参数的数据类型为LPCWSTR 和 LPWSTR
直接 WritePrivateProfileString("COM","portno","2000","路径"); 的话会有错误产生,提示 数据类型不正确
下面是我的代码,我把数据类型进行转换:
TCHAR cPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH,cPath);
String^ strpath = gcnew String(cPath) ;
strpath = strpath + "\\option.ini";
LPWSTR *cget;
if (File::Exists(strpath))
{
GetPrivateProfileString((LPCWSTR)"COM",(LPCWSTR)"portno",(LPCWSTR)"default",*cget,MAX_PATH,cPath);
if(*cget ==(LPWSTR)"default")
{
WritePrivateProfileString(NULL,NULL,NULL,cPath);
WritePrivateProfileString((LPCWSTR)"COM",(LPCWSTR)"portno",(LPCWSTR)"2000",cPath);
this->txtNo->Text = "2000";
MessageBox::Show("222","確認",MessageBoxButtons::OK,MessageBoxIcon::Warning) ;
}else{
String^aa =gcnew String(*cget);
this->txtNo->Text = aa;
}
}else{
File::Create(strpath);
WritePrivateProfileString(LPCWSTR("COM"),LPCWSTR("portno"),LPCWSTR("2000"),cPath);
this->txtNo->Text = "2000";
MessageBox::Show("条坦途","確認",MessageBoxButtons::OK,MessageBoxIcon::Warning);
}
这样本来ini文件里的端口号是数字确读出来一堆乱码填到TXT框里
我听说可以用CString 类,但是在2005里应该怎么调用???
望高手指点,,最好有实现代码,,(包括头文件和引用的类)
还有个问题,要使用CFILE应该用哪个头文件!!!!!!
帮忙啊 !!!!