SnTT: Calling the Active Directory "Pickers" from LotusScript.

This will probably be my last Show-and-tell Thursday story for 2006, so I thought I'd finish with a cracker.

As part of the ongoing development of our product - FirM - we're increasingly adding more and more Active Directory integration. As a result of this, we need to prompt the end-users for active directory objects. Such as allowing a user of our application to select a user from a particular container, etc.

This stuff is *hard* to do in native Lotusscript... For example, I spent about three weeks using COM object calls ("GetObject" and the like) to make Active Directory calls using the ASDI interface. I'd then use the results of these calls in forms to show the user a sort of "browser", where they could select users, groups and suchlike. There were a couple of downsides to this. Because ultimately I had to feed these results back into a Notes form text field, I was limited to about 200 objects at a time. Cue complete heart-failure at customer site when they had 1,000 users in a container. So obviously that had to change. And also, because I did it in notes (and as you may have gathered my graphical skills are somewhat limited), it was butt-ugly. Not good.

MS-AD-ContainerPicker.pngSo lets fall back onto the Microsoft Active Directory Container and Object Pickers. They're built right into each Active Directory environment, so should be straightforward to call, right ?

Ah. No. The Container picker uses some funky C-structure that is *difficult* but not impossible to call from Visual Basic/LotusScript. However, the DSObjectPicker interface is multi-threaded and uses a callback function. Some people have tried - I spent two days on google looking for some positive news on this front. But no.

Lots of Examples in C, and C#. Looks like MS's preferred programming language going forward is going to be C#. This doesnt help us however, as I suspect C# will never be a supported language within Lotus Notes.

lsxwizard.pngSo what do to ? Well, based on a presentation I gave for the View Developer 2006 conference in Vegas and Vienna called "Calling the C-API From LotusScript", I knew I was in a world of pain. I had an option - the LSX toolkit. This allows you to write low-level C-Code or C++ Code and wrapper it, such that it looks like a LotusScript class. So far, so good. Then came the pain of integration MS dot-net v2.x libraries, and of course compiling this. Now - the LSX toolkit v3.1 was last released a number of years ago, and works quite happily on Visual C++ v6, and in MS Visual Studio 2003. It doesnt work at the moment in Visual Studio 2005, though I know there's some desire by individuals within IBM to get it running at some stage. It's not a heavily supported area, so I cant expect folks to drop Hannover development to help me out. So Visual Studio 2003 it was.

As the Screenshot shows, its a case of defining how you wish LotusScript to see your code. The LSX toolkit then generates the thousand-or so lines of wrapper code. Within Visual Studio 2003, its a case of inserting code between clearly commented sections - allowing you to change the definition of the LSX at a later date without losing code. Neat.

Then its a case of compiling the LSX, copying it into your Notes Program directory and testing some code against it. Like all good C-Programmers, the red-box-of-death is now seen as an occupational hazard and not a suicide-provoking trauma, and thus finally debugged.

From within LotusScript, we can now call the AD Object picker with:

Dim ADP As New FirmADPicker

adp.Title = "Please select a target user container" ' The title on the dialog box

adp.Caption = "User Container" ' The caption on the dialog box

Dim targetContainer As String

targetContainer = ADP.BrowseForContainer()

After all that explanation I have some pride in annoucing that our company - HADSL - are releasing the LSX, and the source code (and example database) to the world as open-source software. So please head across to the HADSL website and download it from here