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>
#include <afxext.h>
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <iostream>
#include <mapix.h>
#include <objbase.h>
And here is the main cpp
#include "stdafx.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
CString arg = argv[1];
int nArgSize = arg.GetLength();
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_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. :)