WritePrivateProfileString Lib" kernel32"在服务器2008中 [英] WritePrivateProfileString Lib "kernel32" in server 2008

查看:147
本文介绍了WritePrivateProfileString Lib" kernel32"在服务器2008中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些从ini文件读取和写入的继承遗留代码。我们最近升级到Server 2008(我知道我们落后于时代)但写作退出工作。



声明函数WritePrivateProfileString Libkernel32Alias _

WritePrivateProfileStringA(ByVal lpApplicationName _

As String,ByVal lpKeyName As String,ByVal lpString As String,_

ByVal lpFileName As String)As Integer



这适用于阅读它。



GetPrivateProfileString(sSection,sKey,sDefault,sTemp,511,sINIFile)



我把它变成xml文件之前有什么建议吗?



提前谢谢。

解决方案

我不确定我是否理解正确,但如果您正在寻找INI文件方法的替代方案,那么web.config文件怎么样?

.NET Conf的原因,位置和方式配置文件



如果您对这里感兴趣,还可以举例说明如何将原有的INI转换为XML:

  Dim  iniFile  As   IniFile()
iniFile.Load( Sample.ini

使用 xmlFile = XmlWriter.Create( Sample.xml

xmlFile.WriteStartDocument()
xmlFile.WriteStartElement( sections

每个 iniSection In iniFile.Sections

xmlFile.WriteStartElement( section
xmlFile.Wri teAttributeString( name,iniSection.Name)

对于 每个 iniKey iniSection.Keys

xmlFile.WriteStartElement( key
xmlFile.WriteAttributeString( name,iniKey.Name)
xmlFile.WriteString(iniKey.Value)
xmlFile .WriteEndElement()

下一步
xmlFile.WriteEndElement()
下一步
xmlFile.WriteEndDocument()
结束 使用



以上代码使用我的IniFile库for .NET 中的API。


I have some inherited legacy code that reads and writes from ini file. We recently upgraded to Server 2008 (I know we are behind the times) but writing quit working.

Declare Function WritePrivateProfileString Lib "kernel32" Alias _
"WritePrivateProfileStringA" (ByVal lpApplicationName _
As String, ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Integer

This works for reading it.

GetPrivateProfileString(sSection, sKey, sDefault, sTemp, 511, sINIFile)

Any suggestions before I turn it into an xml file?

Thanks in advance.

解决方案

Hi, I'm not sure if I understood you correctly but if you are looking for an alternative to INI file approach then how about web.config files?
Why, Where, and How of .NET Configuration Files

Also just in case you are interested here is an example how you can convert that legacy INI into an XML:

Dim iniFile As New IniFile()
iniFile.Load("Sample.ini")

Using xmlFile = XmlWriter.Create("Sample.xml")

	xmlFile.WriteStartDocument()
	xmlFile.WriteStartElement("sections")

	For Each iniSection In iniFile.Sections

		xmlFile.WriteStartElement("section")
		xmlFile.WriteAttributeString("name", iniSection.Name)

		For Each iniKey In iniSection.Keys

			xmlFile.WriteStartElement("key")
			xmlFile.WriteAttributeString("name", iniKey.Name)
			xmlFile.WriteString(iniKey.Value)
			xmlFile.WriteEndElement()

		Next
		xmlFile.WriteEndElement()
	Next
	xmlFile.WriteEndDocument()
End Using


Above code uses an API from my IniFile library for .NET.


这篇关于WritePrivateProfileString Lib" kernel32"在服务器2008中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆