Notes Crash

I am trying to connect Lotus Notes with Sage Payroll, the main problem is that I cannot use a COM object like this:

Public oPayrollSDO As New PAYSDOLib.Connection

I have to use the CreateObject method which is fine, but when I try to pass Company Object as a parameter, it’s not accepted (notes throws an error) since oCompany is a variant in Notes and the method expects oCompany object:

oPayrollSDO.GetCompany oCompany

In order to get around this problem, I created a VB6 ActiveX DLL with the following code, but ran into problems:

Public oPayrollSDO As New PAYSDOLib.Connection

Public oCompany As PAYSDOLib.Company

Public oPayment As New PAYSDOLib.Payment

Public oLastError As New PAYSDOLib.LastError

Public Sub ConnectToPayroll(strPath As String)

’ Error Handler

On Error GoTo ErrorHandler

oPayrollSDO.ConnectToDatabase strPath, “MANAGER”, “”

Exit Sub

’ Error Handling Code

ErrorHandler:

MsgBox ("Payroll SDO has generated the following error: " & oLastError.Value & " " & oLastError.Text)

End Sub

Public Sub DisconnectFromPayroll()

Call oPayrollSDO.Disconnect



Set oPayrollSDO = Nothing

Set oCompany = Nothing

Set oPayment = Nothing

Set oLastError = Nothing

End Sub

Public Sub CreatePayment()

' Get Company from Connection Object

oPayrollSDO.GetCompany oCompany



' Get Payments Collection

oCompany.GetPayment oPayment

End Sub

Here’s how I call it from Lotus Notes:

Sub Click(Source As Button)

Dim oGeneric



Set oGeneric = CreateObject("PayrollSDK.Generic")



Call oGeneric.ConnectToPayroll("C:\ProgramData\Sage\Payroll\COMPANY_001\PAYDATA\Payroll.mdb")



oGeneric.CreatePayment



oGeneric.oPayment.MoveToReference 1

Msgbox oGeneric.oPayment.Reference + " - " + oGeneric.oPayment.Description



oGeneric.oPayment.MoveNext

Msgbox oGeneric.oPayment.Reference + " - " + oGeneric.oPayment.Description



oGeneric.DisconnectFromPayroll



Set oGeneric = Nothing

End Sub

It works, but unfortunately at the end once the code has finished executing Lotus Notes crashes. Any insight into this would be greatly appreciated.

Subject: RE: - Further info

I have found the cause of the problem, it’s this method:

Public Sub CreatePayment()

’ Get Company from Connection Object

oPayrollSDO.GetCompany oCompany

’ Get Payments Collection

oCompany.GetPayment oPayment

End Sub

Would appreciate some insight from COM developers about this issue.

Subject: Passing objects to COM methods

I’ve never been able to pass class objects to or return them from COM methods. These methods normally require a strictly typed object which LotusScript cannot provide.

Instead, I normally write a COM ‘wrapper’ for the service that I need to access via LotusScript, then pass serialized objects to and from my ‘wrapper’.

For example, I would use C# or VB.net to write a COM dll that contains all of the functionality needed by your Notes app. If you need to pass or return an object from your wrapper, pass or return it as XML.

Subject: Passing objects to COM methods

Thanks Bill, appreciate your comments. I will write an external application which uses the Notes COM model, to get around this particular issue.