COM-API: Commands & Notifications

In EPLAN 21 API C-functions are used as callbacks or handlers. Using the eplRegisterNotificationHandler function you can e.g. register a C-function which is called up when a certain notification is being sent. The eplRegisterCommandHandler function is used in a similar way for recording a C-function as command handler. The interface for a notification handler has the following form:

interface INotificationHandler


Sub notificationHandler(session          As EplSession,
                        notificationName As String,
                        clientData       As Long,
                        param            As EplHandle)

                                               

The parameters of the procedure have the same meaning as those of the corresponding callback function in C-API.

The interface for the command handler is similar:

interface ICommandHandler


Sub commandHandler(session     As EplSession,
                   commandName As String,
                   param            As EplHandle)

                                               

In Visual Basic such an interface can be implemented by the key word implements. In the following example the implementation of two Visual Basic classes is shown which implement an add-in, a notification handler, as well as a command handler. ActiveX DLL was chosen as VB project.

Example

Class1:
Implements EPLAPILib.IEplanAddIn

Public Sub IEplanAddIn_initialize()
       Dim s As EplSession
       Dim regCmd As EplHandle

       Dim gen As New EPLAPILib.Generic

       s = gen.createSession

       Dim handler As New Class2

       gen.registerCommandHandler s, "TEST.COMMAND03", handler
       gen.registerNotificationHandler s, "TEST.NOTIFICATION03", 0, handler

       regCmd = gen.createCommand(s, "EPLAN.EPLAN21.ADDIN.REGISTER")

       ' -1 = EPL_ERROR
       If regCmd <> -1 Then
               ' 15162 = EPL_PARAM_ADDIN_REGISTER_MENUNAME
               gen.setParam s, regCmd, 15162, "TestCommand03", 1
               ' 15165 = EPL_PARAM_ADDIN_REGISTER_MENUHANDLER
               gen.setParam s, regCmd, 15165, "TEST.COMMAND03", 1

               If gen.executeCommand(s, regCmd) = -1 Then
                       MsgBox "Registration failed"
               End If

               gen.closeObject s, regCmd
       End If

       gen.destroySession s
End Sub

Public Sub IEplanAddIn_deinitialize()
       ' Nothing to do...
End Sub

Class2:
Implements EPLAPILib.ICommandHandler
Implements EPLAPILib.INotificationHandler

Public Sub ICommandHandler_commandHandler(ByVal session        As EplSession,
                                          ByVal commandName    As String,
                                          ByVal param                As EplHandle)
       MsgBox "TEST.COMMAND03 called"

       Dim ret As EplHandle
       Dim notificationCmd As EplHandle
       Dim epl As New EPLAPILib.Generic

       notificationCmd = epl.createCommand(session, "EPLAN.EPLAN21.NOTIFICATION.SEND")
       If notificationCmd <> -1 Then
               ' EPL_PARAM_NOTIFICATION_NAME = 15016
               epl.setParam session, notificationCmd, 15016, "TEST.NOTIFICATION03"

               ret = epl.executeCommand(session, notificationCmd)

               If ret = -1 Then
                       MsgBox "Error: " & Str(ret)
               End If

               epl.closeObject session, notificationCmd
       End If
End Sub

Public Sub INotificationHandler_notificationHandler(ByVal session              As EplSession,
                                                    ByVal notificationName     As String,
                                                    ByVal clientdata           As Long,
                                                    ByVal param                As EplHandle)
       MsgBox "Caught API-Notification"

       Dim gen As New Generic
       Dim iter As EplHandle
       Dim iterType As EplIterType

       iterType = ITERTYPE_PROJECTS
       iter = gen.openIterator(session, -1, iterType)
       gen.closeObject session, iter
End Sub