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
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
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 getprivateprofilestringkey lib "kernel32" alias "getprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as string, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as long private declare function getprivateprofilestringnullkey lib "kernel32" alias "getprivateprofilestringa" (byval lpapplicationname as string, byval lpkeyname as long, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as long