写了一个收集IP\HOSTNAME\MAC的程序,但是在运行的时候提示:无效外部过程,请问是什么原因呢??Private Declare Function netbios Lib "netapi32.dll" (pncb As NCB) As Byte
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 LongPrivate Type NCB
  ncb_command As Byte
  ncb_retcode As Byte
  ncb_lsn As Byte
  ncb_num As Byte
  ncb_buffer As Long
  ncb_length As Integer
  ncb_callname As String * NCBNAMSZ
  ncb_name As String * NCBNAMSZ
  ncb_rto As Byte
  ncb_sto As Byte
  ncb_post As Long
  ncb_lana_num As Byte
  ncb_cmd_cplt As Byte
  ncb_reservr(9) As Byte 
  ncb_event As Long
End Type udtNCB.ncb_command = NCBRESET
 bytResponse = netbios(udtNCB)
 udtNCB.ncb_command = NCBASTAT
 udtNCB.ncb_lana_num = lanaNumber
 udtNCB.ncb_callname = "*"
 udtNCB.ncb_length = Len(udtastat)
 lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
 strout = ""
 If lngASTAT Then
   udtNCB.ncb_buffer = lngASTAT
   byResponse = netbios(udtNCB)
   CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
    With udtastat.adapt
     strout = Right$("00" & Hex$(.adapter_address(0)), 2)
     For x = 1 To 5
      strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
     Next x
    End With
    heapfree GetProcessHeap(), 0, lngASTAT
 End If
ethernetaddress = stroutPrivate Sub Command1_Click()  Text1.Text = Winsock1.LocalIP
  Text2.Text = Winsock1.LocalHostName
  Text3.Text = ethernetaddress()
  Winsock1.Close
 
End Sub

解决方案 »

  1.   

    下面这些要摆在一个事件里面, 你放的位置相当于通用区, 当然属 "外部过程"udtNCB.ncb_command = NCBRESET 
     bytResponse = netbios(udtNCB) 
     udtNCB.ncb_command = NCBASTAT 
     udtNCB.ncb_lana_num = lanaNumber 
     udtNCB.ncb_callname = "*" 
     udtNCB.ncb_length = Len(udtastat) 
     lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length) 
     strout = "" 
     If lngASTAT Then 
       udtNCB.ncb_buffer = lngASTAT 
       byResponse = netbios(udtNCB) 
       CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat) 
        With udtastat.adapt 
         strout = Right$("00" & Hex$(.adapter_address(0)), 2) 
         For x = 1 To 5 
          strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2) 
         Next x 
        End With 
        heapfree GetProcessHeap(), 0, lngASTAT 
     End If 
    ethernetaddress = strout 
      

  2.   

    我把这段代码加在了事件里面,但是现在提示  * NCBNAMSZ  要求常数表达式
    请问是由于什么原因呢??
      

  3.   

    下面这些都是常量,没人会记得那么多,有用到时就在网上搜一下就行了, 这些都放在上面的通用区不放在事件里面.Const NCBASTAT = &H33 
    Const NCBNAMSZ = 16 
    Const NCBRESET = &H32 
    Const HEAP_ZERO_MEMORY = &H8 
    Const HEAP_GENERATE_EXCEPTIONS = &H4 
      

  4.   

    你只要得到这三个何必搞得那么杂呢 ? 告诉我你想要得到什么吧.试着帮你整了一下,缺少udtNCB这个控件3F 的那些要贴在Private Type NCB 上面
    '1F的要放在这个事件里面Private Sub ethernetaddress()
     udtNCB.ncb_command = NCBRESET
     bytResponse = netbios(udtNCB)
     udtNCB.ncb_command = NCBASTAT
     udtNCB.ncb_lana_num = lanaNumber
     udtNCB.ncb_callname = "*"
     udtNCB.ncb_length = Len(udtastat)
     lngASTAT = HwapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MOMORY, udtNCB.ncb_length)
     strout = ""
     If lngASTAT Then
       udtNCB.ncb_buffer = lngASTAT
       byResponse = netbios(udtNCB)
       CopyMemory udtastat, udtNVB.ncb_buffer, Len(udtastat)
        With udtastat.adapt
         strout = Right$("00" & Hex$(.adapter_address(0)), 2)
         For x = 1 To 5
          strout = strout & "-" & Right$("00" & Hex(.adapter_address(x)), 2)
         Next x
        End With
        heapfree GetProcessHeap(), 0, lngASTAT
     End If
    ethernetaddress = strout
    End Sub
      

  5.   

    Private Sub Form_Load()
       MsgBox "网卡MAC地址:" & Replace(MACAddress, ":", "-")
       MsgBox "IP地址:" & Winsock1.LocalIP
       MsgBox "主机名:" & Winsock1.LocalHostName  '"机器名:" & Environ("computername")
       MsgBox "用户名:" & Environ("username")
    End SubPrivate Function MACAddress() As String
       Set objs = GetObject("winmgmts:").ExecQuery("SELECT MACAddress " & "FROM Win32_NetworkAdapter " & "WHERE " & "((MACAddress Is Not NULL) " & "AND (Manufacturer <> " & "'Microsoft'))")
       For Each obj In objs
          MACAddress = obj.MACAddress
          Exit For
       Next obj
    End Function
      

  6.   


    谢谢大哥您了,我现在只是在学习当中,初学VB,对VB的函数不了解。再次表示感谢~~!!