网站首页  词典首页

请输入您要查询的函数:

 

术语 writeprivateprofilestring
释义 WritePrivateProfileString
语法:
C++
BOOL WINAPI WritePrivateProfileString(
__in LPCTSTR lpAppName,
__in LPCTSTR lpKeyName,
__in LPCTSTR lpString,
__in LPCTSTR lpFileName
);
WritePrivateProfileString函数
拷贝到初始化文件中指定的部分字符串。
注意:此功能仅提供了兼容性与16位的Windows版本。应用程序应该在注册表中存储初始化信息。
参数
lpAppName [in]
在到该字符串将被复制部分的名称。如果节不存在,则创建。本节的名称是有独立的,该字符串可以是任何大写和小写字母的组合。
lpKeyName [in]
键的名称,必须与一个字符串。 If the key does not exist in the specified section, it is created.如果该参数为NULL,则整节,包括在该节的所有作品,被删除。
lpString [in]
一个以null 结尾的字符串写入该文件。如果该参数为NULL,关键指出的lpKeyName参数被删除。
lpFileName [in]
在初始化文件的名称。
如果该文件是使用Unicode字符,函数Unicode字符写入到文件。否则,该函数将ANSI字符。
返回值
如果函数成功复制字符串初始化文件,则返回值为非零。
如果函数失败,或者如果它刷新了最近访问的初始化文件的缓存版本,返回值是零。为了获得更多错误信息,调用GetLastError。
备注
阿在初始化文件的部分必须有以下形式:
[节]
关键=字符串



如果lpFileName参数不包含完整路径和文件的文件名,WritePrivateProfileString搜索该文件的Windows目录。如果该文件不存在,此函数创建在Windows目录中的文件。
如果lpFileName包含一个完整路径和文件名和文件不存在,WritePrivateProfileString创建文件。指定的目录必须已经存在。
该系统保存了最新版本的注册表文件映射缓存以提高性能。如果所有参数为NULL,则函数刷新缓存。这个系统虽然是编辑文件的缓存版本,流程,编辑文件本身将使用原始文件,直到缓存已被清除。
该系统的地图最。ini文件到注册表中的引用,使用以下注册表项中定义的映射:
HKEY_LOCAL_MACHINE
Microsoft
Windows NT
CurrentVersion
CurrentVersion
IniFileMappingThis映射可能是,如果一个应用程序修改,如Control.ini,的System.ini系统组件初始化文件中,Winfile.ini。在这种情况下,该函数将信息写入注册表,而不是初始化文件,在存储位置的变化并没有对函数的行为的影响。
配置文件函数使用下列步骤定位初始化信息:
查找在为下IniFileMapping关键初始化文件的名称登记。
查询由lpAppName指定的节的名称。这将是一个命名值中具有关键的初始化文件名,或者一个子项与此名称或名称将不存在,一个值或子项。
如果区段名称由lpAppName指定一个命名值,则该值指定在注册表中您会发现,该科的钥匙。
如果区段名称由lpAppName指定一个子项,然后命名该子项下的具体值,其中,在注册表中您会发现,该科的钥匙。如果密钥您正在寻找不存在的一个命名值,就会有一个未命名的值(显示为<无名称>),指定注册表中的默认位置,您会发现关键。
如果按lpAppName区段名称不存在指定作为一个命名值或一个子项,然后会有一个未命名的值(显示为<无名称>),指定注册表中的默认位置,您将找到的钥匙一节。
如果没有子项或部分名称项,然后查找磁盘上的实际初始化文件并阅读其内容。
当在注册表值寻找其他指定的注册表位置,有几个前缀是改变的。ini文件映射的行为:
! -这个人物写的所有部队都进入到注册表和。ini文件在磁盘上。
# -该字符会导致注册表值被设置为在Windows 3.1的。ini文件中的价值当新用户登录的安装后的第一次。
@ -此字不允许任何人去。ini文件在磁盘上,如果请求的数据不在注册表中读取。
USR: -这个前缀代表HKEY_CURRENT_USER,文本后的前缀是相对于该键。
SYS: -这个前缀代表HKEY_LOCAL_MACHINE \\软件,文本后的前缀是相对于该键。
应用程序使用WritePrivateProfileString函数进入。ini文件到注册表的信息,应遵循以下原则:
确保没有。ini文件中指定的名称上存在的制度。
确保有一个在注册表中指定。ini文件的关键项。此项目应根据路径HKEY_LOCAL_MACHINE \\软件\\微软\\视窗NT \\ CurrentVersion \\ IniFileMapping。
指定该值。ini文件的关键项指定的一节。也就是说,应用程序必须指定区段名称,因为这会出现在。ini文件或注册表项。下面是一个例子:[我的部分]。
对于系统文件,指定一个增值SYS。
对于应用程序文件,在指定的附加值usr下。下面是一个例子:“我的第:USR:应用程序名称\\科”。而且,由于USR表明在HKEY_CURRENT_USER映射,应用程序也应该建立在HKEY_CURRENT_USER下,指定应用程序的名称中列出的附加价值的关键。对于刚才的例子,那将是“应用程序名称”。
经过上述步骤之后,应用程序的安装程序应调用前三个参数设置为NULL WritePrivateProfileString,和第四个参数设置为INI文件的名称。例如:
WritePrivateProfileString(空,空,空,升“appname.ini”);
这样的调用会导致一个的。ini映射文件到注册表,以之前在下次系统重新启动后生效。该系统重新读取到共享内存映射信息。用户将不必在安装后重新启动他们的计算机应用程序,以便有应用程序的未来调用看到的。ini映射文件到注册表。
实例
下面的示例代码说明了前面的指导方针,是根据若干假设为基础:
有一个名为App名称的申请。
该应用程序使用。ini文件名为AppName.ini。
有一个的。ini部分文件,我们想是这样的:
[Section1]
FirstKey = It all worked out okay.
SecondKey = By golly, it works.
ThirdKey = Another test.
The user will not have to reboot the system in order to have future invocations of the application see the mapping of the .ini file to the registry.
#include
#include
#include

int main()
{
TCHAR inBuf[80];
HKEY hKey1, hKey2;
DWORD dwDisposition;
LONG lRetCode;
TCHAR szData[] = TEXT("USR:App Name\\\\Section1");

// Create the .ini file key.
lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\IniFileMapping\\\\appname.ini"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey1,
&dwDisposition);

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating appname.ini key (%d).\\n", lRetCode);
return (0) ;
}

// Set a section value
lRetCode = RegSetValueEx ( hKey1,
TEXT("Section1"),
0,
REG_SZ,
(BYTE *)szData,
sizeof(szData));

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in setting Section1 value\\n");
// Close the key
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return (0) ;
}
}

// Create an App Name key
lRetCode = RegCreateKeyEx ( HKEY_CURRENT_USER,
TEXT("App Name"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey2,
&dwDisposition);

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating App Name key (%d).\\n", lRetCode);
// Close the key
lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return (0) ;
}
}

// Force the system to read the mapping into shared memory
// so that future invocations of the application will see it
// without the user having to reboot the system
WritePrivateProfileStringW( NULL, NULL, NULL, L"appname.ini" );

// Write some added values
WritePrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("It all worked out OK."),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("SecondKey"),
TEXT("By golly, it works!"),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("ThirdKey"),
TEXT("Another test..."),
TEXT("appname.ini"));
// Test
GetPrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("Error: GPPS failed"),
inBuf,
80,
TEXT("appname.ini"));
_tprintf (TEXT("Key: %s\\n"), inBuf);

// Close the keys
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return(0);
}
lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return(0);
}

return(1);
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderWinbase.h(头文件:winuser.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode和ANSI namesWritePrivateProfileStringW(Unicode)和WritePrivateProfileStringA(ANSI)的
参见
GetPrivateProfileString
WriteProfileString
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月27日
==英文原文==WritePrivateProfileString Function
Copies a string into the specified section of an initialization file.
Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry.
Syntax
C++
BOOL WINAPI WritePrivateProfileString(
__in LPCTSTR lpAppName,
__in LPCTSTR lpKeyName,
__in LPCTSTR lpString,
__in LPCTSTR lpFileName
);
Parameters
lpAppName [in]
The name of the section to which the string will be copied. If the section does not exist, it is created. The name of the section is case-independent; the string can be any combination of uppercase and lowercase letters.
lpKeyName [in]
The name of the key to be associated with a string. If the key does not exist in the specified section, it is created. If this parameter is NULL, the entire section, including all entries within the section, is deleted.
lpString [in]
A null-terminated string to be written to the file. If this parameter is NULL, the key pointed to by the lpKeyName parameter is deleted.
lpFileName [in]
The name of the initialization file.
If the file was created using Unicode characters, the function writes Unicode characters to the file. Otherwise, the function writes ANSI characters.
Return Value
If the function successfully copies the string to the initialization file, the return value is nonzero.
If the function fails, or if it flushes the cached version of the most recently accessed initialization file, the return value is zero. To get extended error information, call GetLastError .
Remarks
A section in the initialization file must have the following form:
[section]
key=string
.
.
.
If the lpFileName parameter does not contain a full path and file name for the file, WritePrivateProfileString searches the Windows directory for the file. If the file does not exist, this function creates the file in the Windows directory.
If lpFileName contains a full path and file name and the file does not exist, WritePrivateProfileString creates the file. The specified directory must already exist.
The system keeps a cached version of the most recent registry file mapping to improve performance. If all parameters are NULL, the function flushes the cache. While the system is editing the cached version of the file, processes that edit the file itself will use the original file until the cache has been cleared.
The system maps most .ini file references to the registry, using the mapping defined under the following registry key:
HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
Windows NT
CurrentVersion
IniFileMappingThis mapping is likely if an application modifies system-component initialization files, such as Control.ini, System.ini, and Winfile.ini. In this case, the function writes information to the registry, not to the initialization file; the change in the storage location has no effect on the function's behavior.
The profile functions use the following steps to locate initialization information:
Look in the registry for the name of the initialization file under the IniFileMapping key.
Look for the section name specified by lpAppName. This will be a named value under the key that has the name of the initialization file, or a subkey with this name, or the name will not exist as either a value or subkey.
If the section name specified by lpAppName is a named value, then that value specifies where in the registry you will find the keys for the section.
If the section name specified by lpAppName is a subkey, then named values under that subkey specify where in the registry you will find the keys for the section. If the key you are looking for does not exist as a named value, then there will be an unnamed value (shown as ) that specifies the default location in the registry where you will find the key.
If the section name specified by lpAppName does not exist as a named value or as a subkey, then there will be an unnamed value (shown as ) that specifies the default location in the registry where you will find the keys for the section.
If there is no subkey or entry for the section name, then look for the actual initialization file on the disk and read its contents.
When looking at values in the registry that specify other registry locations, there are several prefixes that change the behavior of the .ini file mapping:
! - this character forces all writes to go both to the registry and to the .ini file on disk.
# - this character causes the registry value to be set to the value in the Windows 3.1 .ini file when a new user logs in for the first time after setup.
@ - this character prevents any reads from going to the .ini file on disk if the requested data is not found in the registry.
USR: - this prefix stands for HKEY_CURRENT_USER, and the text after the prefix is relative to that key.
SYS: - this prefix stands for HKEY_LOCAL_MACHINE\\SOFTWARE, and the text after the prefix is relative to that key.
An application using the WritePrivateProfileString function to enter .ini file information into the registry should follow these guidelines:
Ensure that no .ini file of the specified name exists on the system.
Ensure that there is a key entry in the registry that specifies the .ini file. This entry should be under the path HKEY_LOCAL_MACHINE\\SOFTWARE \\Microsoft\\Windows NT\\CurrentVersion\\IniFileMapping.
Specify a value for that .ini file key entry that specifies a section. That is to say, an application must specify a section name, as it would appear within an .ini file or registry entry. Here is an example: [My Section].
For system files, specify SYS for an added value.
For application files, specify USR within the added value. Here is an example: "My Section: USR: App Name\\Section". And, since USR indicates a mapping under HKEY_CURRENT_USER, the application should also create a key under HKEY_CURRENT_USER that specifies the application name listed in the added value. For the example just given, that would be "App Name".
After following the preceding steps, an application setup program should call WritePrivateProfileString with the first three parameters set to NULL, and the fourth parameter set to the INI file name. For example:
WritePrivateProfileString( NULL, NULL, NULL, L"appname.ini" );
Such a call causes the mapping of an .ini file to the registry to take effect before the next system reboot. The system rereads the mapping information into shared memory. A user will not have to reboot their computer after installing an application in order to have future invocations of the application see the mapping of the .ini file to the registry.
Examples
The following sample code illustrates the preceding guidelines and is based on several assumptions:
There is an application named App Name.
That application uses an .ini file named AppName.ini.
There is a section in the .ini file that we want to look like this:
[Section1]
FirstKey = It all worked out okay.
SecondKey = By golly, it works.
ThirdKey = Another test.
The user will not have to reboot the system in order to have future invocations of the application see the mapping of the .ini file to the registry.
#include
#include
#include

int main()
{
TCHAR inBuf[80];
HKEY hKey1, hKey2;
DWORD dwDisposition;
LONG lRetCode;
TCHAR szData[] = TEXT("USR:App Name\\\\Section1");

// Create the .ini file key.
lRetCode = RegCreateKeyEx ( HKEY_LOCAL_MACHINE,
TEXT("SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\IniFileMapping\\\\appname.ini"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey1,
&dwDisposition);

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating appname.ini key (%d).\\n", lRetCode);
return (0) ;
}

// Set a section value
lRetCode = RegSetValueEx ( hKey1,
TEXT("Section1"),
0,
REG_SZ,
(BYTE *)szData,
sizeof(szData));

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in setting Section1 value\\n");
// Close the key
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return (0) ;
}
}

// Create an App Name key
lRetCode = RegCreateKeyEx ( HKEY_CURRENT_USER,
TEXT("App Name"),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hKey2,
&dwDisposition);

if (lRetCode != ERROR_SUCCESS)
{
printf ("Error in creating App Name key (%d).\\n", lRetCode);
// Close the key
lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return (0) ;
}
}

// Force the system to read the mapping into shared memory
// so that future invocations of the application will see it
// without the user having to reboot the system
WritePrivateProfileStringW( NULL, NULL, NULL, L"appname.ini" );

// Write some added values
WritePrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("It all worked out OK."),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("SecondKey"),
TEXT("By golly, it works!"),
TEXT("appname.ini"));
WritePrivateProfileString (TEXT("Section1"),
TEXT("ThirdKey"),
TEXT("Another test..."),
TEXT("appname.ini"));
// Test
GetPrivateProfileString (TEXT("Section1"),
TEXT("FirstKey"),
TEXT("Error: GPPS failed"),
inBuf,
80,
TEXT("appname.ini"));
_tprintf (TEXT("Key: %s\\n"), inBuf);

// Close the keys
lRetCode = RegCloseKey( hKey1 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return(0);
}
lRetCode = RegCloseKey( hKey2 );
if( lRetCode != ERROR_SUCCESS )
{
printf("Error in RegCloseKey (%d).\\n", lRetCode);
return(0);
}

return(1);
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesWritePrivateProfileStringW (Unicode) and WritePrivateProfileStringA (ANSI)
See Also
GetPrivateProfileString
WriteProfileString
Send comments about this topic to Microsoft
Build date: 8/27/2009
==原始网址==http://msdn.microsoft.com/en-us/library/ms725501(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 11:30:07