MAPILogonEx中的访问冲突 [英] Access violation in MAPILogonEx

查看:135
本文介绍了MAPILogonEx中的访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对MAPILogonEx的调用,该调用引发了异常.

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

<br />
<pre><br />
#ifndef WINVER              // Allow use of features specific to Windows XP or later.<br />
#define WINVER 0x0501       // Change this to the appropriate value to target other versions of Windows.<br />
#endif<br />
<br />
#ifndef _WIN32_WINNT        // Allow use of features specific to Windows XP or later.<br />
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.<br />
#endif<br />
<br />
#ifndef _WIN32_WINDOWS      // Allow use of features specific to Windows 98 or later.<br />
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.<br />
#endif<br />
<br />
#ifndef _WIN32_IE           // Allow use of features specific to IE 6.0 or later.<br />
#define _WIN32_IE 0x0600    // Change this to the appropriate value to target other versions of IE.<br />
#endif<br />
<br />
#include <stdio.h><br />
#include <tchar.h><br />
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS  // some CString constructors will be explicit<br />
<br />
#ifndef VC_EXTRALEAN<br />
#define VC_EXTRALEAN        // Exclude rarely-used stuff from Windows headers<br />
#endif<br />
<br />
#include <afx.h><br />
#include <afxwin.h>         // MFC core and standard components<br />
#include <afxext.h>         // MFC extensions<br />
#ifndef _AFX_NO_OLE_SUPPORT<br />
#include <afxdtctl.h>       // MFC support for Internet Explorer 4 Common Controls<br />
#endif<br />
#ifndef _AFX_NO_AFXCMN_SUPPORT<br />
#include <afxcmn.h>         // MFC support for Windows Common Controls<br />
#endif // _AFX_NO_AFXCMN_SUPPORT<br />
<br />
#include <iostream><br />
<br />
// TODO: reference additional headers your program requires here<br />
// for MAPI<br />
#include <mapix.h><br />
#include <objbase.h><br />
</pre><br />



这是主要的cpp



And here is the main cpp

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



您还需要链接mapi32.lib来解决这三个MAPI函数调用.如果有人可以提供建议,或者甚至可以使用不同的命令行参数测试该建议,那将是巨大的帮助.感谢大家. :)



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. :)

推荐答案

此异常通常意味着您传递给函数的一个或多个实际参数与形式参数不兼容或已损坏.如果您希望有人帮助您,请发布相关代码. :)
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. :)


这篇关于MAPILogonEx中的访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆