Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use MSMAPI32.ocx in WPF to send mail?
    primarykey
    data
    text
    <p>We are developing an desktop application based on WPF, which has a feature that user can send feedback to us. We can receive the Name, Email, Body and so on.</p> <p>For some historical problems we used <strong>MSMAPI</strong> to help us send mail, as time goes on we found all its function work very well <em>until we did tests on clean machine</em>.</p> <p>The ActiveX control said, <strong>please offer me a license so I can move on</strong>, well that's make us quite confused, because that control doesn't have license at all.</p> <p>Ok, I will talk about the detail now.</p> <p>In folder <code>C:\Windows\SysWOW64</code> (On Win7 x64), we have <code>msmapi32.ocx</code>. From <a href="http://msdn.microsoft.com/en-us/library/8ccdh774%28v=vs.110%29.aspx" rel="nofollow">MSDN</a>, we have to wrapper it so can be host on a Windows Form. We did it, and got two assemblies: <code>MSMAPI.dll</code> and <code>AxMSMAPI.dll</code>, so we make our application reference these two DLLs.</p> <p>Here is our code(XAML):</p> <pre><code>&lt;Window x:Class="WpfApplication14.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ax="clr-namespace:AxMSMAPI;assembly=AxMSMAPI" Title="MainWindow" Width="525" Height="350"&gt; &lt;StackPanel&gt; &lt;WindowsFormsHost&gt; &lt;ax:AxMAPIMessages Name="axMAPIMessage" /&gt; &lt;/WindowsFormsHost&gt; &lt;WindowsFormsHost&gt; &lt;ax:AxMAPISession Name="axMAPISession" /&gt; &lt;/WindowsFormsHost&gt; &lt;/StackPanel&gt; &lt;/Window&gt; </code></pre> <p>Ofcourse, we have to <strong>change our project build target to X86</strong>, otherwise it would throw ClassNotDefined exception. Pretty well, press F5, the main window shows successfully.</p> <p>Then we copy the Debug folder of our demo application, double click, Oops... It said, <em>WpfAPplication14 has stopped work</em>. We captured the exption, here is the stack:</p> <pre><code>System.Windows.Markup.XamlParseException occurred _HResult=-2146233087 _message='Initialization of 'AxMSMAPI.AxMAPIMessages' threw an exception.' Line number '-' and line position '-'. HResult=-2146233087 IsTransient=false Message='Initialization of 'AxMSMAPI.AxMAPIMessages' threw an exception.' Line number '-' and line position '-'. Source=PresentationFramework LineNumber=- LinePosition=- StackTrace: at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) InnerException: System.ComponentModel.LicenseException _HResult=-2146232063 _message=You must have a license to use this ActiveX control. HResult=-2146232063 IsTransient=false Message=You must have a license to use this ActiveX control. Source=System.Windows.Forms StackTrace: at System.Windows.Forms.AxHost.CreateInstance() at System.Windows.Forms.AxHost.GetOcxCreate() at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state) at System.Windows.Forms.AxHost.CreateHandle() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.AxHost.EndInit() at MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(XamlType xamlType, Object obj, Boolean begin) InnerException: </code></pre> <p>Then we wrote a Windows Forms application, in the beginning we did excatly the same with WPF demo, reference the two DLLs to project, and even the result is the same. It only can show window in our develpment machine, cannot run on clean Test Machine.</p> <p>So we followed some steps on MSDN, add the ActiveX control (<code>C:\Windows\SysWOW64\msmapi32.ocx</code>) to Visual Studio Toolbox, and drag them to the surface, and it works very well on Test Machine.</p> <p>The last try by us is, follow the Windows Forms demo did, we intended to add the ocx to toolbox, but the Visual Studio said <strong>it is successfully added to toolbox, but it is not enabled in the active designer due to incompatible with the current designer and .NET framework version (VS2012/.NET 4.0/WPF)</strong>.</p> <p>We don'n know what's the reason the demo window thrown exception when parse XAML in Test Machine, <strong>it seems we need a license, but does it need a license???</strong></p> <p>We tried to achieve it follow Windows Forms demo did, but we even cannot add the ocx to toolbox.</p> <p>So, if you have some advices towards below questions or any of them, please feel free to let us know:</p> <ul> <li>Where does the <code>msmapi32.ocx</code> come from? Does any windows machine has it or only after installed something. <em>By the way, we also tried to install Office 2013 on our Test Machine, it sitll the same exception thrown.</em></li> <li>We know our ocx version is 6.0, which released at 2000. So if we would like to use it in our WPF application, any suggestions?</li> <li>What factors can affect this? <em>we searched the Dev and Test machine, both have the ocx in the folder, and both registry have the MSAPI related item (and the Windows Forms works very well).</em></li> <li>So if above questions can be answered, it can help us a lot. From your experience, how can you achieve this feature using WPF, using the native API provided by .NET or some else 3rd party control/plugin? In fact our requirement is so eary that user send feedback to some fixed address. That's all we need to do.</li> </ul> <p>Very appreciate if you have some thoughts about our question, and feel free to ask us questions which puzzled you.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload