Private Declare Function SE_instance_free_locks Lib "sde30"
(ByReflock_list_address As Long, ByVal lock_count As Long) As Long
Private Declare Function SE_instance_get_locks Lib "sde30" (ByVal serverAs
String, ByVal instance As String, ByRef address_to_array_of_lock_list_addr As
Long, ByRef lock_count_addr AsLong) As Long
Private Sub Command1_Click()
Dim status As Long
'set by SDE
Dim lock_list_addr As Long
'set by SDE API call
Dim sde_lock_count As Long
'set by SDE API call
Dim lock_list_addr_save As Long
'needed to free the list array later
Dim m_lockCount As Integer
'loop iterator
'get the locks from SDE
status = SE_instance_get_locks("drfinlay", "esri_sde", lock_list_addr, sde_lock_count)
' Report the status, list array address and number of locks
Text1.Text = "SDE Error status: " & Str(status)
Text2.Text = "Lock List Address: " & Str(lock_list_addr)
Text3.Text = "Lock Count: " & Str(sde_lock_count)
' save the list address
lock_list_addr_save = lock_list_addr
' declare an array of 200 (max)
SE_INSTANCE_LOCK structures
Dim myLocks(200) As SE_INSTANCE_LOCK
' declare an instance of a
single lock - used to get the size in Bytes of the structure
Dim aLock As SE_INSTANCE_LOCK
' iterate through all the locks
For m_lockCount = 0 To sde_lock_count - 1
' copy memory from the list array address into myLocks(n), using the length in Bytes
' of a single SE_INSTANCE_LOCK
CopyMemory myLocks(m_lockCount), ByVal lock_list_addr,LenB(aLock)
' Report the details of the nth element of myLocks
MsgBox "Layer ID : " & vbTab & Str(myLocks(m_lockCount).layer_id) & vbNewLine & _
"Lock Type: " & vbTab & Str(myLocks(m_lockCount).lock_type) & vbNewLine & _
"Pid: " & vbTab & vbTab & Str(myLocks(m_lockCount).pid), vbDefaultButton1, "SDE Lock Details"
'increment the lock list array address by the length of a SE_INSTANCE_LOCK structure
lock_list_addr =
lock_list_addr + LenB(aLock)
Next m_lockCount
' free the instance locks list array - using the previously saved address
status =
SE_instance_free_locks(lock_list_addr_save, sde_lock_count)
End Sub
Private Sub Form_Load()
Command1.Caption = "Get all SDE locks"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Form1.Caption =
"SDE Instance Locks example"
' set up MapObjects SDE connection
dc.server = "drfinlay"
dc.User =
"sde_user"
dc.Password =
"sde_user"
dc.Database = "esri_sde"
dc.Connect
End Sub