Tip #11: some Win32 stuff 01 Apr, 2003
As you can see from the "Further reading" section, I've published a few articles on this site that cover Lotusscript versions of Win32 API calls. This kind of stuff can be really useful. For example, you can use the Windows API to:
- get a handle on and change the current machine's registry
- add navigation options to your applications (e.g. pop-up menus)
- change other machine environment options such as printer settings
- browse for folders using a standard OS dialog box
- provide a functional version of
There are many more applications for the API, and I would recommend getting hold of something like the AllAPI reference to see what calls are available to you. In dealing with API calls, my current favoured approach is to wrap the Windows functions in standard Lotusscript functions. Yes, it's another layer of abstraction, but there are no real penalties in terms of performance, and it makes things far simpler in the long run.
Many of the functions typically used result in some kind of string: a directory path, a file name, and so on. In these instances, the Windows functions often add a trailing space to the result, which needs to be trimmed to be of any use to you. It's nice to have a standard function to get rid of this, and you'll find one in the attached file.
Adapting code for Lotusscript
Lotusscript is broadly compatible with Visual Basic, and so most functions can be fairly easily tweaked to work from Lotusscript. Read through the Win32 API articles here, and look at code posted either in the Sandbox or the forums at the Lotus Developer Domain to see more examples. Once you've done a couple, I think you'll find it that "translating" the Win32 functions becomes a handy addition to your toolset. Also, bear in mind that you'll need the very simple
GetActiveWindow function for just about everything. ;-)
So, what am I offering today? The attached Lotusscript source file contains all the declarations, code and functions to do two things. It demonstrates how a standard Win32 call, GetUserProfileDirectory, has been wrapped in Lotusscript, together with a simple function to trim excess white space from the resulting string buffer, as mentioned above. The
getUserProfileDir function returns the current user's home directory path (e.g. "c:\documents & settings\%USER%"), which I've found to be a great when dealing with attachments or Notes-based installers. The other function, the one that trims the white space, is called
trimBuffer and constitutes a handy addition to one's code "toolbox". Have fun!