Intialization of Notes Session using the C++ API

Hi,

there’s something i don’t really understand with the initialization of Notes sessions with the C++ API (version 2.4, compiling with Visual Studio 6.0 under Windows 2000 SP2).

The documentation says that the LNNotesSession::Init() function must be called by a parent process in a program, and then LNNotesSession::InitThread() for all subsequent threads.

I’m running my program in a multi-threaded environment. First an initialization function function is called in a first thread (I’m not sure whether that’s the parent thread or not, is that relevant??). This function creates a Notes session, and initializes it using LNNotesSession::Init(). Then another thread is created, which will actually use this Notes session. Here’s how the code looks like:

/* first thread, creation and initialisation of the Notes session */

cerr << "initialising notes session in thread " << GetCurrentThreadId() << endl;

try {

_notesSession.Init();

}

catch( LNSTATUS lnerror ) {

char    errorBuf[ 256 ];

errorBuf[ 0 ] = '\0';

LNGetErrorMessage( lnerror, errorBuf, 256 );

cerr << "Error " << lnerror << ": " << errorBuf << endl;

return;

}

cerr << “notes session initialised” << endl;

/* end of the function */

/* … */

/* second thread, makes use of the Notes session */

cerr << "now in thread " << GetCurrentThreadId() << endl;

try {

if( !_notesSession.IsThreadInitialized() ) {

    cerr << "session has not been initialized in thread" << endl;

    _notesSession.InitThread();

}

else {

    cerr << "session has already been initialized in thread" << endl;

}

}

catch( LNSTATUS lnerror ) {

char    errorBuf[ 256 ];

errorBuf[ 0 ] = '\0';

LNGetErrorMessage( lnerror, errorBuf, 256 );

cerr << "Error " << lnerror << ": " << errorBuf << endl;

return;

}

cerr << “done initializing session in thread (initializeThread)” << endl;

/* end of the function */

Now when I run this, I get the following output:

initialising notes session in thread 2360

notes session initialised

now in thread 2372

session has not been initialized in thread

Error 3221225484: Notes session has already been initialized

which shows that though LNNotesSession::IsThreadInitialized() returned false, I get an error because it seeems that the session has already been initialized.

If I try to go on anyway, I get a very “funny” error when I try to open a database, namely an exception is thrown even if I haven’t set ThrowAllErrors. The exception is not a LNSTATUS exception, nor a standard windows exception – can’t get caught by any of these two patterns… I don’t know if these problems are related, but I can’t focus on the latter as long as I haven’t understood the former.

Any help would be much appreciated.

Thx,

David