Results 1 to 2 of 2

Thread: Mutex

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2001
    Location
    Vietnam
    Posts
    613

    Mutex

    I am trying to create a Mutex object using the API:
    Code:
    Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
    So far without success. Have you done it before. Please help.

    Regards.

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Here is an example of how to use than function:
    VB Code:
    1. 'This code must be pasted into a module
    2. 'Set the project's startup object to 'Sub Main' (-> Project -> Project Properties -> General Tab -> Startup Object)
    3. Public Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
    4. Public Type SECURITY_ATTRIBUTES
    5.         nLength As Long
    6.         lpSecurityDescriptor As Long
    7.         bInheritHandle As Long
    8. End Type
    9. Public Const ERROR_ALREADY_EXISTS = 183&
    10. Private Sub Main()
    11. Dim sa As SECURITY_ATTRIBUTES
    12.     sa.bInheritHandle = 1
    13.     sa.lpSecurityDescriptor = 0
    14.     sa.nLength = Len(sa)
    15.     'Try to create a new Mutex
    16.     Debug.Print CreateMutex(sa, 1, App.Title)
    17.     Debug.Print Err.LastDllError
    18.     'Check if the function was succesfull
    19.     If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
    20.         'More than one instance detected
    21.         MsgBox "More than one instance"
    22.     Else
    23.         'No other instance detected...
    24.         'Your program-load code here
    25.     End If
    26. End Sub
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width