哪位能人能帮忙详细解释下下面几段代码是什么意思,谢谢了!
AnsiString sIniFile = ChangeFileExt(Application->ExeName, ".ini");
TIniFile *pIniFile = new TIniFile(sIniFile);
sCOMPort= pIniFile->ReadString("Global", "port", "");
-----------------------------------------------------
AnsiString sIniFile = ChangeFileExt(Application->ExeName, ".ini");
if (!(FileGetAttr(sIniFile) & faReadOnly) || !FileExists(sIniFile))
{
TIniFile *pIniFile = new TIniFile(sIniFile);
pIniFile->WriteString("Global", "port", sComport);
--------------------------------------------------------
HANDLE hCom = CreateFile("COM1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
---------------------------------------------------------
bWriteStat = WriteFile(hCom,"hello",5,&nLen,NULL);
if (!bWriteStat)
{
MessageBox("通讯失败,请检查串口设置是否正确!","系统提示");
}
C/C++? C++Builder Windows编程
[解决办法]
// 生成一个文件名,和主程序EXE同名,后缀名是.ini
// 比如文件名是D:\\aaa.exe,那么这个sIniFile的值就是D:\\aaa.ini
AnsiString sIniFile = ChangeFileExt(Application->ExeName, ".ini");
// 创建一个TIniFile对象,用来读写Ini文件
TIniFile *pIniFile = new TIniFile(sIniFile);
// 从ini配置文件的Global段内读取port的值
sCOMPort= pIniFile->ReadString("Global", "port", "");
---------------------------------------------------------
AnsiString sIniFile = ChangeFileExt(Application->ExeName, ".ini");
// 如果这个ini文件不是只读或文件不存在
if (!(FileGetAttr(sIniFile) & faReadOnly)
[解决办法]
!FileExists(sIniFile))
{
// 创建一个TIniFile对象读写ini文件
TIniFile *pIniFile = new TIniFile(sIniFile);
// 向这个ini配置文件的Global段内写入端口值
pIniFile->WriteString("Global", "port", sComport);
--------------------------------------------------------
// 打开COM1端口进行写数据
HANDLE hCom = CreateFile("COM1",GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
---------------------------------------------------------
// 向打开的端口中写入hello五个字节
bWriteStat = WriteFile(hCom,"hello",5,&nLen,NULL);
if (!bWriteStat)
{
// 如果写失败,提示用户
MessageBox("通讯失败,请检查串口设置是否正确!","系统提示");
}