PRB: Current Directory Changes After OL2000 Installation (245557)



The information in this article applies to:

  • Microsoft Extended Messaging Application Programming Interface (MAPI)
  • Microsoft Outlook 2000

This article was previously published under Q245557

SYMPTOMS

After installing Microsoft Outlook 2000, a call to MAPIInitialize (or anything that calls MAPIInitialize such as a CreateObject("MAPI.Session") call in CDO) causes the current directory to change to the directory where the Microsoft Outlook 2000 installed MAPI subsystem into.

MORE INFORMATION

Workaround

Begin by assuming the directory will change. First thing to do in the application is to select your current directory. Then, make a call to MAPIInitialize thereby forcing the directory to change. Finally, calculate a relative path between the two.

The following CDO code written in Microsoft Visual Basic and Extended MAPI code written in Microsoft Visual C++ can be used to reproduce this issue:

Visual Basic Code to Reproduce Issue:
' This sample assumes a reference to the CDO library. 
'
Dim objSess As MAPI.Session

Sub Main()
    'Display the default drive and dir, as well as that on C: and D:
    MsgBox "Def: " & CurDir & vbCrLf & _
           "Drive C: " & CurDir("C") & vbCrLf & _
           "Drive D: " & CurDir("D")

    'The following line of code will result in default drive and dir
    'changing. This is a major problem for apps that depend on relative
    'pathing.
    Set objSess = CreateObject("mapi.session")

    'Note drive and dir is different than on first msgbox
    MsgBox "Def: " & CurDir & vbCrLf & _
           "Drive C: " & CurDir("C") & vbCrLf & _
           "Drive D: " & CurDir("D")
End Sub
				

Visual C++ Code to Reproduce Issue:

#include "windows.h"
#include "mapix.h"
#include "stdio.h"

void main()
{
	char	sDir[MAX_PATH];

	if(GetCurrentDirectory(MAX_PATH, sDir))
	{
		printf("Starting : %s\n", sDir);
	}

	HRESULT hr = MAPIInitialize(NULL);

	if(GetCurrentDirectory(MAX_PATH, sDir))
	{
		printf("Post Init: %s\n", sDir);
	}

	LPMAPISESSION	pSession = NULL;

	hr = MAPILogonEx(NULL, NULL, NULL, MAPI_LOGON_UI, &pSession);

	if(GetCurrentDirectory(MAX_PATH, sDir))
	{
		printf("Post Logon: %s\n", sDir);
	}
        
         pSession->Logoff(0, 0, 0);
	if (pSession) pSession->Release();

	MAPIUninitialize();
}
				

This behavior has also been reported to occur on calls to other MAPI functions besides MAPIInitialze.

Modification Type:MinorLast Reviewed:8/25/2005
Keywords:kbMsg kbprb KB245557