Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP office automation - Outlook Quit()
Message
From
28/02/2006 19:26:49
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
 
 
To
28/02/2006 16:19:01
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01100122
Message ID:
01100220
Views:
16
David,

How about CREATEOBJECTEX()?

>I am having a problem quitting outlook opened via
>CREATEOBJECT("OUTLOOK.APPLICATION"). I end up with multiple
>Outlook.exe processes running. Once I get the Outlook MailItems, I cannot make Outlook go away. I am using Outlook 2003.
>
>There are two things I want to accomplish.
>1) If Outlook is already running, use the same instance, AND not quit -
>I would need to know if Outlook is already running, then just don't
>Quit()
>2) If Outlook is not running, I need for it to close/quit and go away.
>As I said, Outlook will quit, as long as I don't access the mail items
>- see the comment in the code below.
>
>Also, if you see anywhere that I can enhance this class, please let me know.
>
>************************************************************************
>
>LOCAL loFolders AS Outlook.Folders, loMessages AS Outlook.MailItem
>
>oMSO = CREATEOBJECT("MSOutlook")
>
>llLogon = oMSO.Logon()  && Logon and set mail folders
>IF NOT llLogon
>	WAIT WINDOW "Logon failed"
>	RETURN
>ENDIF
>
>loFolders  = oMSO.GetMailFolder("Inbox")
>
>* When GetMessages() runs, Outlook.exe no longer goes away - the process remains in memory
>*!*	loMessages = oMSO.GetMessages(loFolders)
>*!*	loMessages = NULL
>*
>loFolders  = NULL
>oMSO       = NULL
>
>RETURN
>
>
>DEFINE CLASS MSOutlook AS CUSTOM
>
>	HIDDEN oOL  && && Outlook object
>	HIDDEN oNS  && && Namespace object
>
>	HIDDEN cMessageStore  && Assign in the subclass, for example "Mailbox - Name"
>
>	PROCEDURE INIT
>		THIS.oOL = CREATEOBJECT("OUTLOOK.APPLICATION")
>
>		RETURN
>	ENDPROC
>
>	PROCEDURE DESTROY
>		IF NOT ISNULL(THIS.oOL )
>			THIS.oOL.QUIT()
>			THIS.oNS = NULL
>			THIS.oOL = NULL
>		ENDIF
>
>		RETURN
>	ENDPROC
>
>	PROCEDURE Logon
>		* log onto the mail system
>		LPARAMETERS tcMessageStore AS CHARACTER
>		PRIVATE lSuccess
>		lSuccess = .T.
>
>		THIS.oNS = THIS.oOL.GetNameSpace("MAPI")
>
>		* Logon.  If there is an error, trap for it and set logon flag.
>		lcOnError = ON("ERROR")
>		ON ERROR lSuccess = .F.
>		THIS.oNS.Logon()
>		ON ERROR &lcOnError
>
>		IF NOT lSuccess
>			RETURN .F.
>		ENDIF
>
>		IF PCOUNT() = 1 AND VARTYPE(tcMessageStore) = "C"
>			THIS.cMessageStore = tcMessageStore
>		ELSE
>			* Assume that the first folder in the namespace is the user's
>			* main folder.
>			lcOnError = ON("ERROR")
>			ON ERROR lSuccess = .F.
>			THIS.cMessageStore = THIS.oNS.Folders("Mailbox - " + THIS.oNS.CurrentUser.NAME).NAME
>			IF NOT lSuccess
>				* Try again, this time, w/o the "Mailbox - "
>				lSuccess = .T.
>				THIS.cMessageStore = THIS.oNS.Folders(THIS.oNS.CurrentUser.NAME).NAME
>			ENDIF
>			ON ERROR &lcOnError
>
>			IF NOT lSuccess
>				RETURN .F.
>			ENDIF
>		ENDIF
>
>		RETURN .T.
>	ENDPROC
>
>	PROCEDURE GetMailFolder
>		* Recurse through the mail folders, until the
>		* folder is found.  Make the folder if necessary.
>		LPARAMETERS tcFolder AS CHARACTER
>
>		LOCAL ;
>			lcCurrentFolder AS CHARACTER
>
>		LOCAL ;
>			loFolder AS Outlook.Folders, ;
>			loMailfolder AS Outlook.Folders
>
>		IF VARTYPE(loFolderCollection) <> "O"
>			PRIVATE loFolderCollection
>			loFolderCollection = THIS.oNS.Folders(THIS.cMessageStore)
>		ENDIF
>
>		lcCurrentFolder = GETWORDNUM(tcFolder, 1, "\")
>
>		loMailfolder = NULL
>
>		FOR EACH loFolder IN loFolderCollection.Folders
>			IF UPPER(loFolder.NAME) == UPPER(lcCurrentFolder)
>				IF GETWORDCOUNT(tcFolder, "\") > 1
>					loFolderCollection = loFolder
>					loMailfolder = THIS.GetMailFolder(SUBSTR(tcFolder, LEN(lcCurrentFolder) + 2))
>				ELSE
>					loMailfolder = loFolder
>				ENDIF
>				EXIT
>			ENDIF
>		ENDFOR
>
>		* Make the folder if it is not found, then continue with next item in path
>		IF ISNULL(loMailfolder)
>			loFolder = loFolderCollection.Folders.ADD(lcCurrentFolder)
>			IF GETWORDCOUNT(tcFolder, "\") > 1
>				loFolderCollection = loFolder
>				loMailfolder = THIS.GetMailFolder(SUBSTR(tcFolder, LEN(lcCurrentFolder) + 2))
>			ELSE
>				loMailfolder = loFolder
>			ENDIF
>
>		ENDIF
>		loFolder = NULL
>		loFolderCollection = NULL
>		RELEASE loFolderCollection
>		RELEASE loFolder
>
>		RETURN loMailfolder
>	ENDPROC
>
>	PROCEDURE GetMessages
>		LPARAMETERS toFolder AS Outlook.Folders
>		LOCAL loFolder AS Outlook.Folders
>		LOCAL loMailItems AS Outlook.MailItem
>
>		loMailItems = NULL
>		loFolder = NULL
>		* Get the messages from the specified folder.  Default to Inbox
>		IF VARTYPE(toFolder) = "O"
>			loMailItems = toFolder.Items
>		ELSE
>			loFolder = THIS.GetMailFolder("Inbox")
>			loMailItems = loFolder.Items
>		ENDIF
>		toFolder = NULL
>		loFolder = NULL
>
>		RETURN loMailItems
>	ENDPROC
>
>	PROCEDURE ScanMessages
>		LPARAMETERS toMailItems AS Outlook.MailItem
>		LOCAL loMailItem AS Outlook.MailItem
>		LOCAL oTherm AS Thermometer OF pr_app
>		LOCAL lnMsgCnt, lnMsgNo, llParsable
>
>		lnMsgCnt = toMailItems.COUNT
>
>*!*			oTherm = CREATEOBJECT("Thermometer", "Scanning messages...", lnMsgCnt)
>*!*			oTherm.VISIBLE = .T.
>
>		* Scan the messages and then process each one.  Start from the
>		* last item, this would be the oldest item.
>		FOR lnMsgNo = lnMsgCnt TO 1 STEP -1
>*!*				oTherm.UPDATE(lnMsgCnt - lnMsgNo + 1)
>			loMailItem = toMailItems.ITEM(lnMsgNo)
>
>			THIS.ProcessMessage(lnMsgNo, loMailItem)
>
>		ENDFOR
>
>*!*			oTherm.COMPLETE()
>*!*			RELEASE oTherm
>
>		RETURN
>	ENDPROC
>
>	PROCEDURE ProcessMessage
>		LPARAMETERS tnEmailNo, toMailItem AS Outlook.MailItem
>
>		RETURN
>	ENDPROC
>
>	PROCEDURE ProcessAttachment
>		LPARAMETERS toAttachment AS Outlook.Attachment
>
>		RETURN
>	ENDPROC
>
>ENDDEFINE
Previous
Reply
Map
View

Click here to load this message in the networking platform