WriteProfileString的问题

来源:互联网 发布:鬼遮眼网络大电影 编辑:程序博客网 时间:2024/05/21 00:55

该函数有两个同名原型,一个是windows API,一个是CWinApp的成员函数。

作为API的情况,MSDN的说明如下:

The WriteProfileString function copies a string into the specified section of the Win.ini file. If Win.ini uses Unicode characters, the function writes Unicode characters to the file. Otherwise, thefunction writes ANSI characters.
Note  This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry.
BOOL WriteProfileString(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  LPCTSTR lpString
);
总的来说,也就是,这个函数在32位机以后不再使用,存在的目的只是为了与16位机兼容。

作为CWinApp成员函数的情况:

MSDN说明:
Call this member function to write the specified string into the specified section of the application's registry or .INI file.
BOOL WriteProfileString(
    LPCTSTR lpszSection,
 LPCTSTR lpszEntry,
 LPCTSTR lpszValue);
简而言之,就是说这个函数写的内容可能是在注册表中,也可能是在.ini文件中,那么究竟怎么判断呢?
先来看一个函数MSDN说明:
 Causes application settings to be stored in the registry instead of INI files.
void SetRegistryKey(
  LPCTSTR lpszRegistryKey 
);
void SetRegistryKey(
  UINT nIDRegistryKey 
);
  翻译过来很明了,这个函数就是用来控制程序初始化信息时存储位置的,是注册表,或者.ini文件。
  如果想存到注册表中,就先调用一下这个函数就OK了,默认是存储在.ini文件中的。那么问题又来了,这个.ini文件存在什么地方?又叫什么名字呢?
  调试跟踪到CWinApp::WriteProfileString中间,发现了这个函数:return ::WritePrivateProfileString(lpszSection, lpszEntry, lpszValue,m_pszProfileName);
然后根据m_pszProfileName的名字RPT.ini(因为我的应用程序名字为RPT.exe)查找,最后在C:\WINDOWS下查找到了RPT.ini的文件,打开看下,结果不错。
原创粉丝点击