Archived

This topic is now archived and is closed to further replies.

Adding email link to about box (Win9x/NT)

This topic is 6021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I am trying to invoke the email client when you click an ''Email'' button on the about box, so that users can send comments and suggestions. The problem is that the follwing works on an NT box, but an my laptop when I try to resolve the name it returns:
  
MAPI_E_FAILURE 

One or more unspecified errors occurred. The name was not resolved
  
Now with other programs that utilise an email option they work perfectly (i.e. SETISpy). Here is the code. I am scratching my head here folks. Maybe there is a better way? Thanks in advance.
  
void CAboutDlg::OnEmail() 
{
 	HINSTANCE hMail = ::LoadLibraryA("MAPI32.DLL");

	if (hMail == NULL)
	{
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
						NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
						(LPTSTR) &lpMsgBuf,0,NULL);
		MessageBox( (LPCSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
		LocalFree( lpMsgBuf );
		return;
	}

	ULONG (PASCAL *lpfnResolveName)(LHANDLE,ULONG,LPSTR,FLAGS,ULONG,lpMapiRecipDesc *);
	(FARPROC&)lpfnResolveName = GetProcAddress(hMail, "MAPIResolveName");

	if (lpfnResolveName == NULL)
	{
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
						NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
						(LPTSTR) &lpMsgBuf,0,NULL);
		MessageBox( (LPCSTR)lpMsgBuf, "MAPIResolveName", MB_OK|MB_ICONINFORMATION );
		LocalFree( lpMsgBuf );
		FreeLibrary(hMail);
		return;
	}

	MapiRecipDesc recip,*temprecip;
	ULONG err = lpfnResolveName(0L,            // implicit session

					(ULONG)this->m_hWnd,            // no UI handle

					"Joe@sixpack.com", // friendly name

					MAPI_DIALOG | MAPI_LOGON_UI,            // no flags, no UI allowed

					0L,            // reserved; must be 0

					&temprecip);// where to put the result


	if (err != SUCCESS_SUCCESS)
	{
		FreeLibrary(hMail);
		return;
	}
	recip.ulReserved   = temprecip->ulReserved;
	recip.ulRecipClass = MAPI_TO;
	recip.lpszName     = temprecip->lpszName;
	recip.lpszAddress  = temprecip->lpszAddress;
	recip.ulEIDSize    = temprecip->ulEIDSize;
	recip.lpEntryID    = temprecip->lpEntryID;

	ULONG (PASCAL *lpfnMAPIFreeBuffer)(LPVOID lpBuffer);
	(FARPROC&)lpfnMAPIFreeBuffer = GetProcAddress(hMail, "MAPIFreeBuffer");
	if (lpfnMAPIFreeBuffer)
		lpfnMAPIFreeBuffer(temprecip);

	//------------------------------------------------------------------

	ULONG (PASCAL *lpfnSendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
	(FARPROC&)lpfnSendMail = GetProcAddress(hMail, "MAPISendMail");
	if (lpfnResolveName == NULL)
	{
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
						NULL,GetLastError(),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
						(LPTSTR) &lpMsgBuf,0,NULL);
		MessageBox( (LPCSTR)lpMsgBuf, "MAPISendMail", MB_OK|MB_ICONINFORMATION );
		LocalFree( lpMsgBuf );
		FreeLibrary(hMail);
		return;
	}

	MapiMessage note = {0,            // reserved, must be 0

                    TITLE_VERSION,         // subject

                    "Comments:\n\nSuggestions:\n",         // no note text

                    NULL,         // NULL = interpersonal message

                    NULL,         // no date; MAPISendMail ignores it

                    NULL,         // no conversation ID

                    0L,           // no flags, MAPISendMail ignores it

                    NULL,         // no originator, this is ignored too

                    1,            // zero recipients

                    &recip,         // NULL recipient array

                    0,            // no attachment

                    NULL}; // the attachment structure

	err = lpfnSendMail (0L,          // use implicit session.

                    (ULONG)(HWND)this,          // ulUIParam; 0 is always valid

                    ¬e,       // the message being sent

                    MAPI_DIALOG | MAPI_LOGON_UI,
                    0L);         // reserved; must be 0


	FreeLibrary(hMail);
}
  
D.V.

Share this post


Link to post
Share on other sites
to answer my own question.

You don''t need to resolve the name

just do the following

  
recip.ulReserved = 0;
recip.ulRecipClass = MAPI_TO;
recip.lpszName = "sally@housecoat.com";
recip.lpszAddress = "SMTP:sally@housecoat.com";
recip.ulEIDSize = 0;
recip.lpEntryID = 0;


and then it should work. I havn''t tried it out with AOLers yet.

D.V.

Share this post


Link to post
Share on other sites