读写ini文件的问题

ahljxwy 2010-11-16 03:37:23
我用的是从网上找的读写INI文件的模块,但写入文件时总是提示 "无法在 DLL“kernel32 ”中找到名为“WritePrivateProfileStringA ”的入口点。"请各位大虾发个能用的模块给我,感激不尽!
...全文
123 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahljxwy 2010-11-16
  • 打赏
  • 举报
回复
能给我说一下加 @ 是什么意思吗?
烈火蜓蜻 2010-11-16
  • 打赏
  • 举报
回复
调用API的时候,不要用后缀有A的方法, 没有后缀他会自动根据平台环境,自动选择适合的API函数
烈火蜓蜻 2010-11-16
  • 打赏
  • 举报
回复
WritePrivateProfileString (kernel32)

Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
. Summary
The WritePrivateProfileString API
C# Signature:
[DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool WritePrivateProfileString(string lpAppName,
string lpKeyName, string lpString, string lpFileName);



VB.NET Signature:
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Boolean
End Function



VB.NET Alternative Signature:
<DllImport("kernel32.dll", SetLastError:=True)> _
Private Declare Auto Function WritePrivateProfileString Lib "kernel32" (ByVal lpAppName As String, _
ByVal lpKeyName As String, _
ByVal lpString As String, _
ByVal lpFileName As String) As Boolean



C++ Signature:
[DllImport("KERNEL32.DLL", CharSet=CharSet::Auto, EntryPoint="WritePrivateProfileString")]
static Boolean WritePrivateProfileString(String^ lpAppName, String^ lpKeyName, String^ lpString, String^ lpFileName);



User-Defined Types:
None.

Notes:
If StringToWrite is NULL, the line indicated by SectionName and KeyName will be deleted.

If KeyName is NULL, the entire section indicated by SectionName and all keys and values therein will be deleted.

Tips & Tricks:
Please add some!

Sample Code:
C# Sample:

bool WriteINI(string SectionName, string KeyName, string StringToWrite, string INIFileName)

{

bool Return;
Return = WritePrivateProfileString(SectionName,
KeyName,
StringToWrite,
INIFileName);
return Return;


}

VB.NET Sample

Dim bres As Boolean
bres = WritePrivateProfileString("AppName", "KeyName", "TestValue", "c:\test.ini")
Console.WriteLine("WritePrivateProfileString returned : " & bres.ToString())



VB.NET Alternative Sample

Public Function WriteIni(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFilename As String) As Boolean
Try

WritePrivateProfileString(lpAppname, lpKeyName, lpString, lpFilename)
Return True
Exit Try

Catch ex As Exception

Return False

End Try
End Function



Alternative Managed API:
Do you know one? Please contribute it!

  • 打赏
  • 举报
回复
cboServer.Text = GetINI("连接", "服务器", "", Application.StartupPath + @“\Config.ini")
  • 打赏
  • 举报
回复
cboServer.Text = GetINI("连接", "服务器", "", "Application.StartupPath + \Config.ini")
少了一个@
cboServer.Text = GetINI("连接", "服务器", "", @"Application.StartupPath + \Config.ini")
Todd_Zhang 2010-11-16
  • 打赏
  • 举报
回复
学习。。。
烈火蜓蜻 2010-11-16
  • 打赏
  • 举报
回复
引用错了DLL了,上网Baidu一下,看看,WritePrivateProfileStringA 这个方法是在哪个DLL里
ahljxwy 2010-11-16
  • 打赏
  • 举报
回复
我现在可以写入数据了,但我用
cboServer.Text = GetINI("连接", "服务器", "", "Application.StartupPath + \Config.ini")
我方法来读时却读不出数据???

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧