为什么返回值总是0呢?

captain9293 2005-11-25 11:26:36
这是个读写配置文件的问题,我所使用的类见:http://dev.csdn.net/develop/article/46/46139.shtm
但是我在使用的时候发现是用到dwRetValue = GetPrivateProfileString(
(LPCTSTR)strSection,
NULL,
_T(""),
chSection,
sizeof(chSection)/sizeof(TCHAR),
(LPCTSTR)m_strPath);
的地方返回的值都是0,并且GetPrivateProfileString()的地方返回的值都是0,怎么都不会改变,这是怎么回事呢?
我用的配置文件如下:
[student]
number=40
male=25
female=15
average_age=15

[computer]
cpu=2.0
motherboard=ASUS
harddisk=120
ram=512
display=sansung
...全文
204 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
captain9293 2005-11-26
  • 打赏
  • 举报
回复
哦,知道了,谢谢大家.
captain9293 2005-11-25
  • 打赏
  • 举报
回复
哈哈,又是鹦鹉
strSection是SectionExist(CString strSection)的参数,表示的是ini文件里的结点名称,就是我上面的student和computer,我在程序里调用的时候是用 file.SectionExist("computer") file是我定义的对象
快乐鹦鹉 2005-11-25
  • 打赏
  • 举报
回复
GetPrivateProfileString(
(LPCTSTR)strSection,
NULL,
_T(""),
chSection,
sizeof(chSection)/sizeof(TCHAR),
(LPCTSTR)m_strPath);
那么,这里的strSection是什么呢?你应该说明你传递的参数都是什么阿。而且要经过调试,确认这些参数是否正确。
fine10000 2005-11-25
  • 打赏
  • 举报
回复
Return Values
The return value is the number of characters copied to the buffer, not including the terminating null character.

If neither lpAppName nor lpKeyName is NULL and the supplied destination buffer is too small to hold the requested string, the string is truncated and followed by a null character, and the return value is equal to nSize minus one.

If either lpAppName or lpKeyName is NULL and the supplied destination buffer is too small to hold all the strings, the last string is truncated and followed by two null characters. In this case, the return value is equal to nSize minus two.
zkxz 2005-11-25
  • 打赏
  • 举报
回复
GetPrivateProfileString函数要求INI文件的路径是绝对路径,不知楼主有否设置正确?
oyljerry 2005-11-25
  • 打赏
  • 举报
回复
调试一下,看内存中是否正确
alen_ghl 2005-11-25
  • 打赏
  • 举报
回复
以前也碰到过一次
后来稀里糊涂给解决了
好像是ini文件路径给写错了

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧