当前位置:首页 > 网络编程 > 软件语言 > .NET > vb.Net编程简介之四

vb.Net编程简介之四

点击次数:52 次 发布日期:2008-11-06 08:06:51 作者:源代码网
源代码网推荐
广告载入中
Windows APIs
源代码网推荐 大多数的API调用可以象在Visual Basic 6.0中一样使用,因为
源代码网推荐 数据类型发生了改变。在Visual Basic 6.0中的Long类型在Visual Basic.NET中定义为Integer类型。在升级过程中这些定义会自动改变,例如:
源代码网推荐
源代码网推荐 Private Declare Function GetVersion Lib "kernel32" () As
源代码网推荐 Long
源代码网推荐 Function GetVer()
源代码网推荐 Dim Ver As Long
源代码网推荐 Ver = GetVersion()
源代码网推荐 MsgBox ("System Version is " & Ver)
源代码网推荐 End Function
源代码网推荐
源代码网推荐 改变为:
源代码网推荐
源代码网推荐 Private Declare Function GetVersion Lib "kernel32" () As
源代码网推荐 Integer
源代码网推荐 Function GetVer()
源代码网推荐 Dim Ver As Integer
源代码网推荐 Ver = GetVersion()
源代码网推荐 MsgBox("System Version is " & Ver)
源代码网推荐 End Function
源代码网推荐
源代码网推荐 除了数字类型的升级外,Visual Basic 6.0还支持固定长度字符
源代码网推荐 串类型,该类型升级到Visual Basic.NET后会定义为固定长度字符串兼容类。
源代码网推荐
源代码网推荐 所以在Visual Basic 6.0代码中最好使用通用字符串定义,例如:
源代码网推荐
源代码网推荐 Private Declare Function GetUserName Lib "advapi32.dll"
源代码网推荐 Alias _
源代码网推荐 "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As
源代码网推荐 Long) As Long
源代码网推荐 Function GetUser()
源代码网推荐 Dim Ret As Long
源代码网推荐 Dim UserName As String
源代码网推荐 Dim Buffer As String * 25
源代码网推荐 Ret = GetUserName(Buffer, 25)
源代码网推荐 UserName = Left$(Buffer, InStr(Buffer, Chr(0)) - 1)
源代码网推荐 MsgBox (UserName)
源代码网推荐 End Function
源代码网推荐
源代码网推荐 上面的代码出现了固定长度字符串,最好更改为:
源代码网推荐
源代码网推荐 Dim Buffer As String
源代码网推荐 Buffer = String$(25, " ")
源代码网推荐
源代码网推荐 升级到Visual Basic.NET后会称为下面的样子:
源代码网推荐
源代码网推荐 Declare Function GetUserName Lib "advapi32.dll" Alias _
源代码网推荐 "GetUserNameA" (ByVal lpBuffer As String, ByRef nSize As
源代码网推荐 Integer) As Integer
源代码网推荐 Function GetUser()
源代码网推荐 Dim Ret As Integer
源代码网推荐 Dim UserName As String
源代码网推荐 Dim Buffer As String
源代码网推荐 Buffer = New String(CChar(" "), 25)
源代码网推荐 Ret = GetUserName(Buffer, 25)
源代码网推荐 UserName = Left(Buffer, InStr(Buffer, Chr(0)) - 1)
源代码网推荐 MsgBox(UserName)
源代码网推荐 End Function
源代码网推荐
源代码网推荐 在有些情况下,Visual Basic.NET能够更好的控制传递字符串到
源代码网推荐 API调用,因为你可以通过ANSI 和UNICODE关键字定义字符串传递的方式。
源代码网推荐
源代码网推荐 有三种情况需要对代码最手工改进。
源代码网推荐 1、在传递给API函数的自定义数据类型定义中包含固定长度字符串和
源代码网推荐 数组。在Visual Basic.NET中你需要对自定义数据类型定义中的每一个固定长度字符串和数组添加MarshallAs 属性。
源代码网推荐 2、在定义中使用As Any声明。该种声明不再被Visual Basic.NET支
源代码网推荐 持,变量定义为As Any通常是为了传递一个既可能是字符串也可能是Null的变量,在Visual Basic.NET中,你可以定义两个不同类型的API,一个为Long类型,一个为String类型,以API函数GetPrivateProfileString 为例:
源代码网推荐
源代码网推荐 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,

源代码网推荐

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华