首页 > 开发 > 综合 > 正文

读写INI文件的自定义函数(VB)

2024-07-21 02:20:42
字体:
来源:转载
供稿:网友

private declare function getprivateprofileint lib "kernel32" alias "getprivateprofileinta" (byval lpapplicationname as string, byval lpkeyname as string, byval ndefault as long, byval lpfilename as string) as long
private declare function getprivateprofilestring lib "kernel32" alias "getprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as any, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as long
private declare function writeprivateprofilestring lib "kernel32" alias "writeprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as any, byval lpstring as any, byval lpfilename as string) as long
private declare function getwindowsdirectory lib "kernel32" alias "getwindowsdirectorya" (byval lpbuffer as string, byval nsize as long) as long

'写ini文件(字符串)
public sub writeini(byval filename as string, byval app as string, byval key as string, byval strvalue as string)
dim result as long
result = writeprivateprofilestring(app, key, strvalue, filename)
end sub
'读整型
public function getiniint(byval filename as string, byval app as string, byval key as string) as long
dim result as long
result = getprivateprofileint(app, key, 0, filename)
getiniint = result
end function
'读字符串
public function getinistr(byval filename as string, byval app as string, byval key as string) as string
dim result as long
dim bufferstr as string * 255
result = getprivateprofilestring(app, key, "", bufferstr, len(bufferstr), filename)
if result = 0 then
getinistr = ""
else
getinistr = left(bufferstr, result)
end if
end function
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表