Thanks to several helpful posts by Andre Guirard and others, I was able to piece together a little LotusScript agent that successfully queried Windows XP for any attached WIA-compatible devices and then allowed the user to snap a pic, which was then automatically resized and attached to a rich text field in the currently open document. The agent only relied on wiaaut.dll having first been registered with regsvr32, and it worked great. I’ve pasted it below in case it helps anyone else.
Now my first customer running Windows 7 wants to use this feature in my app, and from what I’ve read online over the past several days, Windows 7 simply does not support wiaaut.dll any longer, only something called WPD or Windows Portable Devices protocol, which I haven’t been able to find any code samples for other than C++ code, which I don’t know how to translate to LotsuScript. So I’m kind of stuck.
Has anyone been able to update their LotusScript code, or write some from scratch, to access an attached webcam in Windows 7 for the purposes of capturing a still photo?
Any help would be greatly, greatly appreciated.
Andrew
Here is my agent that works in XP:
Set devmgr = createobject( “WIA.DeviceManager”)
For c = 1 To devmgr.DeviceInfos.Count
If devmgr.DeviceInfos( c).Type = 2 Or devmgr.DeviceInfos( c).Type = 3 Then ' 2 = Camera, 3 = Video
Set dev = devmgr.DeviceInfos( c).Connect()
Set cdg = Createobject( "WIA.CommonDialog")
' First remove all buffered images from previous sessions
TempPath$ = dev.Properties( 24).Value
TempFilter$ = TempPath$ + "\*.jpg"
fileName$ = Dir$( TempFilter$, 0)
Do While fileName$ <> ""
Kill TempPath$ + "\" + fileName$
fileName$ = Dir$()
Loop
Set cdg = Createobject( "WIA.CommonDialog")
Set img = cdg.ShowAcquireImage( _
3, _
1, _
65536, _
"{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", _
0, _
0, _
0)
' Resize the captured image
Set IP = CreateObject("WIA.ImageProcess")
IP.Filters.Add IP.FilterInfos("Scale").FilterID
IP.Filters(1).Properties("MaximumWidth") = 200
IP.Filters(1).Properties("MaximumHeight") = 100
Set Img = IP.Apply(Img)
If img Is Nothing Then ' they clicked cancel
Exit Sub
End If
' save the pic to hard disk with the filename D09679A7EF130E7988256FF4000A5265-08-18-2009 03-46-42 PM PDT.jpg
' where those first 32 chars are what's in the DOCID field of the currently open document
Dim dtNow As New NotesDateTime( Now)
strDate$ = dtNow.LocalTime
varDate = Evaluate( |@ReplaceSubstring( "| + strDate$ + |"; ":" : "/"; "-")|)
strDate$ = Cstr( varDate( 0))
Dim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace
Set uidoc = ws.CurrentDocument
Dim strFilePath As String
strFilePath = session.GetEnvironmentString( "MyAppTempDirPath") + "\" + uidoc.Document.DOCID( 0) + "-" + strDate$ + ".jpg"
Call img.SaveFile( strFilePath)
Call uidoc.GotoField( "Picture")
Call uidoc.Import( "JPEG Image", strFilePath)
intID = Shell( |cmd /c del "| + strFilePath + |"|) ' delete the temp file from hard disk
Call uidoc.GotoNextField
Exit For ' no need to look for any more devices
End If
Subject: Has anyone figured out how to access a webcam from LotusScript in Windows 7?
I haven’t actually done it, no – but by carefully looking through the MS documentation, I did manage to run across a carefully-hidden* COM interface for WPD:
That should get you around unpleasantries like faking unsigned ints and LPTRSTRs in LS (or the need to develop a DLL to mediate access).
By “carefully-hidden”, I mean that the documentation pretty much states that the only access path you’d use to the COM/OLE interface is JScript. I guess the idea that VBA or other non-.NET languages might be involved kinda slipped their minds.
Subject: RE: Has anyone figured out how to access a webcam from LotusScript in Windows 7?
Stan,
Thank you very much for your response. I know once I read through the Programming Guide, scan the Reference and familiarize myself with the Object Model itself I’ll be in good stead to tackle the specifics of my implementation.
I just have one more favor to ask from you, please… since I don’t have a clue where to begin when it comes to how all this would actually be implemented in a LotusScript environment, could you possibly show me what a simple stub to access these objects would look like?
In other words, I’ve got this short script so far:
Dim window As Variant
Dim deviceObject As Variant
Dim servicesCollection As Variant
Dim service As Variant
set window = _____________? <<<<<<<<<<<<<
Set deviceObject = window.external ' I see this line in the reference, but how do I get access to 'window' first?
Set servicesCollection = deviceObject.Services
For i = 0 To servicesCollection.Count
service = servicesCollection( i)
Next i
So as you can see, I don’t know how to get a handle to window to kick things off.
Any help you can offer to get me started would again be greatly appreciated.
Subject: RE: Has anyone figured out how to access a webcam from LotusScript in Windows 7?
“window” is the global object in JScript and “window.external” is the method of hopping out of the browser (or app window) context to address the rest of the system; it won’t apply to LotusScript code. Unfortunately, the WPD Automation documentation has only this to say about instantiating the top-level WPD object from COM:
“WPD Automation can be instantiated from C++/COM outside of script. Because the IDispatch interface was specifically designed for use by script, this approach is somewhat cumbersome and not recommended. However, the approach can offer a simplified way of programming against WPD; it is not explained further in this documentation.”
Obviously, there is an IDispatch (COM) hook that should be accessible from outside of JScript (and IDispatch means that it’s likely registered as a COM server with regsvr32); it’s just a matter of finding out the magic spell. That’ll probably mean a trip to MS support. Sorry I can’t be of more help, but I don’t have a working Notes/Designer setup to play with at the moment.