主题:离开vb开发ide环境,就不能获取mac地址
离开vb开发ide环境,就不能获取mac地址了。比如在开发目录中直接运行生成的exe文件或者打包安装到机上上运行,就获取到:00 00 00 00 00 00
请高手有时间解答一下啊
以下是随书《vb开发经验技巧宝典》中的代码:
Option Explicit
Const NCBASTAT As Long = &H33
Const NCBNAMSZ As Long = 16
Const HEAP_ZERO_MEMORY As Long = &H8
Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Const NCBRESET As Long = &H32
Private Type NET_CONTROL_BLOCK
ncb_command As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte
adapter_type As Byte
End Type
Private Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NET_CONTROL_BLOCK) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Private Sub Command1_Click()
Dim i As Integer
Dim pASTAT As Long
Dim NCB As NET_CONTROL_BLOCK
Dim AST As ASTAT
NCB.ncb_command = NCBRESET
Call Netbios(NCB)
NCB.ncb_callname = "* "
NCB.ncb_command = NCBASTAT
NCB.ncb_lana_num = 0
NCB.ncb_length = Len(AST)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _
Or HEAP_ZERO_MEMORY, NCB.ncb_length)
NCB.ncb_buffer = pASTAT
Call Netbios(NCB)
CopyMemory AST, NCB.ncb_buffer, Len(AST)
For i = 0 To 5
Text1.Text = Text1.Text & Format$(Hex(AST.adapt.adapter_address(i)), "00") & " "
Next i
HeapFree GetProcessHeap(), 0, pASTAT
End Sub
Private Sub Command2_Click()
End
End Sub
请高手有时间解答一下啊
以下是随书《vb开发经验技巧宝典》中的代码:
Option Explicit
Const NCBASTAT As Long = &H33
Const NCBNAMSZ As Long = 16
Const HEAP_ZERO_MEMORY As Long = &H8
Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Const NCBRESET As Long = &H32
Private Type NET_CONTROL_BLOCK
ncb_command As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte
adapter_type As Byte
End Type
Private Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NET_CONTROL_BLOCK) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Private Sub Command1_Click()
Dim i As Integer
Dim pASTAT As Long
Dim NCB As NET_CONTROL_BLOCK
Dim AST As ASTAT
NCB.ncb_command = NCBRESET
Call Netbios(NCB)
NCB.ncb_callname = "* "
NCB.ncb_command = NCBASTAT
NCB.ncb_lana_num = 0
NCB.ncb_length = Len(AST)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS _
Or HEAP_ZERO_MEMORY, NCB.ncb_length)
NCB.ncb_buffer = pASTAT
Call Netbios(NCB)
CopyMemory AST, NCB.ncb_buffer, Len(AST)
For i = 0 To 5
Text1.Text = Text1.Text & Format$(Hex(AST.adapt.adapter_address(i)), "00") & " "
Next i
HeapFree GetProcessHeap(), 0, pASTAT
End Sub
Private Sub Command2_Click()
End
End Sub