T
thangarasu
Hi,
I developing a C# Outlook add-in which sends the mail when the user
clicks my custom button on the Inspector window. I am using extended
MAPI to avoid the security warning in Office XP which is written in
C++.
I am passing the Outlook mailItem object and the MAPI Namespace to the
C++ dll which inturn gets the MAPI session from the Namespace.
Everything works perfect when the Outlook HTML editor is used as Email
editor. But when I set the email editor to MS WORD, the MAPI Object is
junk and I am not able to get the MAPI Session.
Any help is greatly appriciated.
Here is my C# code:
//import
[DllImport("ExtendedMAPIInterface.dll", EntryPoint="SendMailItem",
CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
public static extern uint
SendMailItem([MarshalAs(UnmanagedType.IDispatch)] System.Object
objNameSpace, ref IntPtr lpDispatch);
//Function call
IntPtr lpDispatch = Marshal.GetIDispatchForObject(item);
uint nResult = SendMailItem(applicationObject.GetNamespace("MAPI"),
ref lpDispatch);
//C++ Implementation:
HRESULT SendMailItem(LPDISPATCH pNameSpace, LPDISPATCH* pMailItem)
{
HRESULT hr =S_OK;
LPMAPISESSION pSession = NULL;
hr = GetMapiSession(pNameSpace, &pSession);
........
}
//Get MAPI Session is implemented as
HRESULT GetMapiSession(LPDISPATCH pMapiNameSpace, LPMAPISESSION*
ppMapiSession)
{
HRESULT hr = S_OK;
try
{
Outlook::_NameSpacePtr pMapiNS;
if (pMapiNameSpace == NULL)
return S_FALSE;
*ppMapiSession = NULL;
pMapiNameSpace->AddRef();
pMapiNS = pMapiNameSpace;
IUnknown * pUnk = pMapiNS->MAPIOBJECT;
if (pUnk == NULL)
return S_FALSE;
//Queryinterface will call the AddRef() internally.
hr= pUnk->QueryInterface(IID_IMAPISession, (void**)ppMapiSession);
if (!SUCCEEDED(hr))
{
Log("Failed to get the interface pointer for IMAPISession.\n");
return S_FALSE;
}
pUnk->Release();
}
catch(...)
{
Log("Extended MAPI: Exception occured when getting the MAPI
Session.");
}
return hr;
}
Thanks
Thanga
I developing a C# Outlook add-in which sends the mail when the user
clicks my custom button on the Inspector window. I am using extended
MAPI to avoid the security warning in Office XP which is written in
C++.
I am passing the Outlook mailItem object and the MAPI Namespace to the
C++ dll which inturn gets the MAPI session from the Namespace.
Everything works perfect when the Outlook HTML editor is used as Email
editor. But when I set the email editor to MS WORD, the MAPI Object is
junk and I am not able to get the MAPI Session.
Any help is greatly appriciated.
Here is my C# code:
//import
[DllImport("ExtendedMAPIInterface.dll", EntryPoint="SendMailItem",
CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
public static extern uint
SendMailItem([MarshalAs(UnmanagedType.IDispatch)] System.Object
objNameSpace, ref IntPtr lpDispatch);
//Function call
IntPtr lpDispatch = Marshal.GetIDispatchForObject(item);
uint nResult = SendMailItem(applicationObject.GetNamespace("MAPI"),
ref lpDispatch);
//C++ Implementation:
HRESULT SendMailItem(LPDISPATCH pNameSpace, LPDISPATCH* pMailItem)
{
HRESULT hr =S_OK;
LPMAPISESSION pSession = NULL;
hr = GetMapiSession(pNameSpace, &pSession);
........
}
//Get MAPI Session is implemented as
HRESULT GetMapiSession(LPDISPATCH pMapiNameSpace, LPMAPISESSION*
ppMapiSession)
{
HRESULT hr = S_OK;
try
{
Outlook::_NameSpacePtr pMapiNS;
if (pMapiNameSpace == NULL)
return S_FALSE;
*ppMapiSession = NULL;
pMapiNameSpace->AddRef();
pMapiNS = pMapiNameSpace;
IUnknown * pUnk = pMapiNS->MAPIOBJECT;
if (pUnk == NULL)
return S_FALSE;
//Queryinterface will call the AddRef() internally.
hr= pUnk->QueryInterface(IID_IMAPISession, (void**)ppMapiSession);
if (!SUCCEEDED(hr))
{
Log("Failed to get the interface pointer for IMAPISession.\n");
return S_FALSE;
}
pUnk->Release();
}
catch(...)
{
Log("Extended MAPI: Exception occured when getting the MAPI
Session.");
}
return hr;
}
Thanks
Thanga