PP_SEMOPEN()

Opens the Network Semaphore File in exclusive mode

Applies to:

Win32, Win64

Syntax-VB:

Declare Function pp_semopen(ByVal handle As Long, ByVal flags As Long, ByVal prefix_server As String, ByVal name As String, ByRef semhandle As Long) As Long

Syntax-C:

LONG pp_semopen(LONG handle, LONG flags, LPSTR prefix_server, LPSTR name, LPLONG semhandle)

Arguments:

<handle> is the handle to the License File given by pp_lfopen()

<flags> reserved - set to zero

<prefix_server> is the complete path to the Network Semaphore Files of the server counting the number of simultaneous users

<name> is a four-character identifier to use to count the workstations

<semhandle> is the buffer in which to place the Network Semaphore File handle

Returns:

Refer to pp_errorstr() for a table of possible return codes and their meaning. Typically, PP_SUCCESS [1] (file was opened) is returned. A numeric value that represents a handle to this Network Semaphore File is returned in <semhandle>. This handle is used with pp_semclose() to close the defined file.

Description:

This function attempts to secure the next available workstation license. Currently, only the type of SEM_FILE counting is available. The parameter <prefix_server> contains the complete path to the network semaphore files, INCLUDING a trailing backslash (\) character. The <name> parameter contains the first 4 characters of the semaphore files. The semaphore files will be created as necessary until the workstation limit has been reached. Be sure not to modify the value of the <semhandle> or unpredictable results may occur.

The handle returned by this function is not to be confused with the handle used by the License File. Unlike the License File, this file is kept open in the exclusive mode until it is closed.

The semaphore files are named by the path and prefix you choose. The files are numbered starting at 0 through 9999 and are zero padded with a file extension of .net. An example list of files using "f:\appname\data\" for <prefix_server> and "sema" for <name> is:

f:\appname\data\sema000.net
f:\appname\data\sema001.net
.
f:\appname\data\sema9999.net

This function will attempt to open and secure a license from the semaphore files in the given path for the number of workstations that is in the License File field "number of allowed users." It ignores the field "number of current users" when determining ERR_NET_LIC_FULL.

Note that in large network installations, the time delay for each workstation will increase as the semaphore files are scanned for the next available license.

Example:

' Attempt to open a network semaphore file

' lfhandle contains the License File

' handle which was initialized earlier.

Dim rc As Long, semhandle As Long

rc = pp_semopen(lfhandle, 0, "m:\appname\data\", "sema", semhandle)

If rc = ERR_NET_LIC_FULL Then

 MsgBox "No more licenses available, try later"

 End

ElseIf rc <> PP_SUCCESS Then

 MsgBox "Encountered error number " & Str(rc)

 End

End If

' Continue with program execution

. . .

' At the end of your program

rc = pp_semclose(semhandle)

If rc <> PP_SUCCESS Then

 MsgBox "Encountered error number " & Str(rc)

 End

End If

See Also:

PP_SEMCLOSE() and PP_SEMCOUNT()

Related Topics