Microsoft KB Archive/269170

= PRB: Set of DEFAULT Changed After MAPI.SESSION Logon =

Article ID: 269170

Article Last Modified on 6/13/2002

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q269170



SYMPTOMS
Programmers often maintain a default directory in Microsoft Visual FoxPro applications. They use this directory for the creation of temporary tables, work files, and so forth. However, if a Microsoft Visual FoxPro application also makes use of MAPI functions to send or receive mail, the default directory may change without warning.



RESOLUTION
In order to maintain the default directory and still use MAPI functionality, store the current directory to a variable and switch back to it after you are finished with the MAPI process with the following code: LOCAL loMAPISession, lcCurDir lcCurDir = SYS(5) + SYS(2003) loMAPISession = CREATEOBJECT(&quot;MAPI.Session&quot;) loMAPISession.Logon loMAPISession.LogOff CD (lcCurDir) RELEASE loMAPISession, lcCurDir
 * !* Create a MAPI Session object, logon then logoff
 * !* Perform mail functions here.



Steps to Reproduce Behavior
To demonstrate this behavior, save the following code to a new program file on a computer with Microsoft Visual FoxPro version 5.0 or higher and Microsoft Outlook.

When it is run, the program will first Change Directory (using the CD command) to the directory in which the program file is located. It then prints the current directory to the screen. The program creates a MAPI.SESSION object, logs in, and then logs out. Finally, the current directory is printed once more: notice that it has changed.

NOTE: This problem also occurs when you choose SEND from the File menu on the main Microsoft Visual FoxPro menu. To demonstrate this, comment the first line in the following code and run it. Close the Compose Mail screen when it appears, and note that the current directory has changed.
 * 1) DEFINE InCode

CD JUSTPATH(SYS(16)) CLEA ? &quot;Current Directory Before Message: &quot; CD

LOCAL loMAPISession *!* Create a MAPI Session object, logon then logoff loMAPISession = CREATEOBJECT(&quot;MAPI.Session&quot;) loMAPISession.Logon loMAPISession.LogOff RELEASE loMAPISession ? &quot;&quot; ? &quot;Current Directory After MAPI Logon: &quot; CD
 * 1) IFDEF InCode

*!* Call the compose mail window via File>Send KEYBOARD '{ALT+F}' KEYBOARD '{D}' DOEVENTS ? &quot;&quot; ? &quot;Current Directory After MAPI Logon: &quot; CD
 * 1) ELSE


 * 1) ENDIF

