For a small project which requires a custom made DLL for a Lotus Notes database, I have to deploy this custom DLL to the user's workstations in order for the application to work. I've decided to attempt doing it from within the Lotus Notes Database Script, in the PostOpen event. This event is trigerred when the database is opened.

Sub Postopen(Source As Notesuidatabase)
    Call ExtractDLL("mycustom.dll")
End Sub

The database itself contains a hidden view (dll) keyed on dllname in it. The forms have a rich text field on them (dllbody) into which a DLL is attached. What the sub ExtractDLL now does is to first check if the DLL exists on the user's workstation, and if it doesn't, it searches for the first document in the view that matches the name of the file to extract, retrieves the attachment and dumps it into the Lotus program directory.

Sub ExtractDLL (Byval dllname As String)
    ' Copy the required DLL to the user's workstation (Win32 only!)
    ' Find the first document called dllname$ in the hidden view
    ' (dll). Attempt to determine the Lotus Notes program directory
    ' name and extract the first attachment in that document to it.
    ' Currently, if the file exists, it is not overwritten.
    Dim s As New NotesSession
    Dim db As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim targetpath As String
    Dim notesdir As String
    notesdir$ = getNotesProgramDirectory()
    targetpath$ = notesdir$ & "\" & dllname$
    If Dir(targetpath$) <> "" Then
        Print dllname$ & ": " & targetpath$ &" already exists on this workstation."
        Dim obj As NotesEmbeddedObject
        Dim rtitem As NotesRichTextItem
        Set db = s.currentdatabase
        Set view = db.GetView("(dll)")
        Set doc = view.Getdocumentbykey(dllname$)
        Set rtitem = doc.GetFirstItem("dllbody")
        Set obj = rtitem.EmbeddedObjects(0) 
        If (obj Is Nothing) Then
            Print dllname$ & ": Error: No DLL found in this database."
        End If    
        ' DLL does not exist. Detach it
        Print targetpath$ & " is being extracted to your workstation"
        Call obj.extractFile(targetpath$)        
    End If
End Sub

ExtractDLL utilizes Rocky Oliver's getNotesProgramDirectory() function to determine the directory in which Lotus Notes is installed. That is the directory into which the DLLs are dropped. If you have to deploy more than one DLL, just set up the documents which their attachments accordingly and invoke several calls to ExtractDLL, specifying the name of each DLL in turn. Unfortunately, this is not "real" software deployment, as it doesn't cater for updated file versions, but it has helped me in this pinch.

Flattr this
DomiNotes :: 08 Nov 2006 :: e-mail


blog comments powered by Disqus