Wednesday, November 25, 2009

Differences between Lotus Notes C API and C++ API

We always have few options if we need to do with Lotus Notes something externally. Here I'll try to provide a brief comparison chart of Lotus Notes CAPI and CppAPI. I hope this brochure can help to do the right choice before going deep into the water.

Lotus Notes CAPI
Lotus Notes CppAPI
Complex code, requires high attention during development because it works with raw memory pointers. So without experience it's very easy to produce memory leaks and access violations.
Simple code, it's very similar to Lotus Script and Java APIs.
Procedural code.
Object oriented code.
Notes uses it internally, so no dependency files required to install.
CppAPI requires lcppnXX.dll, there XX is a version of CppAPI. While this dll has versioning info most functionality is compatible across Lotus Notes versions. So lcppn70.dll is working with Lotus Notes 6.5 and Lotus Notes 8.5.1 Standard.
Can be coded anything so it can work much like it was a built-in feature of Lotus Notes.
There are limitations introduced by CppAPI implementation. It's obvious because CppAPI built on CAPI. In most cases it's the same limitations as in LotusScript or Java API. So if you can't do something in LotusScript and you like to move to a lower level than CppAPI is not your option. A good example of such limitations is a memo with attachment. While it's only few lines of code using CppAPI, this memo doesn't look good in Notes because there is no icon thumbnail, just a gray rectangle. With CAPI there will be 300-400 lines of code to add an attachment and to represent it as an icon inside of memo body. It's complex, but memo will look like the one created in Lotus Notes by a real user.
Strings represented in form of special LN Multibyte string (LMBCS). While in the code it looks like a normal ANSI string of type "char *" it can contain zeros inside and encoded non ANSI symbols. It's very easy to miss a large part of text and break international symbols if you apply standard C functions like strcat or strcpy. I'll write in the next post how to work with Lotus strings in CAPI to preserve international symbols and handle zeros in the middle of the string.
LNString class handles lotus strings just perfect. It has methods for string concatenation, searches, substring extraction, etc. It can return a pointer to the platform one byte character set encoding of the string. However it's still better to convert LMBCS to Unicode if you need to pass it outside of Lotus, and it's missing in CppAPI.

Here is a sample code of the same functionality in Lotus CAPI and CppAPI. The code opens Lotus database.

void CppApiCode()
{
 LNNotesSession session;
 session.Init();
 LNString databasePath = "special\\testdb.nsf";
 LNString serverPath;
 LNDatabase docDB;
 session.GetDatabase(databasePath, &docDB, serverPath);
 // Open the database.
 docDB.Open();
 ...
 docDB.Close();
}

void CApiCode()
{
 STATUS error = NotesInitExtended();
 DBHANDLE hDB = 0;
 char szFileName[] = "special\\testdb.nsf";
 char szServerName[] = "";
 char szDbPath[MAXPATH+1];
 error = OSPathNetConstruct(0, szServerName, szFileName, szDbPath);
 // Open the database.
 error = NSFDbOpen(szDbPath, &hDB);
 ...
 NSFDbClose(hDB);
}

2 comments:

  1. im trying to write a windows service which logs into Notes and downloads messages from a particular notes database.

    The service expects that the notes client is running for it to automatically login. is there anyway in the api to pass the password as a parameter to login ?

    ReplyDelete
  2. Business intelligence Analyst
    SQIAR (http://www.sqiar.com/services/bi-strategy/) is a leading Business Intelligence company.Sqiar Provide business intelligence Services Which help the company to present Information in Meaningful form.

    ReplyDelete