#include <windows.h>
#include <stdio.h>
#include <string.h>
#define WOM_WOMCLTMD_INI "E://work//vctest//testmjong//womcltmd.ini"
int main(void)
{
unsigned int func_rtn;
char StrBuf[256];
char work[256];
memset(StrBuf, '/0', sizeof(StrBuf));
memset(work, '/0', sizeof(work));
memcpy(work,"Can not fined",15);
func_rtn = GetPrivateProfileInt(
"womcltmd",
"daikou_second",
0,
WOM_WOMCLTMD_INI);
printf("func_rtn = %d/nwork = %s/nStrBuf = %s/n",func_rtn,work,StrBuf);
return 0;
}
需要注意的地方:
1. 要是全路径
2.可以通过GetCurrentDirectory()函数来配合使用,我上面只是提供一个例子来测试下,大家若是需要可以做修改。
3.另外大家如果要从配置文件中获得字符串,可以用这个函数GetPrivateProfileString
GetPrivateProfileString
The GetPrivateProfileString function retrieves a string from the specified section in an initialization file.
Note This function is provided only for compatibility with 16-bit Windows-based applications. Win32-based applications should store initialization information in the registry.
msdn上面的描述如果是32位的系统要把这些信息放在注册表中。
我尝试了下其实放在配置文件中依然可以读取正确。