我快崩潰了...就這個玩意搞了2天...神啊...救救我吧....Module中的代碼
------------------------------------------------
Option Explicit
'常數定義
Public Const MAX_LANA = 255
Public Const NCBNAMSZ = 16
Public Const NCBENUM = &H37
'Type of LANA_ENUM'LANA_ENUM結構定義
Public Type LANA_ENUM
Length As Integer
lana(MAX_LANA) As Integer
End Type
'NCB控制塊結構定義
Public Type NCB
ncb_command As Integer
ncb_retcode As Integer
ncb_lsn As Integer
ncb_num As Integer
ncb_buffer As String
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Integer
ncb_sto As Integer
ncb_post As Long
ncb_lana_num As Integer
ncb_cmd_cplt As Integer
ncb_reserve(10) As Byte ' Reserved, must be 0
ncb_event As Long
End Type'Netbios命令定義
Public Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
-------------------------------------------以上命令,常數定義都是API Viewer中copy的,應該不會有錯...以下是窗口中的代碼 -- 就1個按鈕 click事件Private Sub Command1_Click()
Dim lenum As LANA_ENUM '定義1個lana_enum結構變量
Dim pncb As NCB '定義1個NCB結構變量
pncb.ncb_command = NCBENUM '對ncb賦值
pncb.ncb_buffer = varptr(lenum)
pncb.ncb_length = Len(lenum)IF Netbios(pncb)<>1 then msgbox "wrong" End Sub上面netbios(pncb)老是出錯....正確的該是怎麼樣的寫法?請各位達人幫幫忙....
------------------------------------------------
Option Explicit
'常數定義
Public Const MAX_LANA = 255
Public Const NCBNAMSZ = 16
Public Const NCBENUM = &H37
'Type of LANA_ENUM'LANA_ENUM結構定義
Public Type LANA_ENUM
Length As Integer
lana(MAX_LANA) As Integer
End Type
'NCB控制塊結構定義
Public Type NCB
ncb_command As Integer
ncb_retcode As Integer
ncb_lsn As Integer
ncb_num As Integer
ncb_buffer As String
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Integer
ncb_sto As Integer
ncb_post As Long
ncb_lana_num As Integer
ncb_cmd_cplt As Integer
ncb_reserve(10) As Byte ' Reserved, must be 0
ncb_event As Long
End Type'Netbios命令定義
Public Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
-------------------------------------------以上命令,常數定義都是API Viewer中copy的,應該不會有錯...以下是窗口中的代碼 -- 就1個按鈕 click事件Private Sub Command1_Click()
Dim lenum As LANA_ENUM '定義1個lana_enum結構變量
Dim pncb As NCB '定義1個NCB結構變量
pncb.ncb_command = NCBENUM '對ncb賦值
pncb.ncb_buffer = varptr(lenum)
pncb.ncb_length = Len(lenum)IF Netbios(pncb)<>1 then msgbox "wrong" End Sub上面netbios(pncb)老是出錯....正確的該是怎麼樣的寫法?請各位達人幫幫忙....
自己解決了...原來Dim lenum As LANA_ENUM不會幫你分配內存...
所以pncb.ncb_buffer = varptr(lenum)並不會得到一個buffer地址
所以必須使用heapalloc來手工分配地址,再把得到的指針賦給ncb_buffer
執行即可...香自己一個.
模塊中的申明增加相應的堆操作API
command1_click中的代碼改成下面即可:
Dim mylana As LANA_ENUM
Dim pmylana As Long
Dim myncb As NCB
Dim bret As Bytemyncb.ncb_command = NCBENUM
myncb.ncb_length = Len(mylana)
pmylana = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or HEAP_ZERO_MEMORY,myncb.ncb_length)
myncb.ncb_buffer = pmylana
bret = Netbios(myncb)
CopyMemory mylana, myncb.ncb_buffer, Len(mylana)
HeapFree GetProcessHeap, 0, pmylana
这样看看
set lenum= new LANA_ENUM