Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a call to MAPILogonEx that is throwing an exception.
First-chance exception at 0x2038325f in FileMail.exe: 0xC0000005: Access violation reading location 0x2038325f.

The documentation[^] doesn't mention anything and since it is an access violation, I expect that I have some kind of linking mismatch, or worse, a corrupt run-time DLL. Anyone have a thought on a next step to dig further into solving this one. Thanks.

I've put a test program together that nails the problem, but still leaves me shaking my head. I've a simple Win32 console app with MFC support and the call to MAPILogonEx throws an exception when the command line parameters are 4317 characters in length. If they are 4316 or less, no problem. Go over that length and the exception happens. Here is the code.

The sfdafx.h file
#ifndef WINVER              // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501       // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT        // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINDOWS      // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE           // Allow use of features specific to IE 6.0 or later.
#define _WIN32_IE 0x0600    // Change this to the appropriate value to target other versions of IE.
#endif

#include <stdio.h>
#include <tchar.h>
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS  // some CString constructors will be explicit

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN        // Exclude rarely-used stuff from Windows headers
#endif

#include <afx.h>
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>         // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <iostream>

// TODO: reference additional headers your program requires here
// for MAPI
#include <mapix.h>
#include <objbase.h>


And here is the main cpp
#include "stdafx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;
	CString		arg		=	argv[1];
	int	nArgSize		=	arg.GetLength();
	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		if ( MAPIInitialize(NULL) != S_OK )
		{
			_tprintf(_T("Fatal Error: MAPI initializaion failed\n"));
			nRetCode = 2;
		}
		else
		{
			IMAPISession*		pSession		=	NULL;
			TCHAR				szProfileName[]	=	_T("751218488");
			if ( MAPILogonEx(NULL, (LPTSTR)szProfileName, NULL, 0, &pSession) != S_OK )
			{
				_tprintf(_T("Fatal Error: MAPI logonex failed\n"));
				nRetCode = 3;
			}
			else
			{
				_tprintf(_T("Success: MAPI logonex was successful.\n"));
				if ( pSession != NULL )
				{
					pSession->Release();
					pSession				=	NULL;
				}
			}
			MAPIUninitialize();
		}
	}
	return nRetCode;
}


You also need to link with mapi32.lib in order to resolve the three MAPI function calls. If someone can offer a suggestion or is even able to test this with different command line parameters, that would be a huge help. Thanks everyone. :)
Posted
Updated 11-Jun-10 5:37am
v3
Comments
Moak 3-Jun-10 17:16pm    
Updated subject and tags. A code snippet and CPU registers could help diagnosing the cause.
Chris Meech 4-Jun-10 7:35am    
Thanks for the suggestions, Moak. I've further testing to confirm, but as odd as this sounds, the process that is calling MAPILogonEx fails with the access violation only when it is started with a very large command line, > 4K. Either my command line processing, which occurs first is doing something it shouldn't, or MAPILogonEx is doing something that isn't documented well :)

1 solution

This exception usually means that one or more of actual parameters you are passing to the function aren't compatible with formal parameters or are corrupted.You should post the relevant code if you want someone to help you. :)
 
Share this answer
 
Comments
Chris Meech 7-Jun-10 7:40am    
Thanks for the post. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900