如何输出API 返回的字符串?
Private Declare Function GetEnvironmentStrings Lib "kernel32" Alias "GetEnvironmentStringsA" () As Long
如何显示此函数返回的字符串?
或者 如何将此函数返回的字符串转换为 VB 的字符串?
谢谢指教~
问题点数:100、回复次数:4Top
1 楼YaDa()回复于 2005-04-03 12:51:53 得分 10
用这个 GetEnvironmentVariable 不就行了,得到的是字符串。Top
2 楼TechnoFantasy((VB MVP)www.applevb.com)回复于 2005-04-03 12:59:55 得分 45
Private Declare Function GetEnvironmentStrings Lib "kernel32" Alias "GetEnvironmentStringsA" () As Long
Private Declare Function FreeEnvironmentStrings Lib "kernel32" Alias "FreeEnvironmentStringsA" (ByVal lpsz As String) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Sub Form_Load()
'The KPD-Team 2001
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim lngRet As Long, strDest As String, lLen As Long
'set the graphics mode to persistent
Me.AutoRedraw = True
'retrieve the initial pointer to the environment strings
lngRet = GetEnvironmentStrings
Do
'get the length of the following string
lLen = lstrlen(lngRet)
'if the length equals 0, we've reached the end
If lLen = 0 Then Exit Do
'create a buffer string
strDest = Space$(lLen)
'copy the text from the environment block
CopyMemory ByVal strDest, ByVal lngRet, lLen
'show the text
Me.Print strDest
'move the pointer
lngRet = lngRet + lstrlen(lngRet) + 1
Loop
'clean up
FreeEnvironmentStrings lngRet
End SubTop
3 楼YaDa()回复于 2005-04-03 13:08:42 得分 45
在VB里有 Environ 函数,直接用它才是VB程序员的风格。
Environ 函数示例
本示例使用 Environ 函数来提供来自环境变量表中 PATH 语句的长度及路径项目数。
Dim EnvString, Indx, Msg, PathLen ' 声明变量。
Indx = 1 ' 设置索引值的初值为 1。
Do
EnvString = Environ(Indx) ' 取得环境变量。
If Left(EnvString, 5) = "PATH=" Then ' 检查 PATH 项。
PathLen = Len(Environ("PATH")) ' 取得长度。
Msg = "PATH entry = " & Indx & " and length = " & PathLen
Exit Do
Else
Indx = Indx + 1 ' 不是 PATH 项,
End If ' 则跳过此项,继续检查下一项。
Loop Until EnvString = ""
If PathLen > 0 Then
MsgBox Msg ' 显示消息。
Else
MsgBox "No PATH environment variable exists."
End If
Top
4 楼kadxm(可爱的小猫)回复于 2005-04-03 17:34:56 得分 0
thx
Top




