Programm crashes with Outlook 2010

Jul 3, 2011 at 10:04 AM
Edited Jul 3, 2011 at 10:04 AM

Hello community!

I have a dll to connect to the address book of Outlook. The dll works fine on Outlook 2003, 2007 but not on Outlook 2010.

When I want to close the main exe programm the Visual Studio returns a failure and the debugger jumps to following position:

dbghook.c

void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
{
    /* assign 0 to _debugger_hook_dummy so that the function is not folded in retail */
    (_Reserved);
    _debugger_hook_dummy = 0;
}

This is my function to test the connection to Outlook:

BOOL ConnectOutlook(LPTSTR lpstrProfileName, LPTSTR lpstrProfilePwd)
{
	BOOL bReturn = FALSE;
	HRESULT hRes = NULL;
	LPMAPISESSION lpSession = NULL;
	LPADRBOOK lpAdrBook = NULL;
	ULONG ulObjType = 0;
	LPABCONT lpABContainer = NULL;
	LPMAPITABLE lpTableRoot = NULL;

	hRes = MAPIInitialize(NULL);
	if(hRes != S_OK)
	{
		goto cleanup;
	}

	hRes = MAPILogonEx(NULL, lpstrProfileName, lpstrProfilePwd, MAPI_EXTENDED | MAPI_NEW_SESSION |
		MAPI_EXPLICIT_PROFILE | MAPI_UNICODE | MAPI_MULTITHREAD_NOTIFICATIONS, &lpSession);
	if(hRes != S_OK)
	{
		goto cleanup;
	}

	hRes = lpSession->OpenAddressBook(0, NULL, 0, &lpAdrBook);
	if(hRes != S_OK)
	{
		goto cleanup;
	}

	hRes = lpAdrBook->OpenEntry(0, NULL, NULL, 0, &ulObjType, (LPUNKNOWN*)&lpABContainer);
	if(hRes != S_OK)
	{
		goto cleanup;
	}

	hRes = lpABContainer->GetHierarchyTable(MAPI_UNICODE, &lpTableRoot);
	if(hRes != S_OK)
	{
		goto cleanup;
	}

	bReturn = TRUE;

cleanup:
	if(lpTableRoot)
	{
		lpTableRoot->Release();
	}

	if(lpABContainer)
	{
		lpABContainer->Release();
	}

	if(lpAdrBook)
	{
		lpAdrBook->Release();
	}

	if(lpSession)
	{
		lpSession->Logoff(NULL, NULL, NULL);
		lpSession->Release();
	}

	MAPIUninitialize();

	return bReturn;
}

 Can someone help me, please?

Coordinator
Jul 5, 2011 at 1:27 PM

What's the call stack of the crash?

Jul 5, 2011 at 2:26 PM

Now I know the cause of my problem. I have a file logging in the background and the mapi session changes the result of the getcurrentdirectory function. Thanks for your reply.