主题:c调用GetPrivateProfileString()函数 参数如何设定?
ollydbg
[专家分:0] 发布于 2006-05-11 06:22:00
用c调用GetPrivateProfileString()函数读取ini文件,那个lpReturnedString参数应该怎样设定?nsize参数应该怎样设定?
下面是该函数的信息:
将信息从INI文件中读入程序中的变量.
1.所用的WINAPI函数原型为:
DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
);
其中各参数的意义:
前二个参数与 WritePrivateProfileString中的意义一样.
lpDefault : 如果INI文件中没有前两个参数指定的字段名或键名,则将此值赋给变量.
lpReturnedString : 接收INI文件中的值的CString对象,即目的缓存器.
nSize : 目的缓存器的大小.
lpFileName : 是完整的INI文件名.
回复列表 (共2个回复)
沙发
aaronwang [专家分:16870] 发布于 2006-05-11 08:55:00
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. Applications should store initialization information in the registry.
DWORD GetPrivateProfileString(
LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName
);
Parameters
lpAppName
[in] Pointer to a null-terminated string that specifies the name of the section containing the key name. If this parameter is NULL, the GetPrivateProfileString function copies all section names in the file to the supplied buffer.
lpKeyName
[in] Pointer to the null-terminated string specifying the name of the key whose associated string is to be retrieved. If this parameter is NULL, all key names in the section specified by the lpAppName parameter are copied to the buffer specified by the lpReturnedString parameter.
lpDefault
[in] Pointer to a null-terminated default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. If this parameter is NULL, the default is an empty string, "".
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedString buffer to strip any trailing blanks.
Windows Me/98/95: Although lpDefault is declared as a constant parameter, the system strips any trailing blanks by inserting a null character into the lpDefault string before copying it to the lpReturnedString buffer.
lpReturnedString
[out] Pointer to the buffer that receives the retrieved string.
Windows Me/98/95: The string cannot contain control characters (character code less than 32). Strings containing control characters may be truncated.
nSize
[in] Size of the buffer pointed to by the lpReturnedString parameter, in characters.
lpFileName
[in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.
MSDN都有,慢慢看.
板凳
fresher [专家分:730] 发布于 2006-05-26 23:14:00
参数是你将要从文件中读出的字符串,nsize参数是你要读出字符串的大小.可以这样操作:
char lpReturnedString[32];
nsize=sizeof(szText);
然后带入函数就行.
我来回复