<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Devosaure</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/devosaure/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/devosaure/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:07:05 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Scénarios d’interopérabilité entre une application Moderne et une application de Bureau Part I.</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/scnarios-dinteroprabilit-entre-une-application-moderne-et-une-application-de-bureau-part-i</link>
      <pubDate>Wed, 15 Apr 2015 02:43:10 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/04/15/scnarios-dinteroprabilit-entre-une-application-moderne-et-une-application-de-bureau-part-i/</guid>
      <description><![CDATA[Pour développer des applications sur Windows 8 et 8.1, aujourd’hui vous avez deux...]]></description>
      <content:encoded><![CDATA[<p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2"></font></p>  <p><font size="2">Pour développer des applications sur Windows 8 et 8.1, aujourd’hui vous avez deux paradigmes de développement comme illustré sur la figure suivante : </font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2843.Image2_6E8EC53D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2843.Image2_5F00_6E8EC53D.png"><img title="Image2" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Image2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/1033.Image2_thumb_4BCD8D80.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/1033.Image2_5F00_thumb_5F00_4BCD8D80.png" width="851" height="484" /></a></p>  <p><font size="2">Des applications de bureaux traditionnelles, et d</font><font size="2">es applications pour le Windows store ou dites Modernes, vous remarquerez qu’il existe une <font size="2"><strong>frontière</strong> entre les deux.</font></font></p>  <p><font size="2">En effet, l</font><font size="2">es applications Modernes sont pour la plus part développées pour un déploiement dans le Windows Store, elles s’exécutent essentiellement dans un <strong>conteneur</strong> “hyper protecteur”, ou il n’est pas possible de dialoguer aussi facilement qu’on le souhaiterait avec des applications de Bureau via les canaux Interprocessus traditionnels (</font><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx"><font size="2">IPC</font></a><font size="2">). </font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0181.Image1_49276280.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0181.Image1_5F00_49276280.png"><img title="Image1" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="Image1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/7457.Image1_thumb_6DBB80B5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/7457.Image1_5F00_thumb_5F00_6DBB80B5.png" width="842" height="409" /></a></p>  <p>&#160;</p>  <p><font size="2">Avec Windows 8, seul deux mécanismes sont mis à notre disposition.</font></p>  <ul>   <li><a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.launcher.aspx"><font size="2">Les protocoles personnalisés</font></a><font size="2"> </font></li>    <li><a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.system.launcher.aspx"><font size="2">Et les associations d’extensions de fichiers</font></a><font size="2"> </font></li> </ul>  <p><font size="2">Avec l’arrivée de Windows 8.1 Update 1 deux autres mécanismes sont désormais disponibles.</font></p>  <ul>   <li><font size="2">L’utilisation de composants dits </font><a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx"><font size="2">Brokered Components</font></a><font size="2"> </font></li>    <li><font size="2">Et permettre à l’application Moderne d’utiliser le </font><a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn640582.aspx"><font size="2">LoopBack réseau</font></a><font size="2"> </font></li> </ul>  <p><font size="2">Partant de ces mécanismes, il est possible d’imaginer différents scénarios afin de faire passer des informations entre les deux types d’applications ou entre une application Moderne et un composant qui ne serait pas chargé dans ce container “Hyper protecteur”.</font></p>  <p><font size="2">Par exemple, nous pourrions imaginer les scénarios suivants : </font></p>  <p><font size="2"><font color="#0000ff" size="3">Comment lancer votre application Moderne (Windows Store) au chargement de Windows 8.1 ?        <br /></font>      <br />Avec Windows il est possible de définir une application qui se lancera dés que l’utilisateur se connecte, il suffit de placer votre application dans le répertoire suivant :</font></p>  <p><strong><font size="2">C:\Users\[VOUS]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup</font></strong></p>  <p><font size="2">Le hic, c’est que <strong>vous ne pouvez-pas y placer</strong> votre application Moderne.</font></p>  <p><font size="2">Une des solutions consiste à :</font></p>  <p><font size="2">Définir un </font><a href="https://code.msdn.microsoft.com/windowsapps/Association-Launching-535d2cec"><font size="2">protocole personnalisé</font></a><font size="2"> pour votre application moderne, comme illustré sur la figure suivante :      <br /></font><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/6825.image_4B5799C8.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/6825.image_5F00_4B5799C8.png"><font size="2"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/8400.image_thumb_4CBBBC9A.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/8400.image_5F00_thumb_5F00_4CBBBC9A.png" width="658" height="208" /></font></a><font size="2">      <br /></font></p>  <p><font size="2">Créer une petite application de bureau qui invoquera ce protocole dans sa méthode Main(), comme illustré dans le code suivant :      <br /></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:286070a0-b80e-40f2-96f0-fc62b7459de3" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> Main()</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000"> ppi = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;alsdkcs:&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">            ppi.WindowStyle = </span><span style="background:#ffffff;color:#2b91af">ProcessWindowStyle</span><span style="background:#ffffff;color:#000000">.Maximized;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000"> pp = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">            pp.StartInfo = ppi;</span><br> <span style="background:#ffffff;color:#000000">            pp.Start();              </span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>  <p><font size="2">Enfin il faut copier l’application de bureau dans le répertoire de démarrage et le tour est joué.</font></p>  <p><font size="2">Lorsque l’utilisateur se connectera, l’application de bureau démarre qui elle même invoque l’application moderne via son protocole.      <br /></font><font color="#0000ff" size="3"></font></p>  <p><font color="#0000ff" size="3">Comment lancer votre application de bureau à partir d’une application Moderne ?</font></p>  <p><font size="2">Si l’application manipule des fichiers, le plus simple sera donc d’utiliser la méthode <strong>LaunchFileAsync, </strong>le fichier sera passé comme paramètre, à la méthode <strong>Main</strong> de l’application desktop. Il suffira alors de charger le fichier.       <br />Néanmoins, plusieurs restrictions seront à prendre en compte. </font></p>  <p><font size="2">Ce fichier à charger doit être présent :</font></p>  <p><font size="2">Soit dans le répertoire courant de l’application      <br /></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8c78241b-9650-43af-99e5-fcfc807d1a41" class="wlWriterSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">   <div style="font-size: 10pt; border-top: #000080 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: #000080 1px solid; border-bottom: #000080 1px solid; color: #000; border-left: #000080 1px solid">     <div style="overflow: auto; padding-bottom: 2px; padding-top: 2px; padding-left: 5px; padding-right: 5px; background-color: #ffffff"><span style="background: #ffffff; color: #2b91af">ApplicationData</span><span style="background: #ffffff; color: #000000">.Current.LocalFolder.GetFileAsync(</span><span style="background: #ffffff; color: #a31515">&quot;presentation2.ppsx&quot;</span><span style="background: #ffffff; color: #000000">);</span></div>   </div> </div>  <p><font size="2">Soit dans un répertoire connu comme <strong>Images</strong> par exemple. </font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0e1be939-8270-40c1-a686-58f9e2a83144" class="wlWriterSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">   <div style="font-size: 10pt; border-top: #000080 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: #000080 1px solid; border-bottom: #000080 1px solid; color: #000; border-left: #000080 1px solid">     <div style="overflow: auto; padding-bottom: 2px; padding-top: 2px; padding-left: 5px; padding-right: 5px; max-height: 300px; background-color: #ffffff"><span style="background: #ffffff; color: #2b91af">KnownFolders</span><span style="background: #ffffff; color: #000000">.PicturesLibrary.GetFileAsync(</span><span style="background: #ffffff; color: #a31515">&quot;presentation2.ppsx&quot;</span><span style="background: #ffffff; color: #000000">);</span></div>   </div> </div>  <p><font size="2">Il ne sera pas possible de passer directement des paramètres (sauf à y être placés dans le fichier lui même).</font></p>  <p><font size="2">L’autre méthode, consiste à utiliser un protocole personnalisé pour lancer l’application de bureau.</font></p>  <p><font size="2">Tout d’abord il faut enregistrer un protocole personnalisé pour votre application de bureau. C’est très simple, ce n’est que des clés de registre à créer, dont voici un bout de code qui vous simplifiera la tâche.      <br /></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5bf0a808-2753-469d-b29b-e371bc2f59c3" class="wlWriterSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">   <div style="font-size: 10pt; border-top: #000080 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; border-right: #000080 1px solid; border-bottom: #000080 1px solid; color: #000; border-left: #000080 1px solid">     <div style="overflow: auto; white-space: nowrap; padding-bottom: 2px; padding-top: 2px; padding-left: 5px; padding-right: 5px; background-color: #ffffff"><span style="background: #ffffff; color: #000000">&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">public</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">static</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">class</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #2b91af">CustomProtocol</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL_STRING&#160;&#160;&#160;&#160; =&#160;&#160;&#160; </span><span style="background: #ffffff; color: #a31515">&quot;URL:{0} Protocol&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; =</span><span style="background: #ffffff; color: #a31515">&quot;URL Protocol&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL_DEFAULTICON =</span><span style="background: #ffffff; color: #a31515">&quot;DefaultIcon&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL_COMMAND&#160;&#160;&#160;&#160; =</span><span style="background: #ffffff; color: #a31515">&quot;Shell\\Open\\command&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL_OPEN&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; =</span><span style="background: #ffffff; color: #a31515">&quot;Shell\\Open&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">const</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> URL_PROTOCOL_SHELL&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; =</span><span style="background: #ffffff; color: #a31515">&quot;Shell&quot;</span><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">public</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">static</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">int</span><span style="background: #ffffff; color: #000000"> Register(</span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> protocolname,</span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> exepath)</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKey</span><span style="background: #ffffff; color: #000000"> HKCR = </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKey</span><span style="background: #ffffff; color: #000000"> SubKeyProtocolName=</span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKey</span><span style="background: #ffffff; color: #000000"> SubKeyDefaultIcone = </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKey</span><span style="background: #ffffff; color: #000000"> SubKeyCommand = </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">int</span><span style="background: #ffffff; color: #000000"> Status = 0;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">try</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HKCR = </span><span style="background: #ffffff; color: #2b91af">Registry</span><span style="background: #ffffff; color: #000000">.ClassesRoot;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyProtocolName = HKCR.CreateSubKey(protocolname,</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKeyPermissionCheck</span><span style="background: #ffffff; color: #000000">.ReadWriteSubTree,</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryOptions</span><span style="background: #ffffff; color: #000000">.None);</span>         <br />        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyProtocolName.SetValue(</span><span style="background: #ffffff; color: #a31515">&quot;&quot;</span><span style="background: #ffffff; color: #000000">, </span><span style="background: #ffffff; color: #2b91af">String</span><span style="background: #ffffff; color: #000000">.Format(URL_PROTOCOL_STRING,protocolname));</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyProtocolName.SetValue(URL_PROTOCOL, </span><span style="background: #ffffff; color: #a31515">&quot;&quot;</span><span style="background: #ffffff; color: #000000">);</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyDefaultIcone=SubKeyProtocolName.CreateSubKey(URL_PROTOCOL_DEFAULTICON,</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKeyPermissionCheck</span><span style="background: #ffffff; color: #000000">.ReadWriteSubTree, </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryOptions</span><span style="background: #ffffff; color: #000000">.None);</span>         <br />        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyDefaultIcone.SetValue(</span><span style="background: #ffffff; color: #a31515">&quot;&quot;</span><span style="background: #ffffff; color: #000000">, exepath);</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyCommand = SubKeyProtocolName.CreateSubKey(URL_PROTOCOL_COMMAND,</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKeyPermissionCheck</span><span style="background: #ffffff; color: #000000">.ReadWriteSubTree,</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryOptions</span><span style="background: #ffffff; color: #000000">.None);</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> command = </span><span style="background: #ffffff; color: #2b91af">String</span><span style="background: #ffffff; color: #000000">.Format(</span><span style="background: #ffffff; color: #a31515">&quot;{0} %1&quot;</span><span style="background: #ffffff; color: #000000">, exepath);</span>         <br />        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SubKeyCommand.SetValue(</span><span style="background: #ffffff; color: #a31515">&quot;&quot;</span><span style="background: #ffffff; color: #000000">, command);</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">catch</span><span style="background: #ffffff; color: #000000">(</span><span style="background: #ffffff; color: #2b91af">Exception</span><span style="background: #ffffff; color: #000000"> ex)</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Status = 1;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">finally</span><span style="background: #ffffff; color: #000000"> </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br />        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">if</span><span style="background: #ffffff; color: #000000"> (SubKeyCommand != </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">) SubKeyCommand.Close();</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">if</span><span style="background: #ffffff; color: #000000"> (SubKeyDefaultIcone != </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">) SubKeyDefaultIcone.Close();</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">if</span><span style="background: #ffffff; color: #000000"> (SubKeyProtocolName!=</span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">) SubKeyProtocolName.Close();</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">if</span><span style="background: #ffffff; color: #000000"> (HKCR != </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">) HKCR.Close();</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br />        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">return</span><span style="background: #ffffff; color: #000000"> Status;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">public</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">static</span><span style="background: #ffffff; color: #000000"> </span><span style="background: #ffffff; color: #0000ff">int</span><span style="background: #ffffff; color: #000000"> UnRegister(</span><span style="background: #ffffff; color: #0000ff">string</span><span style="background: #ffffff; color: #000000"> protocolname)</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">int</span><span style="background: #ffffff; color: #000000"> Status = 0;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #2b91af">RegistryKey</span><span style="background: #ffffff; color: #000000"> HKCR = </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">try</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HKCR = </span><span style="background: #ffffff; color: #2b91af">Registry</span><span style="background: #ffffff; color: #000000">.ClassesRoot;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HKCR.DeleteSubKeyTree(protocolname, </span><span style="background: #ffffff; color: #0000ff">false</span><span style="background: #ffffff; color: #000000">);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">catch</span><span style="background: #ffffff; color: #000000">(</span><span style="background: #ffffff; color: #2b91af">Exception</span><span style="background: #ffffff; color: #000000">)</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Status = 1;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">finally</span><span style="background: #ffffff; color: #000000"> </span>        <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">if</span><span style="background: #ffffff; color: #000000"> (HKCR != </span><span style="background: #ffffff; color: #0000ff">null</span><span style="background: #ffffff; color: #000000">) HKCR.Close();</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span><span style="background: #ffffff; color: #0000ff">return</span><span style="background: #ffffff; color: #000000"> Status;</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span>         <br /><span style="background: #ffffff; color: #000000">&#160;&#160;&#160; }</span></div>   </div> </div>  <p><font size="2">A partir de l’application Moderne, il suffit d’appeler la méthode suivante :      <br /></font></p>  <p><font size="2"><font color="#0000ff">await</font> Windows.System.<font color="#4bacc6">Launcher</font>.LaunchUriAsync(<font color="#0000ff">new</font> <font color="#4bacc6">Uri</font>(<font color="#ff0000">“LauncherProtocol:”</font>));</font></p>  <p><font size="2">Lorsque l’application de bureau se lance, Windows passe à la méthode Main la chaine <strong>LauncherProtocol</strong> qu’il faut intercepter.</font><font size="2"></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:becf8041-69ce-4993-bea6-ab6edac2e8dd" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> Main(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000">[] args)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> protocol = args[0];</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (args[0]==</span><span style="background:#ffffff;color:#a31515">&quot;LauncherProtocol:&quot;</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#008000">//code omis</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">else</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#008000">//code omis</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>  <p>   <br /><font size="2">A la différence de l’association de fichier, vous pouvez également passer des paramètres via le protocole. </font><font size="2">En partant de ce principe on peu alors imaginer une foultitude de scénarios, comme dans la section suivante.</font></p>  <p><font size="2"></font></p>  <p><font color="#0000ff" size="3">Comment formater un e-mail dans une application moderne et l’envoyer dans Outlook ?</font></p>  <p><font color="#000000" size="2">L’idée ici est de pouvoir ce substituer au contrat de partage de Windows 8.1, et formater un e-mail avec une liste de distribution, des fichiers attachés, et un corps de message au format HTML.</font></p>  <p><font color="#000000" size="2">On va donc utiliser la méthode à base de protocole personnalisé et procéder par étapes.</font></p>  <p><font color="#000000"><font size="2">L’application Moderne va sauvegarder dans son répertoire courant un fichier au format XML qui contiendra les éléments du message, comme illustrer sur la figure suivante&#160; :        <br /></font><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/3603.clip_image002_4A15919A.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/3603.clip_5F00_image002_5F00_4A15919A.jpg"><font size="2"><img title="clip_image002" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/7824.clip_image002_thumb_09E208D1.jpg" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/7824.clip_5F00_image002_5F00_thumb_5F00_09E208D1.jpg" width="709" height="448" /></font></a><font size="2">        <br />Dans ce fichier on retrouve en gros les destinataires du message, les fichiers attachés, ainsi que le corps du message au format HTML.</font></font><font size="2"> </font></p>  <p><font size="2">Cette application au lieu d’invoquer directement Outlook via le protocole Mailto, invoquera une application de bureau via le protocole personnalisé nommé <b>LauncherProtocol : </b>qui ne prend qu’un seul paramètre, c’est à dire le chemin d’accès au fichier xml au préalablement crée.       <br /></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b875cf0c-9d27-40af-a1ed-fe696bbca8b0" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> filePath = </span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> CreateMailAsync();</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Uri</span><span style="background:#ffffff;color:#000000"> uri = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Uri</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000">.Format(</span><span style="background:#ffffff;color:#a31515">&quot;LauncherProtocol:{0}&quot;</span><span style="background:#ffffff;color:#000000">, filePath));</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> Windows.System.</span><span style="background:#ffffff;color:#2b91af">Launcher</span><span style="background:#ffffff;color:#000000">.LaunchUriAsync(uri);</span></div> </div> </div>  <p><font size="2">L’application de bureau est lancée via son protocole, va traiter la demande lancer Outlook si il n’est pas déjà chargé, puis demander à Outlook de créer un nouveau message factice à l’aide cette fois-ci du protocole <strong>MailTo</strong>. </font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0dd7d172-5424-4535-83dd-6fbd1d236b79" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> Main(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000">[] args)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">                        </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> IndexOf= args[0].IndexOf(</span><span style="background:#ffffff;color:#a31515">&#39;:&#39;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> file = args[0].Remove(0, IndexOf+1);            </span><br> <span style="background:#ffffff;color:#000000">            InvokeAppByProtocol(file);            </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> InvokeAppByProtocol(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> file)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000">[] Processes= </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000">.GetProcessesByName(</span><span style="background:#ffffff;color:#a31515">&quot;outlook&quot;</span><span style="background:#ffffff;color:#000000">);            </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (Processes.Count() &gt; 1)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                StartNewMessage(file);</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000">; </span><span style="background:#ffffff;color:#008000">//no need to restart outlook;</span><br> <span style="background:#ffffff;color:#000000">            }                </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000"> pi = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Outlook.Exe&quot;</span><span style="background:#ffffff;color:#000000">);            </span><br> <span style="background:#ffffff;color:#000000">            pi.CreateNoWindow = </span><span style="background:#ffffff;color:#0000ff">false</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            pi.UseShellExecute = </span><span style="background:#ffffff;color:#0000ff">true</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            pi.WindowStyle = </span><span style="background:#ffffff;color:#2b91af">ProcessWindowStyle</span><span style="background:#ffffff;color:#000000">.Maximized;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000"> p = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">            p.StartInfo = pi;</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (p.Start())</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">                StartNewMessage(file);</span><br> <span style="background:#ffffff;color:#000000">            }            </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> StartNewMessage(</span><span style="background:#ffffff;color:#0000ff">string</span><span style="background:#ffffff;color:#000000"> file)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <br> <br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000"> ppi = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ProcessStartInfo</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000">.Format(</span><span style="background:#ffffff;color:#a31515">&quot;mailto:fake@contoso.com?subject={0}&quot;</span><span style="background:#ffffff;color:#000000">, file));</span><br> <span style="background:#ffffff;color:#000000">            ppi.WindowStyle = </span><span style="background:#ffffff;color:#2b91af">ProcessWindowStyle</span><span style="background:#ffffff;color:#000000">.Maximized;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000"> pp = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Process</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">            pp.StartInfo = ppi;</span><br> <span style="background:#ffffff;color:#000000">            pp.Start();</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Program</span><span style="background:#ffffff;color:#000000">.ShowWindow(pp.MainWindowHandle, 3);</span><br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>  <p><font size="2">Enfin, l’astuce consiste à développer un Add-In Outlook qui va :</font></p>  <ul>   <li><font size="2">Intercepter le nouveau message factice.</font> </li>    <li><font size="2">Récupérer le chemin d’accès au fichier dans le champ <b>Subject</b>.</font> </li>    <li><font size="2">De sérialiser le vrai message à partir du fichier xml.</font> </li>    <li><font size="2">Et enfin, créer un nouveau message, comme illustré dans le listing suivant : </font></li> </ul>  <p><font size="2"></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b0eccbec-8e38-47ae-8e25-238e883f61d6" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000">     </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.</span><span style="background:#ffffff;color:#2b91af">Inspector</span><span style="background:#ffffff;color:#000000"> Inspector)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <br> <span style="background:#ffffff;color:#000000">                Outlook.</span><span style="background:#ffffff;color:#2b91af">MailItem</span><span style="background:#ffffff;color:#000000"> currentMailItem = Inspector.CurrentItem </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> Outlook.</span><span style="background:#ffffff;color:#2b91af">MailItem</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (currentMailItem != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (currentMailItem.Subject == </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">StreamReader</span><span style="background:#ffffff;color:#000000"> reader = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StreamReader</span><span style="background:#ffffff;color:#000000">(currentMailItem.Subject);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Mail</span><span style="background:#ffffff;color:#000000"> mail = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Mail</span><span style="background:#ffffff;color:#000000">(reader.BaseStream);</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (currentMailItem.EntryID == </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        Outlook.</span><span style="background:#ffffff;color:#2b91af">Attachments</span><span style="background:#ffffff;color:#000000"> mailAttachments = currentMailItem.Attachments;</span><br> <span style="background:#ffffff;color:#000000">                        Outlook.</span><span style="background:#ffffff;color:#2b91af">Attachment</span><span style="background:#ffffff;color:#000000"> newAttachment = </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> attachment </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> mail.Attachments)</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            newAttachment = mailAttachments.Add(attachment);</span><br> <br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.Save();</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (newAttachment != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.ReleaseComObject(newAttachment);</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (mailAttachments != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.ReleaseComObject(mailAttachments);</span><br> <br> <span style="background:#ffffff;color:#000000">                        currentMailItem.Subject = mail.Subject;</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.HTMLBody = mail.HTMLBody;</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.Importance = (Outlook.</span><span style="background:#ffffff;color:#2b91af">OlImportance</span><span style="background:#ffffff;color:#000000">)mail.Importance;</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.CC = mail.Cc;</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.To = mail.To;</span><br> <span style="background:#ffffff;color:#000000">                        currentMailItem.BCC = mail.Bcc;</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.ReleaseComObject(currentMailItem);</span><br> <span style="background:#ffffff;color:#000000">                    }</span><br> <span style="background:#ffffff;color:#000000">                }</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">Exception</span><span style="background:#ffffff;color:#000000"> ex)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> Message = ex.Message;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>  <p><font size="2">ce qui donne un message Outlook du style de la figure suivante : </font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0250.image_4705C456.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0250.image_5F00_4705C456.png"><font size="2"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/3857.image_thumb_1D255021.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/3857.image_5F00_thumb_5F00_1D255021.png" width="854" height="443" /></font></a></p>  <p><font size="2">Bon ok, c’est un peu tordu, mais c’est une idée…</font></p>  <p><font size="2">Comme je le disais au début de ce billet, avec Windows 8.1 update 1, Microsoft a ouvert un peu les vannes en proposant deux autres mécanismes les <font size="2"></font><a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn630195.aspx"><font size="2">Brokered Components</font></a><font size="2"> et l’utilisation du <a href="https://msdn.microsoft.com/en-us/library/windows/apps/dn640582.aspx"><font size="2">LoopBack réseau</font></a><font size="2"> </font></font>      <br />qui permet à des applications Modernes de dialoguer plus largement avec des applications de bureau, voir d’utiliser des librairies qui ne sont disponibles que pour le modèle de développement de bureau, <strong>mais</strong>&#160;<strong>si et seulement si ces applications modernes sont </strong></font><a href="https://blogs.msdn.com/b/devosaure/archive/2013/08/06/d-233-ploiement-d-une-application-windows-8-interface-moderne-en-entreprise.aspx"><strong><font size="2">“sideloadées</font></strong></a>”<font size="2"><strong>, c’est à dire qu’elles ne soient PAS installées via le Windows Store.</strong> </font></p>  <p><font size="2">Dans la deuxième partie de cet article nous aborderons la manière d’utiliser le Loopback réseau via un mécanisme Interprocessus comme les Sockets ainsi que la manière d’autoriser l’application de bureau à y accéder.</font></p>  <p><font size="2">Eric</font></p>  <p><font size="2"></font></p>]]></content:encoded>
    </item>
    <item>
      <title>Développeurs, connaissez vous UMDH l’outil pour détecter les fuites mémoire ?</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/dveloppeurs-connaissez-vous-umdh-loutil-pour-dtecter-les-fuites-mmoire</link>
      <pubDate>Thu, 02 Apr 2015 01:05:00 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/04/02/dveloppeurs-connaissez-vous-umdh-loutil-pour-dtecter-les-fuites-mmoire/</guid>
      <description><![CDATA[&nbsp;
UMDH (User mode Dump Heap) est un outil qui s&rsquo;utilise en mode console en tant...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p><span style="font-size: small;">UMDH (User mode Dump Heap) est un outil qui s&rsquo;utilise en mode console en tant qu&rsquo;administrateur et permet de tracer de mani&egrave;re tr&egrave;s pr&eacute;cise les fuites m&eacute;moire.</span></p>
<p><span style="font-size: small;">Comment &ccedil;a marche ? </span></p>
<p><span style="font-size: small;">Tout d&rsquo;abord, vous devez cr&eacute;er une "<strong>User Stack Trace Database</strong>" &agrave; l&rsquo;aide de l&rsquo;outil <strong>GFLAGS</strong> en lui donnant une taille de <strong>50 M&eacute;ga-octets</strong> par exemple.</span></p>
<p><span style="font-size: small;"><strong>GFLAGS &ndash;i &lt;image&gt; +ust <br />GFLAGS &ndash;i &lt;image&gt; -tracedb 50</strong> <br />&lt;Image&gt; dans ce contexte, est le nom de votre application (ex : App1.exe)</span></p>
<p><span style="font-size: small;">Si vous ne l&rsquo;avez pas d&eacute;j&agrave; fait, il faut positionner la variable d&rsquo;environnement _NT_SYMBOL_PATH pour que l&rsquo;outil puisse charger les symboles. <br /><strong>Set _NT_SYMBOL_PATH=SRV*c:\LocalSymbolCache</strong></span></p>
<p><span style="font-size: small;">Lancez votre application et prenez une premi&egrave;re photo &agrave; un instant T1 de la m&eacute;moire consomm&eacute;e par votre application. <br /><strong>UMDH &ndash;p :&lt;PID&gt; -f:LogFile1.log </strong></span></p>
<p><span style="font-size: small;"><strong>Note :</strong> PID, est le num&eacute;ro du processus de votre application, que vous retrouverez soit &agrave; l&rsquo;aide du gestionnaire de t&acirc;ches, ou avec l&rsquo;utilitaire <strong>tlist, </strong>livr&eacute; avec la suite <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx">d&rsquo;outils de d&eacute;bogage</a>) <br /><strong>tlist &ndash;p &lt;image&gt; </strong></span></p>
<p><br /><span style="font-size: small;">Utilisez votre application,&nbsp; puis prenez une seconde photo. <br /><strong>UMDH &ndash;p :&lt;PID&gt; -f:LogFile2.log</strong></span></p>
<p><span style="font-size: small;">Enfin comparez les deux fichiers de log. <br /><strong>UMDH logfile1.log logfile2.log &gt; comparaison.txt <br /></strong></span></p>
<p><span style="font-size: small;">Le fichier de comparaison contiendra les informations de fuites m&eacute;moires. Par exemple j&rsquo;ai dans mon exemple un BackTrace3E18904F qui consomme +0x140000104 Octets non lib&eacute;r&eacute;s entre les deux photos (( 140000104 -&nbsp;&nbsp;&nbsp;&nbsp; 0)</span></p>
<p><span style="font-size: small;">+<strong>140000104</strong> ( 140000104 -&nbsp;&nbsp;&nbsp;&nbsp; 0)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 allocs&nbsp;&nbsp;&nbsp; <strong>BackTrace3E18904F</strong> <br />+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5 (&nbsp;&nbsp;&nbsp;&nbsp; 5 -&nbsp;&nbsp;&nbsp;&nbsp; 0)&nbsp;&nbsp;&nbsp; BackTrace3E18904F&nbsp;&nbsp;&nbsp; allocations</span></p>
<p><span style="font-size: small;">Et la pile des appels m&rsquo;indique que cela ce passe dans la m&eacute;thode <strong>Execute</strong>.</span></p>
<p><span style="font-size: x-small;">ntdll!RtlpCallInterceptRoutine+40 <br />ntdll!RtlAllocateHeap+7B5F8 <br />msvcr120d_app!heap_alloc_base+5D <br />msvcr120d_app!free_dbg_nolock+96B <br />msvcr120d_app!nh_malloc_dbg+B9 <br />msvcr120d_app!nh_malloc_dbg+49 <br />msvcr120d_app!malloc+2A <br />App1!App1::MainPage::<strong>Execute</strong>+DA (d:\app1\mainpage.xaml.cpp, 51) <br />App1!App1::MainPage::Button_Click+32 (d:\app1\mainpage.xaml.cpp, 39) <br />App1!`Windows::UI::Xaml::RoutedEventHandler::RoutedEventHandler&lt;App1::MainPage,void (__cdecl App1::MainPage::*)(Platform::Object ^ __ptr64,Windows::UI::Xaml::RoutedEventArgs ^ __ptr64) __ptr64&gt;'::`3'::__abi_PointerToMemberWeakRefCapture::Invoke+10A <br />App1!Windows::UI::Xaml::RoutedEventHandler::Invoke+91 (d:\app1\generated files\mainpage.g.h, 15732480) <br />App1!Windows::UI::Xaml::RoutedEventHandler::[Windows::UI::Xaml::RoutedEventHandler::__abi_IDelegate]:: <br /></span><span style="font-size: x-small;">__abi_Windows_UI_Xaml_RoutedEventHandler___abi_IDelegate____abi_Invoke+4D (d:\app1\generated files\mainpage.g.h, 16707566) <br />Windows.UI.XamlDirectUI::CRoutedEventSourceBase&lt;DirectUI::IUntypedEventSource,Windows::UI:: <br />Xaml::IRoutedEventHandler,IInspectable,Windows::UI::Xaml::IRoutedEventArgs&gt;::Raise+3FC (d:\9144\windows\dxaml\xcp\dxaml\lib\joltclasses.h, 1139) <br />Windows.UI.Xaml!DirectUI::ButtonBase::OnClick+AD </span></p>
<p><span style="font-size: small;">Pour en savoir plus sur l&rsquo;utilisation d&rsquo;umdh, suivez le guide.</span></p>
<p><a href="https://support.microsoft.com/kb/268343"><span style="font-size: small;">https://support.microsoft.com/kb/268343</span></a><span style="font-size: small;"> et <br /></span><a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff558947(v=vs.85).aspx"><span style="font-size: small;">https://msdn.microsoft.com/en-us/library/windows/hardware/ff558947(v=vs.85).aspx</span></a> </p>
<p><span style="font-size: small;">Cet outil fait partie de la suite d&rsquo;outils de d&eacute;bogage que vous pouvez t&eacute;l&eacute;charger &agrave; partir de cette adresse </span><a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx"><span style="font-size: small;">https://msdn.microsoft.com/en-us/library/windows/hardware/ff551063(v=vs.85).aspx</span></a></p>
<p><span style="font-size: small;">Eric</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Point sur les langages et Visual Studio</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/point-sur-les-langages-et-visual-studio</link>
      <pubDate>Tue, 24 Mar 2015 01:48:46 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/03/24/point-sur-les-langages-et-visual-studio/</guid>
      <description><![CDATA[Dans le monde du développement Microsoft, Visual Studio est la pierre angulaire, que dis-je la...]]></description>
      <content:encoded><![CDATA[<p><font size="3"></font></p>  <p><b><font size="3"></font></b></p>  <p><font size="3">Dans le monde du développement Microsoft, Visual Studio est la pierre angulaire, que dis-je la clé de voute pour tous les développeurs. C’est un outil polymorphe, qui s’adresse à tous types de développeurs, que l’on soit développeur Cloud, client, Mobile, Web, Office, de solutions collaboratives, de jeux, de base de données, voir même développeur de drivers.</font></p>  <p><font size="3">Si vous êtes plutôt développeur d’applications <b>clientes traditionnelles de bureau</b>, le modèle qui s’impose aujourd’hui c’est de développer en utilisant </font><a href="https://msdn.microsoft.com/en-us/library/ff361664(v=vs.110).aspx"><font size="3">la plate-forme .NET</font></a><font size="3">.<i>). </i>      <br />Plusieurs langages sont à votre disposition, dans la boite. </font></p>  <p><a href="https://msdn.microsoft.com/fr-fr/library/618ayhy6.aspx"><font size="3">C#</font></a><font size="3">, langage le plus populaire sur la plate-forme .NET, non de code <b>Cool</b> c’est pour dire, et </font><a href="https://msdn.microsoft.com/fr-fr/library/2x7h1hfk.aspx"><font size="3">VB.NET</font></a><font size="3"> le mal aimé, qui contrairement à ce que l’on pourrait penser, permet d’écrire <b>le même code</b> et <b>avoir les mêmes performances</b> que du code écrit en C#.       <br />En dehors de la boite, c’est à dire disponible sous forme d’extension à Visual Studio, il existe d’autres langages, tel que </font><a href="https://pytools.codeplex.com/"><font size="3">Python</font></a><font size="3"> par exemple.</font></p>  <p><font size="3">Mais la liste des langages .NET disponibles avec Visual Studio, ne s’arrête pas là. Il en existe d’autres tels que </font><a href="https://msdn.microsoft.com/fr-fr/library/dd233154.aspx"><font size="3">F#</font></a><font size="3"> langage pour de la </font><a href="https://fr.wikipedia.org/wiki/Programmation_fonctionnelle"><font size="3">programmation fonctionnelle</font></a><font size="3">, </font><a href="https://msdn.microsoft.com/fr-fr/library/68td296t.aspx"><font size="3">C++/CLI</font></a><font size="3"> (C++ pour le Common Language Infrastructure), plus destiné à créer des assemblages .NET, qui feront la colle entre les langages .NET traditionnels et le monde Natif. Le compilateur qui est utilisé est le même que celui pour compiler du code ISO C++, permettant ainsi <b>un mixte des deux langages </b>(C++/CLI et ISO C++)</font><font size="3"><b> dans le même code source.        <br /></b>      <br />L’autre modèle pour développer des applications de bureau, est le modèle historique de Windows, à savoir, à base d’API Win32, affublé de son petit frère le </font><a href="https://www.microsoft.com/com/default.mspx"><font size="3">Common Object Model</font></a><font size="3">. Dans ce cas-là, on utilisera plutôt le langage C++, qui suit la norme </font><a href="https://fr.wikipedia.org/wiki/C%2B%2B14"><font size="3">ISO C++14</font></a><font size="3">. (A noter, que bien qu’il soit possible de faire du C pure, nous ne supportons pas l’intégralité des fonctionnalités <b><a href="https://fr.wikipedia.org/wiki/C_(langage)#Normalisations">C99</a>. </b></font><a href="https://fr.wikipedia.org/wiki/Herb_Sutter"><font size="3">Herb Sutter</font></a><font size="3"> en donne une bonne explication dans son billet </font><a href="https://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/"><font size="3">Reader Q&amp;A: What about VC++ and C99?</font></a></p>  <p><font size="3">Il est également possible pour les puristes qui souhaiteraient optimiser ce que fait le compilateur, sortir un listing </font><a href="https://fr.wikipedia.org/wiki/Assembleur"><font size="3">Assembleur</font></a><font size="3"> à partir du code C++ et de le réassembler avec </font><a href="https://msdn.microsoft.com/fr-fr/library/afzk3475.aspx"><font size="3">MASM</font></a><font size="3">.</font></p>  <p><font size="3">Pour le développeur <b>Web (HTML)</b>, le langage qui s’impose dans Visual Studio, est bien évidement </font><a href="https://msdn.microsoft.com/fr-fr/library/ie/yek4tbz0(v=vs.94).aspx"><font size="3">Javascript</font></a><font size="3">. Néanmoins, si vous êtes plutôt enclin à utiliser un mode de programmation plus classique, </font><a href="https://msdn.microsoft.com/fr-fr/library/dn411562(v=vs.110).aspx"><font size="3">TypeScript</font></a><font size="3"> est le langage fait pour vous. Le code TypeScript est transcompilé en Javascript, pouvant ainsi être interprété par n'importe quel navigateur web ou moteur Javascript. Il a pour but d'améliorer et de sécuriser la production de code Javascript. </font></p>  <p><font size="3">Pour des développements <b><a href="https://msdn.microsoft.com/library/windows/apps/dn726767.aspx">d’applications pour le Windows Store</a></b>, le modèle de développement se fait sur la base d’un nouveau modèle, le </font><a href="https://msdn.microsoft.com/fr-fr/library/windows/apps/br211377.aspx"><font size="3">Windows Runtime</font></a><font size="3"> qui permet de développer des applications dites Universelles, c’est-à-dire qu’elles tourneront à la fois sur du Windows Phone que sur du Windows (PC, Tablettes, ou </font><a href="https://www.microsoft.com/microsoft-surface-hub/en-us"><font size="3">Microsoft Surface HUB</font></a><font size="3">).      <br />Sans surprise nous retrouverons les langages </font><a href="https://msdn.microsoft.com/fr-fr/library/windows/apps/dn631757.aspx"><font size="3">C# et VB.NET</font></a><font size="3">, un petit nouveau, </font><a href="https://msdn.microsoft.com/fr-fr/library/windows/apps/hh974580.aspx"><font size="3">C++/CX</font></a><font size="3">, (</font><a href="https://msdn.microsoft.com/en-us/library/hh699871.aspx"><font size="3">Extension propriétaire</font></a><font size="3"> de Microsoft à l’ISO C++). Sa particularité c’est qu’on peut le mixer aussi avec de l’ISO C++, ce qui en fait un bon candidat pour réutiliser du code ou des librairies C++ déjà éprouvés. Enfin, il est possible d’utiliser ses compétences acquises en </font><a href="https://msdn.microsoft.com/fr-fr/library/windows/apps/br211385.aspx"><font size="3">Javascript</font></a><font size="3">, pour développer également ce type d’application.</font></p>  <p><font size="3">Pour finir, Visual Studio doit faire face aujourd’hui, à une demande croissante de développement sur des plates-formes et des systèmes autres que ceux de Microsoft. On trouvera donc des extensions à Visual Studio tel que </font><a href="https://xamarin.com/"><font size="3">Xamarin</font></a><font size="3">, qui vous permettra de réutiliser vos compétences C# pour développer aussi bien sur Windows, Windows Phone, que sur IOS et Android. </font></p>  <p><font size="3">Dans le même ordre d’idée avec </font><a href="https://www.visualstudio.com/fr-fr/cordova-vs.aspx"><font size="3">l’outil Visual Studio pour Apache Cordova</font></a><font size="3"> vous pourrez sans aucun problème développer sur les différentes plates-formes mobiles, mais cette fois-ci en réutilisant vos compétences Javascript.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Développeurs, connaissez-vous Microsoft Message Analyser, l’outil indispensable pour tout décortiquer ?</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/dveloppeurs-connaissez-vous-microsoft-message-analyser-loutil-indispensable-pour-tout-dcortiquer</link>
      <pubDate>Wed, 18 Mar 2015 10:12:00 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/03/18/dveloppeurs-connaissez-vous-microsoft-message-analyser-loutil-indispensable-pour-tout-dcortiquer/</guid>
      <description><![CDATA[Dans le temps j&rsquo;utilisais Microsoft Network Monitor, pour capturer tous les paquets...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small;">Dans le temps j&rsquo;utilisais <a href="https://www.microsoft.com/en-us/download/details.aspx?id=4865">Microsoft Network Monitor</a>, pour capturer tous les paquets r&eacute;seau afin d&rsquo;analyser le trafique lorsque des probl&egrave;mes survenaient.</span></p>
<p><span style="font-size: small;">Aujourd&rsquo;hui,&nbsp; <a href="https://www.microsoft.com/en-us/download/details.aspx?id=44226">Microsoft Message Analyser</a>, va encore plus loin, il permet de capturer &agrave; peu pr&ecirc;t tout et n&rsquo;importe quoi.</span></p>
<p><span style="font-size: small;">Dans cette figure je sniff l&rsquo;appel au protocole HTTP. Vous me direz mais Fiddler le fait tr&egrave;s bien. Soit, mais ici, je peut aller encore plus loin dans l&rsquo;analyse et descendre dans les couches basses.</span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0513.image_31213EA1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0513.image_5F00_31213EA1.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/1072.image_thumb_00241EA5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/1072.image_5F00_thumb_5F00_00241EA5.png" alt="image" width="860" height="464" border="0" /></a></p>
<p><span style="font-size: small;">Je peux &eacute;galement analyser mon trafic USB, si j&rsquo;ai un probl&egrave;me.</span></p>
<p><span style="font-size: small;">Par exemple dans cette figure, je n&rsquo;ai fait que connecter mon t&eacute;l&eacute;phone &agrave; mon port USB 3.0, et j&rsquo;ai pu tracer les diff&eacute;rentes &eacute;tapes. Ca peut aider c&rsquo;est ton jamais !!</span></p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0385.image_261C5FAC.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0385.image_5F00_261C5FAC.png"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0456.image_thumb_37231E40.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0456.image_5F00_thumb_5F00_37231E40.png" alt="image" width="871" height="470" border="0" /></a></p>
<p><span style="font-size: small;">Je pourrais &eacute;galement tracer les connections Bluetooth, les appels RPC, mais &eacute;galement les appels Syst&egrave;mes.</span></p>
<p><span style="font-size: small;">Il est capable, de lire des <a href="https://msdn.microsoft.com/en-us/library/vstudio/d5zhxt22(v=vs.120).aspx">Dumps</a>, des fichiers ETL (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx">Windows Event Tracing</a>) et autres, que je vous laisse d&eacute;couvrir dans la documentation qui ne fait pas moins de 450 Pages !!</span></p>
<p><span style="font-size: small;">En un mot il sait tout faire, on peut m&ecirc;me l&rsquo;&eacute;tendre et participer &agrave; son am&eacute;lioration.</span></p>
<p><span style="font-size: small;">C&rsquo;est une grosse artillerie &agrave; d&eacute;gainer, si les autres outils et m&eacute;thodes ne suffisent plus.</span></p>
<p><span style="font-size: small;">Eric</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Développeurs, connaissez-vous l’outil Windows powercfg.exe l’outil indispensable pour être un Green Développeur ?</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/dveloppeurs-connaissez-vous-loutil-windows-powercfg-exe-loutil-indispensable-pour-tre-un-green-dveloppeur</link>
      <pubDate>Thu, 12 Mar 2015 11:51:59 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/03/12/dveloppeurs-connaissez-vous-loutil-windows-powercfg-exe-loutil-indispensable-pour-tre-un-green-dveloppeur/</guid>
      <description><![CDATA[&#160;  &#160;  A l’heure ou tout doit être green, le développeur aussi à un rôle à jouer dans ce...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p>&#160;</p>  <p><font size="3">A l’heure ou tout doit être green, le développeur aussi à un rôle à jouer dans ce domaine. Lancer la commande </font><font size="3"><strong>powercfg /energy , </strong>elle vous permettra d’obtenir un rapport d’efficacité énergétique sur votre système et donc également sur votre application.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0042.image_76304934.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0042.image_5F00_76304934.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0550.image_thumb_4A134C43.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0550.image_5F00_thumb_5F00_4A134C43.png" width="709" height="450" /></a></p>  <p><font size="3">En voici un extrait</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2806.image_476D2143.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2806.image_5F00_476D2143.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/8713.image_thumb_2E07AEBA.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/8713.image_5F00_thumb_5F00_2E07AEBA.png" width="746" height="467" /></a></p>  <p>&#160;</p>  <p><a href="https://blogs.msdn.com/b/devosaure/archive/2015/03/02/d-233-veloppeurs-connaissez-vous-l-outil-windows-psr-exe-l-enregistreur-d-actions-utilisateurs.aspx"><font size="3">Enregistreur d’action Utilisateur PSR.EXE</font></a></p>  <p><font size="3">Eric</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Développeurs, connaissez-vous l’outil Windows, PSR.EXE, l’enregistreur d’actions utilisateurs ?</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/dveloppeurs-connaissez-vous-loutil-windows-psr-exe-lenregistreur-dactions-utilisateurs</link>
      <pubDate>Mon, 02 Mar 2015 02:20:43 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/03/02/dveloppeurs-connaissez-vous-loutil-windows-psr-exe-lenregistreur-dactions-utilisateurs/</guid>
      <description><![CDATA[&#160;  Dans cette série de billets, je me propose de faire le tour d’un certain nombre d’outils de...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p><font size="3">Dans cette série de billets, je me propose de faire le tour d’un certain nombre d’outils de Windows qui sont relativement méconnus, mais qui peuvent vous aider, vous développeurs, dans votre démarche de résolution de problèmes.</font></p>  <p><font size="3">Aujourd’hui nous allons manipuler l’outil PSR.EXE (Problem Steps Recorder), qui permet d’enregistrer des actions utilisateurs.</font></p>  <p><font size="3">Imaginons que l’un de l’utilisateur de votre application, ne soit pas en mesure de vous expliquer clairement le problème qu’il rencontre. Il suffit alors de lui demander de lancer sur la ligne de commande l’outil <strong>PSR.EXE</strong> et d’enregistrer les actions, et éventuellement d’ajouter des commentaires.</font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2185.image_5338B153.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2185.image_5F00_5338B153.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/5658.image_thumb_02F659D3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/5658.image_5F00_thumb_5F00_02F659D3.png" width="605" height="69" /></a></p>  <p><font size="3">Appuyer sur “<strong>Commencer l’enregistrement</strong>”</font></p>  <p><font size="3">L’idée ici est d’enregistrer le lancement d’une application comme Excel par exemple, de taper dans une cellule une formule de calcule =100+100, et d’ajouter un commentaire, qui permettra de donner plus d’informations aux développeurs.</font></p>  <p><font size="3">Une fois que l’enregistrement est fait, un rapport est crée, dont voici un extrait.</font></p>  <p><font size="3"><strong>Note :</strong> L’utilisateur peut sauvegarder le rapport, sous forme d’un ZIP, et vous l’envoyer.</font></p>  <p><font size="3"></font></p>  <p><font size="3"><em><strong>Extrait de rapport : </strong></em></font></p>  <p><font size="3"></font></p>  <h3>Étapes enregistrées</h3>  <p>Ce fichier contient toutes les étapes et informations enregistrées pour vous aider à les décrire aux autres. </p>  <p>Avant de partager ce fichier, vérifiez les éléments suivants :</p>  <ul>   <li>Les étapes ci-dessous décrivent précisément l’enregistrement. </li>    <li>Toutes les informations ci-dessous et les captures d’écran peuvent être dévoilées aux autres. </li> </ul>  <p>Les mots de passe et le texte tapé n’ont pas été enregistrés, à l’exception des touches de fonction et de raccourci utilisées.</p>  <p>Vous pouvez procéder comme suit :</p>  <ul>   <li><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Steps">Consulter les étapes enregistrées </a></li>    <li><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht!slide0001.htm">Consulter les étapes enregistrées sous forme de diaporama</a> </li>    <li><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#AdditionalDetails">Consulter les détails supplémentaires</a> </li> </ul>  <h3>Étapes</h3>  <p><a>Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step2">Suivant</a></p>  <p><b>Étape 1: (‎02/‎03/‎2015 10:38:28)</b> Cliqué(e) avec le bouton gauche par l’utilisateur </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/6242.1_304B7833.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/6242.1_5F00_304B7833.png"><img title="1" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="1" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2068.1_thumb_5B266CF6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2068.1_5F00_thumb_5F00_5B266CF6.png" width="877" height="496" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step1">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step3">Suivant</a></p>  <p><b>Étape 2: (‎02/‎03/‎2015 10:38:34)</b> Saisie au clavier par l’utilisateur sur « Search (fenêtre) » dans « Search » [... ENTREE] </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/6237.2_11971EF9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/6237.2_5F00_11971EF9.png"><img title="2" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="2" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0317.2_thumb_07D1B781.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0317.2_5F00_thumb_5F00_07D1B781.png" width="886" height="500" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step2">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step4">Suivant</a></p>  <p><b>Étape 3: (‎02/‎03/‎2015 10:38:42)</b> Début du glissement de la souris par l’utilisateur sur « Excel (fenêtre) » dans « Excel » </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/4401.3_6C2FBC3B.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/4401.3_5F00_6C2FBC3B.png"><img title="3" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="3" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/8078.3_thumb_06FE72F9.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/8078.3_5F00_thumb_5F00_06FE72F9.png" width="886" height="500" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step3">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step5">Suivant</a></p>  <p><b>Étape 4: (‎02/‎03/‎2015 10:38:44)</b> Fin du glissement de la souris par l’utilisateur sur « Excel (fenêtre) » dans « Excel » </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2502.4_18716482.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2502.4_5F00_18716482.png"><img title="4" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="4" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/7750.4_thumb_256DD544.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/7750.4_5F00_thumb_5F00_256DD544.png" width="888" height="501" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step4">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step6">Suivant</a></p>  <p><b>Étape 5: (‎02/‎03/‎2015 10:38:48)</b> Clic avec le bouton gauche par l’utilisateur sur « Nouveau classeur (Lien hypertexte) » dans « Excel » </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/1768.5_5DAEDD0D.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/1768.5_5F00_5DAEDD0D.png"><img title="5" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="5" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0741.5_thumb_5CD907D4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0741.5_5F00_thumb_5F00_5CD907D4.png" width="885" height="500" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step5">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step7">Suivant</a></p>  <p><b>Étape 6: (‎02/‎03/‎2015 10:38:51)</b> Clic avec le bouton gauche par l’utilisateur sur « Classeur1 () » dans « Classeur1 - Excel » </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/6888.6_4A269ECE.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/6888.6_5F00_4A269ECE.png"><img title="6" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="6" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/8078.6_thumb_0DFD63D7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/8078.6_5F00_thumb_5F00_0DFD63D7.png" width="879" height="496" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step6">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step8">Suivant</a></p>  <p><b>Étape 7: (‎02/‎03/‎2015 10:38:54)</b> Saisie au clavier par l’utilisateur sur « Classeur1 () » dans « Classeur1 - Excel » [...] </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/5635.7_23E6D627.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/5635.7_5F00_23E6D627.png"><img title="7" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="7" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/4188.7_thumb_439840A0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/4188.7_5F00_thumb_5F00_439840A0.png" width="885" height="500" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step7">Précédent</a> <a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step9">Suivant</a></p>  <p><b>Étape 8: (‎02/‎03/‎2015 10:38:55)</b> Saisie au clavier par l’utilisateur sur « Modifier l’élément (Modifier) » dans « Classeur1 - Excel » [... ENTREE] </p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/0841.8_759271DB.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/0841.8_5F00_759271DB.png"><img title="8" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="8" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/3513.8_thumb_0B7BE42C.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/3513.8_5F00_thumb_5F00_0B7BE42C.png" width="888" height="501" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#Step8">Précédent</a> <a>Suivant</a></p>  <p><b>Étape 9: (‎02/‎03/‎2015 10:39:09)</b> Commentaire de l’utilisateur: <strong>&quot;Ceci est mon commentaire&quot; </strong></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/7585.9_489F9FB1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/7585.9_5F00_489F9FB1.png"><img title="9" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-top-width: 0px" border="0" alt="9" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/4426.9_thumb_737A9474.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/4426.9_5F00_thumb_5F00_737A9474.png" width="885" height="500" /></a></p>  <p><a href="mhtml:file://C:\Users\ericv\AppData\Local\Temp\Temp1_PSR.ZIP\Recording_20150302_1040.mht#ReportTop">Retourner en haut de la page... </a></p>  <p><a href="https://blogs.msdn.com/b/devosaure/archive/2015/03/12/d-233-veloppeurs-connaissez-vous-l-outil-windows-powercfg-exe-l-outil-indispensable-pour-234-tre-un-green-d-233-veloppeur.aspx"><font size="3">Développeurs, connaissez-vous l’outil Windows powercfg.exe l’outil indispensable pour être un Green Développeur ?</font></a><font size="3">.</font></p>  <p>&#160;</p>  <p>Eric</p>]]></content:encoded>
    </item>
    <item>
      <title>Windows Management Instrumentation avec du code C++</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/windows-management-instrumentation-avec-du-code-c</link>
      <pubDate>Thu, 19 Feb 2015 09:28:00 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2015/02/19/windows-management-instrumentation-avec-du-code-c/</guid>
      <description><![CDATA[&#160;  Il y a quelques semaines, j’ai travaillé sur un bout de code, afin d’activer le contrôle...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p><font size="3">Il y a quelques semaines, j’ai travaillé sur un bout de code, afin d’activer le contrôle parental d’un compte utilisateur sur Windows 8.1. </font><font size="3">Naïvement je pensais qu’il existait une API Win32 simple pour le faire du style&#160; :</font></p>  <p><font size="3">BOOL EnableParentalControl(LPWSTR username).</font></p>  <p><font size="3">Mais en y regardant de plus près, cette simple API n’existe pas. En fouillant plus en profondeur, il faut passer par l’infrastructure <a href="https://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx">Windows Management&#160; Instrumentation</a> (WMI). </font></p>  <p><font size="3">Ce billet a donc juste pour vocation, non pas de vous expliquer ce qu’est WMI, mais à vous montrer comment faire un appel WMI en C++. Vous allez voir c’est existant.</font></p>  <p><font size="3">Tout d’abord, il faut savoir ou trouver les différentes informations, espace de nom, signature des méthodes, propriétés, en gros le schéma utile pour nos différents appels. Pour le contrôle parental, il faut ouvrir le fichier <strong>wpcsprov.mof</strong>, dans le répertoire c:\windows\system32.</font></p>  <p><font size="3">Dans ce fichier, vous pourrez y trouver l’espace de nom racine d'où nous partirons pour effectuer nos requêtes.      <br />#pragma namespace(<a>\\\\.\\ROOT\\CIMV2\\Applications\\WindowsParentalControls</a>)</font></p>  <p><font size="3">Nous y retrouverons le nom de la classe <strong>WpCSystemSettings, </strong>avec ces méthodes associées <strong>AddUser</strong> et <strong>RemoveUser</strong> et leurs signatures.</font></p>  <p><font size="1">//**************************************************************************      <br />//* Class: WpcSystemSettings       <br />//* Derived from:       <br />//**************************************************************************       <br />[Singleton: DisableOverride ToInstance ToSubClass, Description(&quot;Stores system-wide Wpc settings&quot;): ToInstance ToSubClass, provider(&quot;WpcSProv&quot;): ToInstance, dynamic: ToInstance]       <br />class WpcSystemSettings       <br />{       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;Link to the current games rating system in force for the machine&quot;): ToInstance ToSubClass] string CurrentGamesRatingSystem;       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;HTTP app filter exemption list&quot;): ToInstance ToSubClass] string HTTPExemptionList[];       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, Description(&quot;Windows HTTP app filter exemption list&quot;): ToInstance ToSubClass] string WinHTTPExemptionList[];       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;HTTP URL filter exemption list&quot;): ToInstance ToSubClass] string URLExemptionList[];       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, Description(&quot;Windows HTTP URL filter exemption list&quot;): ToInstance ToSubClass] string WinURLExemptionList[];       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;Number of days until a balloon reminder for checking the logs&quot;): ToInstance ToSubClass] uint32 LogViewReminderInterval;       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;Last time the admin checked the log viewer&quot;): ToInstance ToSubClass] DateTime LastLogView;       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;ID of current web filter&quot;): ToInstance ToSubClass] string FilterID;       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;Name of current web filter&quot;): ToInstance ToSubClass] string FilterName;       <br />&#160;&#160;&#160; [Description(&quot;Creates settings for a new User SID&quot;): ToInstance ToSubClass, Implemented: ToInstance ToSubClass, Static: ToInstance ToSubClass] uint32 <strong>AddUser</strong>([Description(&quot;SID to create settings for&quot;): ToInstance ToSubClass, IN] string strSID);       <br />&#160;&#160;&#160; [Description(&quot;Removes settings for a user account&quot;): ToInstance ToSubClass, Implemented: ToInstance ToSubClass, Static: ToInstance ToSubClass] uint32 <strong>RemoveUser</strong>([Description(&quot;SID of the account to delete settings for&quot;): ToInstance ToSubClass, IN] string strSID);       <br />};</font></p>  <p><font size="3">Puis la classe <strong>WpcUserSettings</strong>, qui possède les propriétés et leurs signatures que nous utiliserons pour paramétrer et activer&#160; le contrôle parental. </font></p>  <p><font size="1">//**************************************************************************      <br />//* Class: WpcUserSettings       <br />//* Derived from:       <br />//**************************************************************************       <br />[Description(&quot;Per-account Windows Parental Controls Settings&quot;): ToInstance ToSubClass, provider(&quot;WpcSprov&quot;): ToInstance, dynamic: ToInstance]       <br />class WpcUserSettings       <br />{       <br />&#160;&#160;&#160; [key, read: ToInstance ToSubClass, Description(&quot;SID of the user account owning these settings&quot;): ToInstance ToSubClass] string SID;       <br />&#160;&#160;&#160; [read: ToInstance ToSubClass, write: ToInstance ToSubClass, Description(&quot;Is WPC enabled for this user&quot;): ToInstance ToSubClass] boolean WpcEnabled;       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Is logging enabled for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] boolean LoggingRequired;       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Are hourly restrictions enabled for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] boolean HourlyRestrictions;       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Are time allowance restrictions enabled for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] boolean TimeAllowanceRestrictions;       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Are override requests enabled for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] boolean OverrideRequests;       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Logon Hours mask for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] uint32 LogonHours[7];       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Logon Half-Hours (30 minute offset) mask for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] uint32 LogonHalfHours[7];       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Daily minute allowance&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] uint32 AllowanceMinutes[7];       <br />&#160;&#160;&#160; [write: ToInstance ToSubClass, Description(&quot;Are application restrictions enabled for this user&quot;): ToInstance ToSubClass, read: ToInstance ToSubClass] boolean AppRestrictions;       <br />};</font></p>  <p><font size="1"></font></p>  <p><font size="3">Une fois que l’on a compris que tout est dans ce fichier, on peut commencer à coder.</font></p>  <p><font size="3">WMI étant une API issue du monde <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms680573(v=vs.85).aspx">COM</a>, il faut initialiser COM.       <br /></font></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8b5a6e8b-817d-4f62-b8ef-149e4e580fea" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000">::</span><span style="background:#ffffff;color:#ff0000">CoInitializeEx</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2f4f4f">COINIT_APARTMENTTHREADED</span><span style="background:#ffffff;color:#000000">);</span></div> </div> </div>    <p>Ensuite comme il est indiqué dans l’exemple MSDN suivant <a href="https://msdn.microsoft.com/en-us/library/aa390423(v=vs.85).aspx">Getting WMI Data from the Local Computer</a>, il <strong>faudrait</strong> également initialiser la sécurité COM avec l’API suivante : </p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:21546001-b207-469c-8890-1492ebc43da1" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#ff0000">CoInitializeSecurity</span><span style="background:#ffffff;color:#000000">(</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,      </span><span style="background:#ffffff;color:#008000">// Security descriptor </span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000">-1,      </span><span style="background:#ffffff;color:#008000">// COM negotiates authentication service</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,      </span><span style="background:#ffffff;color:#008000">// Authentication services</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,      </span><span style="background:#ffffff;color:#008000">// Reserved</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">RPC_C_AUTHN_LEVEL_DEFAULT</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#008000">// Default authentication level for proxies</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">RPC_C_IMP_LEVEL_IMPERSONATE</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#008000">// Default Impersonation level for proxies</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,      </span><span style="background:#ffffff;color:#008000">// Authentication info</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#2f4f4f">EOAC_NONE</span><span style="background:#ffffff;color:#000000">,     </span><span style="background:#ffffff;color:#008000">// Additional capabilities of the client or server</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">);      </span><span style="background:#ffffff;color:#008000">// Reserved</span></div> </div> </div>    <p><font size="3">Néanmoins, mon code faisant partie d’un projet beaucoup plus vaste qui sera appelé à partir d’une application C# .NET et comme chacun sait, le CLR de .NET a déjà initialisé COM et sa sécurité pour nous, il n’est donc pas forcément nécessaire de le faire. Tout dépend du contexte.</font></p>  <p><font size="3">Venons-en à WMI proprement dit.</font></p>  <p><font size="3">La première chose à faire est d’initialiser un <a href="https://msdn.microsoft.com/en-us/library/aa389749(v=vs.85).aspx">IWbemLocator</a>.&#160; </font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d89b72ca-cb4a-43a7-8fd2-fd6b8efb27b2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#000000">  </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>   <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemLocator</span><span style="background:#ffffff;color:#000000">&gt; pLocator;</span><br>   <span style="background:#ffffff;color:#000000">hr=pLocator.CoCreateInstance(CLSID_WbemLocator,</span><br>                                <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2f4f4f">CLSCTX_INPROC_SERVER</span><span style="background:#ffffff;color:#000000"> | </span><span style="background:#ffffff;color:#2f4f4f">CLSCTX_LOCAL_SERVER</span><span style="background:#ffffff;color:#000000">);</span><br>   <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>   <span style="background:#ffffff;color:#000000">{          </span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>   <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3">J’utilise ici directement un smart pointeur </font><a href="https://msdn.microsoft.com/en-us/library/ezzw7k98.aspx"><font size="3">CComPtr</font></a><font size="3"> qui permet d’éliminer les fuites mémoires en effectuant automatiquement le décompte de références.</font></p>  <p><font size="3">Ensuite il faut se connecter au service WMI qui nous intéresse, c’est à dire le contrôle parental. Ce service est symbolisé ici par l’espace de nom :</font></p>  <p><font size="3"><a>\\\\.\\ROOT\\CIMV2\\Applications\\WindowsParentalControls</a></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:0de16a95-7ad5-4f2f-a402-49a345c88476" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemServices</span><span style="background:#ffffff;color:#000000">&gt; piWmiServices;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrServiceNameSpace = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;&#92;&#92;&#92;&#92;.&#92;&#92;root&#92;&#92;CIMV2&#92;&#92;Applications&#92;&#92;WindowsParentalControls&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">//Connect to the server</span><br>   <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#000000">hr=pLocator-&gt;ConnectServer(bstrServiceNameSpace,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,                    </span><span style="background:#ffffff;color:#008000">// User name. NULL = current user</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,                    </span><span style="background:#ffffff;color:#008000">// User password. NULL = current</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,                    </span><span style="background:#ffffff;color:#008000">// Locale. NULL indicates current</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,                    </span><span style="background:#ffffff;color:#008000">// Security flags.</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000">0,                       </span><span style="background:#ffffff;color:#008000">// Authority (e.g. Kerberos)</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,                    </span><span style="background:#ffffff;color:#008000">// Context object </span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000">&amp;piWmiServices            </span><span style="background:#ffffff;color:#008000">// pointer to IWbemServices proxy</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3"><strong>Note</strong> : </font><font size="3">Ne pas oublier de libérer la chaine BSTR une fois utilisée </font><font size="3"><strong>SysFreeString</strong>(bstrServiceNameSpace)</font></p>  <p><font size="3">La méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa391769(v=vs.85).aspx">ConnectServer</a></strong> retourne un proxy vers une interface <a href="https://msdn.microsoft.com/en-us/library/aa392093(v=vs.85).aspx">IWbemServices</a>. Ce proxy nous servira pour tous les autres appels. Mais comme nous sommes dans un contexte qui s’exécutera en RPC, il est important avant tout, de pouvoir se faire passer comme la bonne autorité et pour ce faire nous allons utiliser la méthode <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms692692(v=vs.85).aspx">CoSetProxyBlanket</a> sur notre proxy.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:025f92d0-110b-4154-95ff-ee5c7038bb02" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>       <span style="background:#ffffff;color:#000000">hr=</span><span style="background:#ffffff;color:#ff0000">CoSetProxyBlanket</span><span style="background:#ffffff;color:#000000">(piWmiServices,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">RPC_C_AUTHN_WINNT</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">RPC_C_AUTHZ_NONE</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">RPC_C_AUTHN_LEVEL_CALL</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">RPC_C_IMP_LEVEL_IMPERSONATE</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">,</span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2f4f4f">EOAC_NONE</span><br>   <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3">Sans cet appel, tous les autres appels échoueront.</font></p>  <p><font size="3">Maintenant que nous avons notre proxy en bon état de marche, nous allons pouvoir effectuer nos premières requêtes.</font></p>  <p><font size="3">La première étant d’exécuter la méthode <strong>AddUser</strong>, mentionnée plus haut dans le fichier <strong>wpcsprov.mof</strong>, pour la classe <strong>WpcSystemSettings.</strong></font></p>  <p><font size="3">Tout d’abord il faut obtenir une instance de cette classe. Nous allons utiliser la méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa392109(v=vs.85).aspx">GetObject</a></strong>, de notre proxy, en lui passant comme paramètre le nom de la classe sous forme d’une chaine de caractères.</font></p>  <p><font size="3">L’instance sera retournée en tant qu’interface <a href="https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-US&amp;k=k(%22wbemcli%2FIWbemClassObject%22);k(IWbemClassObject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-C%2B%2B);k(TargetOS-Windows);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5)&amp;rd=true">IWbemClassObject</a></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8f878980-fd8c-4459-ac83-0b95e7ed3839" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemClassObject</span><span style="background:#ffffff;color:#000000">&gt; pObjectWpcSystemSettings;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrPath = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;WpcSystemSettings&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">hr=piWmiServices-&gt;GetObject(bstrPath, 0, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, &amp;pObjectWpcSystemSettings, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">);</span><br> <br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3"></font></p>  <p><font size="3">Ensuite sur l’instance de cette classe, nous allons devoir récupérer pour la méthode AddUser, une autre instance de l’interface <a href="https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-US&amp;k=k(%22wbemcli%2FIWbemClassObject%22);k(IWbemClassObject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-C%2B%2B);k(TargetOS-Windows);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5)&amp;rd=true">IWbemClassObject</a> qui définira les paramètres d’entrée de la méthode. (En regardant dans le fichier mof, cette méthode prend comme paramètre une chaine nommée <strong>strSID</strong>. Notez le nom il aura son importance par la suite)</font></p>  <p>uint32 <strong>AddUser</strong>([Description(&quot;SID to create settings for&quot;): ToInstance ToSubClass, IN] string strSID); </p>  <p><font size="3"><strong>Note</strong> : Nous n’utiliserons pas le paramètre de retour de type uint32.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f4338d1a-09fa-483d-a87a-d44533974e15" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemClassObject</span><span style="background:#ffffff;color:#000000">&gt; piObjectSignatureIn;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemClassObject</span><span style="background:#ffffff;color:#000000">&gt; piObjectSignatureOut;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrMethod = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;AddUser&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">hr=pObjectWpcSystemSettings-&gt;GetMethod(bstrMethod, 0, &amp;piObjectSignatureIn, &amp;piObjectSignatureOut);</span><br> <br> <br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3">La méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa391443(v=vs.85).aspx">GetMethod</a></strong>, récupère une instance de la classe <a href="https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-US&amp;k=k(%22wbemcli%2FIWbemClassObject%22);k(IWbemClassObject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-C%2B%2B);k(TargetOS-Windows);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5)&amp;rd=true">IWbemClassObject</a>&#160; (<strong>piObjectSignatureIn</strong>) pour la méthode <strong>AddUser</strong>, qui lui est passée en paramètre en tant que chaine de caractères.</font></p>  <p><font size="3">Nous allons utiliser l’instance <strong>piObjectSignatureIn</strong>, afin de lui affecter le paramètre <strong>strSID</strong> avec la bonne valeur.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:54e9206a-278f-4e2e-a836-315dd5814823" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">VARIANT</span><span style="background:#ffffff;color:#000000"> varSID;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> SID = ::</span><span style="background:#ffffff;color:#ff0000">GetUserSID</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;MonServeur&quot;</span><span style="background:#ffffff;color:#000000">, L</span><span style="background:#ffffff;color:#a31515">&quot;NomUtilisateur&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">InitVariantFromString</span><span style="background:#ffffff;color:#000000">(SID, &amp;varSID);</span><br>       <span style="background:#ffffff;color:#000000"></span><br>       <span style="background:#ffffff;color:#000000">piObjectSignatureIn-&gt;Put(L</span><span style="background:#ffffff;color:#a31515">&quot;strSID&quot;</span><span style="background:#ffffff;color:#000000">, 0, &amp;varSID, 0);</span><br> <br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">VariantClear</span><span style="background:#ffffff;color:#000000">(&amp;varSID);</span></div> </div> </div>  <p><font size="3">La méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa391455(v=vs.85).aspx">Put</a></strong> de notre instance de classe pousse pour le paramètre strSID, la valeur de notre SID.</font></p>  <p><font size="3"><strong>Note :</strong> Il est possible de vérifier si cela a bien fonctionné en utilisant la méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa391448(v=vs.85).aspx">GetObjectText</a></strong> de notre instance.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4d7a8112-a873-412a-9f32-ccf763be2835" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> debug;</span><br>         <span style="background:#ffffff;color:#000000">hr = piObjectSignatureIn-&gt;GetObjectText(0, &amp;debug);</span><br>         <span style="background:#ffffff;color:#000000"></span></div> </div> </div>  <p><font size="3">Vous devriez obtenir un texte au format mof qui ressemble à cela      <br /></font></p>  <p>[abstract]class __PARAMETERS    <br />{     <br />[Description(&quot;SID to create settings for&quot;): ToInstance ToSubClass, IN, ID(0): DisableOverride ToInstance]     <br />string strSID = &quot;S-1-5-21-203241617-564013427-62682210-1111&quot;;     <br />};     <br /></p>  <p><font size="3">Un SID (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa379571(v=vs.85).aspx">Security Identifier</a>) dans Windows est une valeur unique qui permet d’identifier par exemple un utilisateur. </font></p>  <p><font size="3">Voici la méthode qui permet de récupérer un SID pour un utilisateur donné.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:dcc8028f-85b0-4fb0-9e3c-02692f8a1a97" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000">GetUserSID</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">servername</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">username</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000"> dwStatus = </span><span style="background:#ffffff;color:#6f008a">NERR_Success</span><span style="background:#ffffff;color:#000000">;</span><br>   <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">LPUSER_INFO_4</span><span style="background:#ffffff;color:#000000">lpBufUserInfo = </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">;</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000"> LevelUserInfo = 4;</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> sid = </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">;</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">try</span><br>     <span style="background:#ffffff;color:#000000">{</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">//Get the User&#39;s SID</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">CheckNERRStatusAndThrowNERRStatus</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#ff0000">NetUserGetInfo</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#808080">servername</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#808080">username</span><span style="background:#ffffff;color:#000000">, LevelUserInfo, (</span><span style="background:#ffffff;color:#2b91af">LPBYTE</span><span style="background:#ffffff;color:#000000">*) &amp;lpBufUserInfo));</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">PSID</span><span style="background:#ffffff;color:#000000"> CurrentPSID = lpBufUserInfo-&gt;usri4_user_sid;</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">ConvertSidToStringSid</span><span style="background:#ffffff;color:#000000">(CurrentPSID, &amp;sid);</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">//Check if we have an error converting the string</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">CheckNERRStatusAndThrowNERRStatus</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#ff0000">GetLastError</span><span style="background:#ffffff;color:#000000">());</span><br>     <span style="background:#ffffff;color:#000000">}</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">StatusException</span><span style="background:#ffffff;color:#000000"> ex)</span><br>     <span style="background:#ffffff;color:#000000">{</span><br>         <span style="background:#ffffff;color:#000000">dwStatus = ex.GetStatus();</span><br>     <span style="background:#ffffff;color:#000000">}</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (lpBufUserInfo != </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">)</span><br>     <span style="background:#ffffff;color:#000000">{</span><br>         <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">NetApiBufferFree</span><span style="background:#ffffff;color:#000000">(lpBufUserInfo);</span><br>     <span style="background:#ffffff;color:#000000">}</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> sid;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3">Une fois que la propriété est bien initialisée, on peut alors exécuter la méthode AddUser</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8309aaaa-4e4d-44ff-b7c4-3ea9fdecff35" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrPath = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;WpcSystemSettings&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrMethod = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;AddUser&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <br>       <span style="background:#ffffff;color:#000000">piWmiServices-&gt;ExecMethod(bstrPath, bstrMethod, 0, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, piObjectSignatureIn, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">)</span><br> <br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br>       <span style="background:#ffffff;color:#000000">{          </span><br>           <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> StatusException(</span><span style="background:#ffffff;color:#6f008a">NERR_CouldNotEnableParentalControl</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>  <p><font size="3">La dernière chose à faire maintenant est d’activer le contrôle parental pour cet utilisateur.</font></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1396bf60-868b-4404-bfe5-d83a69e75522" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px;"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IEnumWbemClassObject</span><span style="background:#ffffff;color:#000000">&gt; piEnumerator;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IWbemClassObject</span><span style="background:#ffffff;color:#000000">&gt; piEnableWPC;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">VARIANT</span><span style="background:#ffffff;color:#000000"> varEnableParentalControls;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">ULONG</span><span style="background:#ffffff;color:#000000"> uReturned = 0;</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">LPWSTR</span><span style="background:#ffffff;color:#000000"> SID = ::</span><span style="background:#ffffff;color:#ff0000">GetUserSID</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;NomServeur&quot;</span><span style="background:#ffffff;color:#000000">, L</span><span style="background:#ffffff;color:#a31515">&quot;Nomutilisateur&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">CComBSTR</span><span style="background:#ffffff;color:#000000"> bstrQuery(L</span><span style="background:#ffffff;color:#a31515">&quot;Select * from WpcUserSettings where SID=&#39;&quot;</span><span style="background:#ffffff;color:#000000">); </span><br>       <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#2b91af">BSTR</span><span style="background:#ffffff;color:#000000"> bstrWQL = </span><span style="background:#ffffff;color:#ff0000">SysAllocString</span><span style="background:#ffffff;color:#000000">(L</span><span style="background:#ffffff;color:#a31515">&quot;WQL&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>       <span style="background:#ffffff;color:#000000"></span><br>       <span style="background:#ffffff;color:#000000">bstrQuery.Append(SID);</span><br>       <span style="background:#ffffff;color:#000000">bstrQuery.Append(L</span><span style="background:#ffffff;color:#a31515">&quot;&#39;&quot;</span><span style="background:#ffffff;color:#000000">);</span><br>      <span style="background:#ffffff;color:#000000">hr= piWmiServices-&gt;ExecQuery(bstrWQL, bstrQuery, </span><span style="background:#ffffff;color:#2f4f4f">WBEM_FLAG_FORWARD_ONLY</span><span style="background:#ffffff;color:#000000">,</span><br>                                    <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, &amp;piEnumerator)</span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">///FAILED(hr)</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#000000"> hr=piEnumerator-&gt;Next(0, 1, &amp;piEnableWPC, &amp;uReturned);</span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">///FAILED(hr)</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#000000"> hr=</span><span style="background:#ffffff;color:#ff0000">InitVariantFromBoolean</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">TRUE</span><span style="background:#ffffff;color:#000000">, &amp;varEnableParentalControls);     </span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">///FAILED(hr)</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#000000"> hr=piEnableWPC-&gt;Put(L</span><span style="background:#ffffff;color:#a31515">&quot;WpcEnabled&quot;</span><span style="background:#ffffff;color:#000000">, 0, &amp;varEnableParentalControls, 0);</span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">///FAILED(hr)</span><br>     <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#000000"> hr=piWmiServices-&gt;PutInstance(piEnableWPC, 0, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#6f008a">NULL</span><span style="background:#ffffff;color:#000000">);</span><br> <br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">SysFreeString</span><span style="background:#ffffff;color:#000000">(bstrWQL);     </span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">SysFreeString</span><span style="background:#ffffff;color:#000000">(bstrQuery);     </span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#ff0000">VariantClear</span><span style="background:#ffffff;color:#000000">(&amp;varEnableParentalControls);</span><br>      <span style="background:#ffffff;color:#000000"></span><span style="background:#ffffff;color:#008000">///....</span></div> </div> </div>    <p><font size="3">Pour ce faire on utilise la méthode <strong><a href="https://msdn.microsoft.com/en-us/library/aa392107(v=vs.85).aspx">ExecQuery</a></strong> de notre instance de service WMI. On parle ici bien d’une requête qui ressemble à du SQL, mais qui est en fait au format <a href="https://msdn.microsoft.com/en-us/library/aa394606(v=vs.85).aspx">WQL</a> (SQL pour WMI)</font></p>  <p><font size="3">Cette méthode va retrouver tout simplement en fonction du SID de l’utilisateur une instance d’un enumérateur&#160; <a href="https://msdn.microsoft.com/query/dev12.query?appId=Dev12IDEF1&amp;l=EN-US&amp;k=k(%22wbemcli%2FIEnumWbemClassObject%22);k(IEnumWbemClassObject);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5);k(DevLang-C%2B%2B);k(TargetOS-Windows);k(TargetFrameworkMoniker-.NETFramework,Version%3Dv4.5)&amp;rd=true">IEnumWbemClassObject</a> sur la classe <strong>WpcUserSettings</strong>.</font></p>  <p><font size="3">Ensuite on instancie la propriété au travers de l’interface IWbemClassObject (piEnableWPC) avec la méthode <strong>Next.</strong></font></p>  <p><font size="3">On indique que l’on veut activer le contrôle parental à l’aide de la propriété <strong>WpcEnabled </strong>que l’on positionne à TRUE, via la méthode <strong>Put</strong>.</font></p>  <p><font size="3">Enfin on active réellement la propriété à l’aide de la méthode <a href="https://msdn.microsoft.com/en-us/library/aa392115(v=vs.85).aspx">PutInstance</a> de l’instance de notre service et le tour est joué.</font></p>  <p><font size="3"></font></p>  <p><font size="3">Vous me direz beaucoup de travail, pour une simple action <img class="wlEmoticon wlEmoticon-smile" style="border-top-style: none; border-left-style: none; border-bottom-style: none; border-right-style: none" alt="Sourire" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/1234.wlEmoticon-smile_5BEE23BF.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/1234.wlEmoticon_2D00_smile_5F00_5BEE23BF.png" /></font></p>  <p>&#160;</p>  <p><font size="3">Eric</font></p>  <p><font size="3"></font></p>  <p><font size="3">&#160;</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Sauvegarde par défaut dans OneDrive</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/sauvegarde-par-dfaut-dans-onedrive</link>
      <pubDate>Thu, 16 Oct 2014 02:19:24 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2014/10/16/sauvegarde-par-dfaut-dans-onedrive/</guid>
      <description><![CDATA[&#160;  Sur Windows 8.1 dans une application Windows Store, lorsque vous souhaitez sauvegarder un...]]></description>
      <content:encoded><![CDATA[<p>&#160;</p>  <p><font size="3">Sur Windows 8.1 dans une application Windows Store, lorsque vous souhaitez sauvegarder un fichier dans la librairie <strong>Documents</strong> par exemple comme illustré dans le code suivant : </font></p>  <p><font size="3"></font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:777fad74-07d3-4aae-988e-564dbf1e2152" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> docsLib = </span><span style="background:#ffffff;color:#2b91af">KnownFolders</span><span style="background:#ffffff;color:#000000">.DocumentsLibrary;</span><br> <span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> file=</span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> docsLib.CreateFileAsync(</span><span style="background:#ffffff;color:#a31515">&quot;MonFichier.txt&quot;</span><span style="background:#ffffff;color:#000000">);</span></div> </div> </div>  <p><font size="3"> Windows 8.1 utilise <strong>OneDrive</strong> par défaut. Il est possible dans les paramètres OneDrive | Stockage de fichiers de rendre inactif l’enregistrement automatique dans OneDrive. </font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/1030.image_2AE80709.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/1030.image_5F00_2AE80709.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/2437.image_thumb_7AC0BC45.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/2437.image_5F00_thumb_5F00_7AC0BC45.png" width="377" height="83" /></a> </p>  <p><font size="3">Néanmoins, cela demande une action utilisateur, pas toujours souhaitable. Pour remédier à cela voici comment faire par code.</font></p>  <p></p>  <p></p>  <p></p>  <p></p>  <p></p>  <p></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2b3959ef-2e34-43f1-9fe2-c7b3f085c114" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> documents = </span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">StorageLibrary</span><span style="background:#ffffff;color:#000000">.GetLibraryAsync(</span><span style="background:#ffffff;color:#2b91af">KnownLibraryId</span><span style="background:#ffffff;color:#000000">.Documents);</span><br> <span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">foreach</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> folder </span><span style="background:#ffffff;color:#0000ff">in</span><span style="background:#ffffff;color:#000000"> documents.Folders)</span><br> <span style="background:#ffffff;color:#000000"> {</span><br> <span style="background:#ffffff;color:#000000">     </span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> providerId = folder.Provider.Id;</span><br> <span style="background:#ffffff;color:#000000">     </span><span style="background:#ffffff;color:#0000ff">switch</span><span style="background:#ffffff;color:#000000"> (providerId)</span><br> <span style="background:#ffffff;color:#000000">     {</span><br> <span style="background:#ffffff;color:#000000">         </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#a31515">&quot;computer&quot;</span><span style="background:#ffffff;color:#000000">:</span><br> <span style="background:#ffffff;color:#000000">             </span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> folder.CreateFileAsync(</span><span style="background:#ffffff;color:#a31515">&quot;Librairie Document Local.txt&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">             </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">         </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#a31515">&quot;SkyDrive&quot;</span><span style="background:#ffffff;color:#000000">:</span><br> <span style="background:#ffffff;color:#000000">             </span><span style="background:#ffffff;color:#0000ff">await</span><span style="background:#ffffff;color:#000000"> folder.CreateFileAsync(</span><span style="background:#ffffff;color:#a31515">&quot;Librairie Document OneDrive.txt&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">             </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">         </span><span style="background:#ffffff;color:#0000ff">default</span><span style="background:#ffffff;color:#000000">:</span><br> <span style="background:#ffffff;color:#000000">             </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">     }</span><br> <span style="background:#ffffff;color:#000000"> }</span></div> </div> </div>  <p>&#160;</p>  <div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a04150a9-d9bc-4cac-b696-275662e5c109" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px">Mots clés Technorati : <a href="https://technorati.com/tags/OneDrive" rel="tag">OneDrive</a>,<a href="https://technorati.com/tags/Document" rel="tag">Document</a>,<a href="https://technorati.com/tags/Librairies" rel="tag">Librairies</a></div>]]></content:encoded>
    </item>
    <item>
      <title>ListBox, ListView et défilement automatique</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/listbox-listview-et-dfilement-automatique</link>
      <pubDate>Tue, 14 Oct 2014 09:01:46 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2014/10/14/listbox-listview-et-dfilement-automatique/</guid>
      <description><![CDATA[J’alimente un contrôle ListBox&#160; avec un UserControl qui affiche une conversation, comme...]]></description>
      <content:encoded><![CDATA[<p><font size="3"></font></p>  <p><font size="3">J’alimente un contrôle ListBox&#160; avec un UserControl qui affiche une conversation, comme illustré sur la figure suivante : </font></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/3731.image_400E77D0.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/3731.image_5F00_400E77D0.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; border-left: 0px; display: inline" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/7220.image_thumb_0DAD3502.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/7220.image_5F00_thumb_5F00_0DAD3502.png" width="330" height="336" /></a> </p>  <p><font size="3">L’idée c’est d’avoir 0% de code dans la vue, j’utilise donc le modèle MVVM mais le soucis c’est que lorsque le nombre d’éléments dépasse l’espace d’affichage de ma ListBox, aucun défilement automatique n’est effectué pour afficher le dernier élément.</font></p>  <p><font size="3">Pour contourner ce problème est n’avoir toujours aucun code derrière ma vue, je suis parti sur la solution qui consiste à créer une ListBox personnalisée (qui dérive de la ListBox standard), d’implémenter une <strong>DependencyProperty</strong> qui appellera automatiquement la méthode <strong>ScrollIntoView</strong> de la ListBox .</font></p>  <p>   <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:76c57f47-2e70-4102-84b1-2bb18fa136b0" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">CustomListBox</span><span style="background:#ffffff;color:#000000"> : </span><span style="background:#ffffff;color:#2b91af">ListBox</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">readonly</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">DependencyProperty</span><span style="background:#ffffff;color:#000000"> ScrollViewFromIndexProperty =</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">DependencyProperty</span><span style="background:#ffffff;color:#000000">.Register(</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#a31515">&quot;ScrollViewFromIndex&quot;</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000">),</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">CustomListBox</span><span style="background:#ffffff;color:#000000">), </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">PropertyMetadata</span><span style="background:#ffffff;color:#000000">(0, </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">PropertyChangedCallback</span><span style="background:#ffffff;color:#000000">(OnNewItemAdded))</span><br> <span style="background:#ffffff;color:#000000">            );</span><br> <br> <br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> CustomListBox()</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.DefaultStyleKey = </span><span style="background:#ffffff;color:#0000ff">typeof</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">CustomListBox</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">          </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> ScrollViewFromIndex</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000"> { </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000">)GetValue(ScrollViewFromIndexProperty); }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">set</span><span style="background:#ffffff;color:#000000"> {</span><br> <span style="background:#ffffff;color:#000000">                SetValue(ScrollViewFromIndexProperty, (</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000">)</span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                            </span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">private</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> OnNewItemAdded(</span><span style="background:#ffffff;color:#2b91af">DependencyObject</span><span style="background:#ffffff;color:#000000"> d, </span><span style="background:#ffffff;color:#2b91af">DependencyPropertyChangedEventArgs</span><span style="background:#ffffff;color:#000000"> e)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">          </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> CurrentIndex =(</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000">)e.NewValue;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">ListBox</span><span style="background:#ffffff;color:#000000"> CurrentList = d </span><span style="background:#ffffff;color:#0000ff">as</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ListBox</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (CurrentList!=</span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <br> <span style="background:#ffffff;color:#000000">                CurrentList.SelectedIndex=CurrentIndex;</span><br> <span style="background:#ffffff;color:#000000">                CurrentList.UpdateLayout();</span><br> <span style="background:#ffffff;color:#000000">                CurrentList.ScrollIntoView(CurrentList.SelectedItem);</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">        }       </span><br> <span style="background:#ffffff;color:#000000">    }</span></div> </div> </div> </p>  <p><font size="3"></font></p>  <p></p>  <p><font size="3">Je Bind la DependencyProperty <strong>ScrollViewFromIndex</strong> à BINDING_PROP_CURRENT_INDEX qui est elle même mis à jour à chaque fois qu’un nouvel élément est ajouté en tant que source de la ListBox.</font></p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6631c1ca-b732-4cc8-b6ba-6444f03debd1" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 300px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">ShareViews</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#a31515">CustomListBox</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000"> ItemsSource</span><span style="background:#ffffff;color:#0000ff">=&quot;{</span><span style="background:#ffffff;color:#a31515">Binding</span><span style="background:#ffffff;color:#ff0000"> BINDING_PROP_LISTMESSAGES}</span><span style="background:#ffffff;color:#0000ff">&quot;</span><span style="background:#ffffff;color:#ff0000"> Background</span><span style="background:#ffffff;color:#0000ff">=&quot;{</span><span style="background:#ffffff;color:#a31515">x</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#a31515">Null}</span><span style="background:#ffffff;color:#0000ff">&quot;</span><span style="background:#ffffff;color:#000000"> </span><br> <span style="background:#ffffff;color:#000000">           </span><span style="background:#ffffff;color:#ff0000"> ScrollViewFromIndex</span><span style="background:#ffffff;color:#0000ff">=&quot;{</span><span style="background:#ffffff;color:#a31515">Binding</span><span style="background:#ffffff;color:#ff0000"> BINDING_PROP_CURRENT_INDEX}</span><span style="background:#ffffff;color:#0000ff">&quot;</span></div> </div> </div>  <p>&#160;</p>  <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:91050acc-e303-4e3d-b2ea-26e0c900baec" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">private</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> m_CurrentIndex;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> BINDING_PROP_CURRENT_INDEX</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000"> { </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_CurrentIndex; }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">set</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.SetProperty(</span><span style="background:#ffffff;color:#0000ff">ref</span><span style="background:#ffffff;color:#000000"> m_CurrentIndex, </span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#2b91af">ObservableCollection</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">UserControl</span><span style="background:#ffffff;color:#000000">&gt; m_ListMessages;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ObservableCollection</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">UserControl</span><span style="background:#ffffff;color:#000000">&gt; BINDING_PROP_LISTMESSAGES</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000"> { </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_ListMessages; }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">set</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">.SetProperty(</span><span style="background:#ffffff;color:#0000ff">ref</span><span style="background:#ffffff;color:#000000"> m_ListMessages, </span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                BINDING_PROP_CURRENT_INDEX = m_ListMessages.Count - 1;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>  <p><font size="3"></font></p>  <p><font size="3">Sans doute les puristes vont râler, mais bon pour les autres une petite solution simple et rapide à mettre en œuvre et qui fonctionne également pour Windows Phone.</font></p>  <p><font size="3">Eric</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Capturer le flux vidéo d’une caméra avec MediaFoundation dans une application Windows Forms ou WPF</title>
      <link>https://docs.microsoft.com/archive/blogs/devosaure/capturer-le-flux-vido-dune-camra-avec-mediafoundation-dans-une-application-windows-forms-ou-wpf</link>
      <pubDate>Wed, 05 Mar 2014 11:02:28 GMT</pubDate>
      <dc:creator><![CDATA[EVBB]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/devosaure/2014/03/05/capturer-le-flux-vido-dune-camra-avec-mediafoundation-dans-une-application-windows-forms-ou-wpf/</guid>
      <description><![CDATA[Télécharger le code   Dans mon précédant billet, j’ai abordé la manière d’utiliser les APIs du...]]></description>
      <content:encoded><![CDATA[<p><a href="https://onedrive.live.com/#cid=9607F0BF305F86D2&amp;id=9607F0BF305F86D2%217309"><font size="3">Télécharger le code</font></a> </p>  <p><font size="3">Dans mon précédant <a href="https://blogs.msdn.com/b/devosaure/archive/2014/02/25/utilisation-du-windows-runtime-dans-une-librairie-c-pour-une-application-desktop.aspx">billet</a>, j’ai abordé la manière d’utiliser les APIs du Windows Runtime afin de prendre une photo et de l’afficher dans une application Windows Forms. </font><font size="3">Restait alors à implémenter ce que fait la classe XAML <a href="https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.captureelement.aspx">CaptureElement</a><strong></strong> du <a href="https://msdn.microsoft.com/en-us/library/windows/apps/br211377.aspx">Windows Runtime</a> afin de capturer directement le flux vidéo venant de la caméra. </font></p>  <p><font size="3">La classe CaptureElement, utilisant les APIs <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms697062(v=vs.85).aspx">MediaFoundation</a>, et comme il ne </font><font size="3">sera pas possible d’utiliser dans le contexte d’une application de bureau, cette classe XAML</font><font size="3">, </font><font size="3">nous allons donc aborder la manière de capturer le flux vidéo en utilisant&#160; directement MediaFoundation et non pas les APIs du Windows Runtime.</font></p>  <p><font size="3"></font></p>  <h1><font size="5">Architecture de la solution.</font></h1>  <p><font size="3">Dans le code source disponible en téléchargement, vous trouverez 3 projets.</font></p>  <ul>   <li><font size="3">Une librairie C/C++ (<strong>Win32MediaCapture.dll</strong>) qui appelle les APIs MediaFoundation et qui exporte des méthodes afin qu’elles soient utilisables via la technologie <strong>PInvoke</strong> de .NET</font></li>    <li><font size="3">Une Assembly C# <strong>Version 3.5</strong> de .NET (<strong>FRDPE.MediaFoundation.Wrapper.dll</strong>) qui importe les méthodes de la librairie Win32MediaCapture et permet de faire le pont avec l’interface utilisateur.</font></li>    <li><font size="3">Un projet Windows Forms qui utilise l’assembly C# et qui servira de container pour afficher&#160; le flux vidéo.        <br />&#160;&#160;&#160;&#160;&#160;&#160; <br /></font></li> </ul>  <h1><font size="5">Utilisation de MediaFoundation dans la librairie Win32MediaCapture.dll</font></h1>  <p><font size="3"><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms697062(v=vs.85).aspx">MediaFoundation</a> est un jeu d’APIs disponible depuis Windows Vista et qui utilise <a href="https://en.wikipedia.org/wiki/Component_Object_Model">COM</a> comme modèle de programmation. </font></p>  <p><font size="3">Avec Windows 8, de nouvelles interfaces ont été rajoutées, comme <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb970511(v=vs.85).aspx">IMFCaptureEngine, IMFCapturePreviewSink, IMFCaptureSource</a> et d’autres qui vont nous permettre de capturer et de pré-visualiser le flux vidéo.</font></p>  <p><font size="3"></font></p>  <h2>Initialisation du moteur de capture vidéo.</h2>  <p><font size="3">Tout d’abord, il faut démarrer MediaFoundation et initialiser le moteur de capture, comme illustré dans le code suivant :</font><font size="3">      <br /></font></p> <font size="3">   <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5c7080d0-887c-4843-8c31-043635100dc6" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#6f008a">WIN32MEDIACAPTURE_API</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> MFInitialize(</span><span style="background:#ffffff;color:#2b91af">HWND</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">preview</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">CBCOMPLETED</span><span style="background:#ffffff;color:#000000"> *</span><span style="background:#ffffff;color:#808080">cb</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">UINT32</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">//Start the MediaFoundation</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#000000">m_pCaptureManager = std::</span><span style="background:#ffffff;color:#2b91af">unique_ptr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">&gt;(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">());</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pCaptureManager == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_OUTOFMEMORY</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    hr=m_pCaptureManager-&gt;MFStartup();</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFActivate</span><span style="background:#ffffff;color:#000000">&gt; device;</span><br> <span style="background:#ffffff;color:#000000">    hr = m_pCaptureManager-&gt;MFGetDevice(&amp;device, </span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    hr=m_pCaptureManager-&gt;MFInitializeCaptureManager(</span><span style="background:#ffffff;color:#808080">preview</span><span style="background:#ffffff;color:#000000">, device, </span><span style="background:#ffffff;color:#808080">cb</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div> </font>  <p><font size="3"></font></p> <font size="3"></font>  <p><font size="3">La méthode <strong>MFInitialize</strong>, prend comme paramètre :</font></p>  <ul>   <li><font size="3"><strong>HWND preview</strong>, est un HANDLE de fenêtre qui servira de container pour pré-visualiser la vidéo.</font></li>    <li><font size="3"><strong>CBCOMPLETED *cb</strong>, est un pointeur de méthode de rappel pour notifier le client qu’une action est finie.        <br />&#160;</font><font size="3"><strong>UINT32 numdevice</strong>, correspond à un index de caméra à utiliser. (Une tablette peux posséder deux caméras, une frontale et une arrière), il est donc important de pouvoir les sélectionner.</font></li>    <li><font size="3"></font></li> </ul>  <ol>   <li><font size="3">On démarre MediaFoundation (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms702238(v=vs.85).aspx">MFStartup</a>()).</font></li>    <li><font size="3">On récupère un pointeur <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms703039(v=vs.85).aspx">IMFActivate</a>&#160;<strong>MFGetDevice</strong>()) en fonction de l’index de la caméra.         <br /><em> Exemple MFGetDevice</em>         <br />        <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e39b2aec-ca00-41f3-9193-c13daec02a97" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFGetDevice(</span><span style="background:#ffffff;color:#2b91af">IMFActivate</span><span style="background:#ffffff;color:#000000">** </span><span style="background:#ffffff;color:#808080">device</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">UINT32</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFAttributes</span><span style="background:#ffffff;color:#000000">&gt; pAttributes;</span><br> <span style="background:#ffffff;color:#000000">    hr = MFCreateAttributes(&amp;pAttributes, 1);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = pAttributes-&gt;SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,</span><br> <span style="background:#ffffff;color:#000000">        MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">// Enumerate devices.</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">UINT32</span><span style="background:#ffffff;color:#000000"> count;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">IMFActivate</span><span style="background:#ffffff;color:#000000"> **ppDevices;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    hr = MFEnumDeviceSources(pAttributes, &amp;ppDevices, &amp;count);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (count &gt; 0)</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (0 &lt; </span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000"> &amp;&amp; </span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000"> &gt;count)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            *</span><span style="background:#ffffff;color:#808080">device</span><span style="background:#ffffff;color:#000000"> = ppDevices[0];</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">else</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#000000">*</span><span style="background:#ffffff;color:#808080">device</span><span style="background:#ffffff;color:#000000"> = ppDevices[</span><span style="background:#ffffff;color:#808080">numdevice</span><span style="background:#ffffff;color:#000000">];</span><br> <span style="background:#ffffff;color:#000000">        }            </span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>     </font></li>    <li><font size="3">Enfin on initialise le moteur de capture via la méthode </font><font size="3"><strong>MFInitializeCaptureManager</strong> illustré dans le code suivant :         <br />        <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:4dfd4bf8-4868-4cb9-9e39-16ecd272ffab" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFInitializeCaptureManager(</span><span style="background:#ffffff;color:#2b91af">HWND</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">hwndPreview</span><span style="background:#ffffff;color:#000000">, </span><br> <span style="background:#ffffff;color:#000000">                                                        </span><span style="background:#ffffff;color:#2b91af">IUnknown</span><span style="background:#ffffff;color:#000000">* </span><span style="background:#ffffff;color:#808080">pUnk</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">                                                        </span><span style="background:#ffffff;color:#2b91af">CBCOMPLETED</span><span style="background:#ffffff;color:#000000"> *</span><span style="background:#ffffff;color:#808080">cb</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    m_pCallback = std::</span><span style="background:#ffffff;color:#2b91af">unique_ptr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">Win32CaptureEventCallback</span><span style="background:#ffffff;color:#000000">&gt;(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> (std::nothrow)</span><span style="background:#ffffff;color:#2b91af">Win32CaptureEventCallback</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#808080">cb</span><span style="background:#ffffff;color:#000000">));</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000"> == m_pCallback) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_OUTOFMEMORY</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    m_hwndPreview = </span><span style="background:#ffffff;color:#808080">hwndPreview</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFCaptureEngineClassFactory</span><span style="background:#ffffff;color:#000000">&gt;   pFactory = </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = CoCreateInstance(CLSID_MFCaptureEngineClassFactory, </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#2f4f4f">CLSCTX_INPROC_SERVER</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#6f008a">IID_PPV_ARGS</span><span style="background:#ffffff;color:#000000">(&amp;pFactory));</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFAttributes</span><span style="background:#ffffff;color:#000000">&gt; pAttributes = </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = MFCreateAttributes(&amp;pAttributes, 1);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">//Ici DIRECTX</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">//Create a D3D Manager</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#000000">hr = CreateD3DManager();</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    hr = pAttributes-&gt;SetUnknown(MF_CAPTURE_ENGINE_D3D_MANAGER, g_pDXGIMan);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">//// Create and initialize the capture engine.</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#000000">hr = pFactory-&gt;CreateInstance(CLSID_MFCaptureEngine, </span><span style="background:#ffffff;color:#6f008a">IID_PPV_ARGS</span><span style="background:#ffffff;color:#000000">(&amp;m_pEngine));</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    hr = m_pEngine-&gt;Initialize(m_pCallback.get(), pAttributes, </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#808080">pUnk</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>     </font></li> </ol>  <ul>   <li><font size="3">Dans cette méthode, on instancie la classe <strong>Win32CaptureEventCallBack, </strong>qui dérive de l’interface <a href="https://msdn.microsoft.com/en-us/windows/hh447849(v=vs.71).aspx">IMFCaptureEngineOnEventCallback</a> et qui servira d’objet de rappel à l’infrastructure de MediaFoundation. Pour être notifié, il faut implémenter la méthode <strong>OnEvent</strong> de cette Interface. Vous remarquerez que dans son constructeur, nous lui passons un pointeur <strong>CBCOMPLETED *cb</strong>, qui permettra de rappeler le client C# comme nous le verrons par la suite.         <br />        <br /><em>Exemple de méthode OnEvent          <br /></em>        <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2147da2f-8914-4721-8d38-066d1974fc32" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#6f008a">STDMETHODIMP</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureEventCallback</span><span style="background:#ffffff;color:#000000">::OnEvent(</span><span style="background:#ffffff;color:#6f008a">_In_</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">IMFMediaEvent</span><span style="background:#ffffff;color:#000000">* </span><span style="background:#ffffff;color:#808080">pEvent</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hrStatus;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">GUID</span><span style="background:#ffffff;color:#000000"> guidType;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> status = 1;</span><br> <span style="background:#ffffff;color:#000000">    hr = </span><span style="background:#ffffff;color:#808080">pEvent</span><span style="background:#ffffff;color:#000000">-&gt;GetStatus(&amp;hrStatus);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        status = 0;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_cb) m_cb(status);</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = </span><span style="background:#ffffff;color:#808080">pEvent</span><span style="background:#ffffff;color:#000000">-&gt;GetExtendedType(&amp;guidType);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr))</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        status = 0;</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (guidType == MF_CAPTURE_ENGINE_INITIALIZED)</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        status = 1;</span><span style="background:#ffffff;color:#008000">//EngineInitialized</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (guidType == MF_CAPTURE_ENGINE_PREVIEW_STARTED)</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        status = 2; </span><span style="background:#ffffff;color:#008000">//PreviewStarted</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (guidType == MF_CAPTURE_ENGINE_PREVIEW_STOPPED)</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        status = 3; </span><span style="background:#ffffff;color:#008000">//PreviewStopped</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_cb) m_cb(status);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>     </font></li>    <li><font size="3">Ensuite on crée une fabrique de classe <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447847(v=vs.85).aspx">IMFCaptureEngineClassFactory</a>, afin de pouvoir créer&#160; une instance de notre moteur de capture (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447846(v=vs.85).aspx">IMFCaptureEngine</a><strong></strong>).         <br /></font></li>    <li><font size="3"><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh162809(v=vs.85).aspx">MF_CAPTURE_ENGINE_D3D_ENGINE</a>, indique au moteur, d’allouer les frames vidéos en utilisant DirectX et donc d’utiliser l’accélération matérielle pour l’affichage. </font></li>    <li><font size="3">Pour ce faire on utilise une instance de l’interface <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704598(v=vs.85).aspx">IMFAttributes</a><strong>, </strong>créée par la méthode<strong> <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms701878(v=vs.85).aspx">MFCreateAttributes</a>.</strong>&#160; </font></li>    <li><font size="3">Ensuite, on crée une instance du moteur <strong>pFactory-&gt;CreateInstance (…)</strong></font></li>    <li><font size="3">Enfin on initialise le moteur <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447855(v=vs.85).aspx">m_pEngine-&gt;Initialize(..)</a><strong> </strong>en lui donnant :</font></li>    <ul>     <li><font size="3">un pointeur sur la classe de rappel <strong>Win32CaptureEventCallBack</strong></font></li>      <li><font size="3">un attribut correspondant au rendu DirectX</font></li>      <li><font size="3">un pointeur <strong>IUnknown* pUnk</strong>, correspondant à la caméra qui sera utilisée. </font></li>   </ul> </ul>  <p><font size="3"></font></p>  <h2>Démarrer la prévisualisation</h2> <font size="3">   <p>Une fois que le moteur est initialisé, il est alors possible de démarrer la prévisualisation.      <br /></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3f7fa90c-736a-44e4-af60-931ce71f30e4" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFStartPreview(</span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">rotation</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFCapturePreviewSink</span><span style="background:#ffffff;color:#000000">&gt; pPreview;</span><br> <span style="background:#ffffff;color:#000000">    m_rotation = </span><span style="background:#ffffff;color:#808080">rotation</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pEngine == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">S_FALSE</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFCaptureSink</span><span style="background:#ffffff;color:#000000">&gt; pcaptureSink;</span><br> <span style="background:#ffffff;color:#000000">    hr = m_pEngine-&gt;GetSink(</span><span style="background:#ffffff;color:#2f4f4f">MF_CAPTURE_ENGINE_SINK_TYPE_PREVIEW</span><span style="background:#ffffff;color:#000000">, &amp;pcaptureSink);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = pcaptureSink-&gt;QueryInterface(</span><span style="background:#ffffff;color:#6f008a">IID_PPV_ARGS</span><span style="background:#ffffff;color:#000000">(&amp;pPreview));</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = pPreview-&gt;SetRenderHandle(m_hwndPreview);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFCaptureSource</span><span style="background:#ffffff;color:#000000">&gt; pSource;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr = m_pEngine-&gt;GetSource(&amp;pSource);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        hr = pSource-&gt;GetCaptureDeviceSource(</span><span style="background:#ffffff;color:#2f4f4f">MF_CAPTURE_ENGINE_DEVICE_TYPE_VIDEO</span><span style="background:#ffffff;color:#000000">, &amp;m_pMediaSource);</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">        hr = m_pMediaSource-&gt;QueryInterface(</span><span style="background:#ffffff;color:#6f008a">IID_PPV_ARGS</span><span style="background:#ffffff;color:#000000">(&amp;m_pProcAmp));</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">CComPtr</span><span style="background:#ffffff;color:#000000">&lt;</span><span style="background:#ffffff;color:#2b91af">IMFMediaType</span><span style="background:#ffffff;color:#000000">&gt; pMediaType;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">//CComPtr&lt;IMFMediaType&gt; pMediaType2;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#000000">hr = pSource-&gt;GetCurrentDeviceMediaType((</span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#2f4f4f">MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW</span><span style="background:#ffffff;color:#000000">, &amp;pMediaType);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">/*hr = CloneVideoMediaType(pMediaType, MFVideoFormat_ARGB32, &amp;pMediaType2);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">if (FAILED(hr)) return hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">hr = pMediaType2-&gt;SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">if (FAILED(hr)) return hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#008000">*/</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000"> dwSinkStreamIndex;</span><br> <span style="background:#ffffff;color:#000000">    hr = pPreview-&gt;AddStream((</span><span style="background:#ffffff;color:#2b91af">DWORD</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#2f4f4f">MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW</span><span style="background:#ffffff;color:#000000">, pMediaType, </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">, &amp;dwSinkStreamIndex);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <br> <span style="background:#ffffff;color:#000000">    hr=pPreview-&gt;SetRotation(dwSinkStreamIndex, </span><span style="background:#ffffff;color:#808080">rotation</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    hr = m_pEngine-&gt;StartPreview();</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <ul>     <li>Tout d’abord, il faut instancier un récepteur qui recevra le flux de données provenant de la caméra.        <br />Pour ce faire, on récupère à partir du moteur (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447853(v=vs.85).aspx">m_pEngine-&gt;GetSink()</a>) un récepteur (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447882(v=vs.85).aspx">IMFCaptureSink</a>, <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447865(v=vs.85).aspx">IMFCapturePreviewSink</a> qui servira à la prévisualisation (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh162824(v=vs.85).aspx">MF_CAPTURE_ENGINE_SINK_TYPE_PREVIEW</a>)</li>   </ul>    <ul>     <li>Puis on définit sur quelle fenêtre la prévisualisation opèrera        <br /><strong>&#160;<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447870(v=vs.85).aspx">pPreview-&gt;SetRenderHandle</a>(m_hwndPreview)</strong></li>      <li>On récupère la source de la capture <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447854(v=vs.85).aspx">m_pEngine-&gt;GetSource</a><strong>(</strong><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447889(v=vs.85).aspx">IMFCaptureSource</a><strong>)</strong></li>      <li>A partir de la source (<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447893(v=vs.85).aspx">pSource-&gt;GetCurrentDeviceMediaType</a><strong>(</strong><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms704850(v=vs.85).aspx">IMFMediaType</a><strong>)</strong>), on va récupérer une instance IMFMediaType ,&#160; qui représente une description du format du média. Entre autre un flux qui sera de type prévisualisation vidéo (<strong>MF_CAPTURE_ENGINE_PREFERRED_SOURCE_STREAM_FOR_VIDEO_PREVIEW</strong>)</li>      <li>Puis on connecte un flux de données à la source <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447883(v=vs.85).aspx">pPreview-&gt;AddStream()</a></li>      <li>Et on démarre la prévisualisation <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/hh447856(v=vs.85).aspx">m_pEngine-&gt;StartPreview()</a>         <br /></li>   </ul>    <p>Vous aurez également remarqué que nous instancions un pointeur sur le périphérique      <br /><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/jj159896(v=vs.85).aspx">pSource-&gt;GetCaptureDeviceSource</a>(<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms700189(v=vs.85).aspx">IMFMediaSource</a>) et ceci&#160; afin de pouvoir récupérer une instance de la classe <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd376033(v=vs.85).aspx">IAMVideoProcAmp</a> (<strong>m_pMediasource-&gt;QueryInterface()),</strong> qui nous permettra de modifier les paramètres de la caméra, tels que le contraste, la luminosité, la saturation, etc..</p>    <h2><font size="4">Modifier les propriétés de la caméra</font></h2>    <p>Pour modifier par exemple, le contraste, la luminosité et la saturation, il suffit d’utiliser la méthode <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd376036(v=vs.85).aspx">Set</a> de l’interface <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd376033(v=vs.85).aspx">IAMVideoProcAmp</a> avec le bon paramètre, comme illustré dans le code suivant :</p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e8084689-ad4a-4caa-bb74-231f662be1d4" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFSetContrast(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> lValue, lFlags;</span><br> <span style="background:#ffffff;color:#000000">    hr = m_pProcAmp-&gt;Get(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Contrast</span><span style="background:#ffffff;color:#000000">, &amp;lValue, &amp;lFlags);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return    </span><span style="background:#ffffff;color:#000000">m_pProcAmp-&gt;Set(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Contrast</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">, lFlags);        </span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:623dad92-0025-429c-9576-7081d2cc45e4" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFSetBrightness(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> lValue, lFlags;</span><br> <span style="background:#ffffff;color:#000000">    hr = m_pProcAmp-&gt;Get(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Brightness</span><span style="background:#ffffff;color:#000000">, &amp;lValue, &amp;lFlags);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return    </span><span style="background:#ffffff;color:#000000">m_pProcAmp-&gt;Set(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Brightness</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">, lFlags);</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:77f03d89-4901-44f8-81e5-e148436d975e" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFSetSaturation(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> lValue, lFlags;</span><br> <span style="background:#ffffff;color:#000000">    hr = m_pProcAmp-&gt;Get(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Saturation</span><span style="background:#ffffff;color:#000000">, &amp;lValue, &amp;lFlags);</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#6f008a">FAILED</span><span style="background:#ffffff;color:#000000">(hr)) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> hr;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return    </span><span style="background:#ffffff;color:#000000">m_pProcAmp-&gt;Set(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Saturation</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#808080">value</span><span style="background:#ffffff;color:#000000">, lFlags);</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <p>Pour récupérer les propriétés il faut utiliser la méthode <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd376035(v=vs.85).aspx">GetRange</a> de la même interface.       <br /></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:24b7a9aa-7bf6-4323-a87d-43e59a0e14ed" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFGetContrast(</span><span style="background:#ffffff;color:#2b91af">CAPABILITIES</span><span style="background:#ffffff;color:#000000"> *</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_pProcAmp-&gt;GetRange(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Contrast</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">                              &amp;</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">-&gt;Minimum,</span><br> <span style="background:#ffffff;color:#000000">                              &amp;</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">-&gt;Maximum, </span><br> <span style="background:#ffffff;color:#000000">                              &amp;</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">-&gt;Step, </span><br> <span style="background:#ffffff;color:#000000">                              &amp;</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">-&gt;Default, </span><br> <span style="background:#ffffff;color:#000000">                              &amp;</span><span style="background:#ffffff;color:#808080">contrast</span><span style="background:#ffffff;color:#000000">-&gt;Caps);</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e7b5b835-cb91-4050-bf5c-ac1e00c77c9f" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFGetBrightness(</span><span style="background:#ffffff;color:#2b91af">CAPABILITIES</span><span style="background:#ffffff;color:#000000"> *</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_pProcAmp-&gt;GetRange(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Brightness</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">-&gt;Minimum,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">-&gt;Maximum,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">-&gt;Step,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">-&gt;Default,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">brightness</span><span style="background:#ffffff;color:#000000">-&gt;Caps);</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3e947416-b799-4c29-99ab-c5076439c1b2" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Win32CaptureManager</span><span style="background:#ffffff;color:#000000">::MFGetSaturation(</span><span style="background:#ffffff;color:#2b91af">CAPABILITIES</span><span style="background:#ffffff;color:#000000"> *</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> hr = </span><span style="background:#ffffff;color:#6f008a">S_OK</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_pProcAmp == </span><span style="background:#ffffff;color:#0000ff">nullptr</span><span style="background:#ffffff;color:#000000">) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">E_POINTER</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_pProcAmp-&gt;GetRange(</span><span style="background:#ffffff;color:#2f4f4f">VideoProcAmp_Saturation</span><span style="background:#ffffff;color:#000000">,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">-&gt;Minimum,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">-&gt;Maximum,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">-&gt;Step,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">-&gt;Default,</span><br> <span style="background:#ffffff;color:#000000">        &amp;</span><span style="background:#ffffff;color:#808080">caps</span><span style="background:#ffffff;color:#000000">-&gt;Caps);</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <p>et ainsi de suite pour les autres propriétés.</p>    <h1><font size="4">Création du Wrapper .NET C# (<strong>FRDPE.MediaFoundation.Wrapper.dll)</strong></font></h1>    <p>Le wrapper .NET n’est pas indispensable. Il est là uniquement pour simplifier l’utilisation de notre librairie C/C++, dans le contexte d’un client Windows Forms ou WPF.</p>    <p>Nous avons une classe <strong>FRDPE.Win32.Import.MediaFoundation, </strong>qui :</p>    <ul>     <li> importe sous forme de méthodes statiques, toutes les APIs de notre librairies C/C++</li>      <li> définit les signatures des délégués qui seront utilisés plus tard comme méthodes de rappels invoquées par le composant C/C++</li>   </ul>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:591a91e8-4bfb-4661-a437-7c7e8c41a84e" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">namespace</span><span style="background:#ffffff;color:#000000"> FRDPE.Win32.Import</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        </span><br> <span style="background:#ffffff;color:#000000">        [</span><span style="background:#ffffff;color:#2b91af">StructLayout</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">LayoutKind</span><span style="background:#ffffff;color:#000000">.Sequential)]</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> Minimum;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> Maximum;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> Step;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> Default;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> Caps;</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <br> <br> <br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">delegate</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">InitializeCompletedHandler</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> status);</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">delegate</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000">( [</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">,</span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPWStr)] </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> device);</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFInitialize(</span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> hwndPreview, </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> cb,</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> numDevice);</span><br> <span style="background:#ffffff;color:#000000">        </span><br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFEnumDevices(</span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> cb,[</span><span style="background:#ffffff;color:#2b91af">In</span><span style="background:#ffffff;color:#000000">,</span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.SysUInt)] </span><span style="background:#ffffff;color:#0000ff">ref</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UIntPtr</span><span style="background:#ffffff;color:#000000"> count);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFStartPreview(</span><span style="background:#ffffff;color:#0000ff">uint</span><span style="background:#ffffff;color:#000000"> rotation);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFStopPreview();</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetContrast(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> contrast);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetContrast([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">,</span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> contrast);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetBrightness(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> brightness);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetBrightness([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> brightness);</span><br> <br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetSaturation(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetSaturation([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetHue(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetHue([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetSharpness(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetSharpness([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetColorEnable(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetColorEnable([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetGamma(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetGamma([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetWhiteBalance(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetWhiteBalance([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetGain(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetGain([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFSetBacklightCompensation(</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> MFGetBacklightCompensation([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPStruct)] </span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> caps);</span><br> <br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> GetErrorMessage(</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr, </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> message);</span><br> <br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> GetErrorMessageSize(</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr);</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">    };</span></div> </div> </div>    <p>Ensuite, on définit une classe C# <strong>FRDPE.MediaFoundation.Wrapper.MediaCapture</strong>, qui servira de façade entre l’Interface utilisateur et la librairie C/C+.&#160;&#160;&#160;&#160; <br />Cette classe n’est pas forcement utile, mais elle simplifiera l’utilisation de la librairie C/C++ dans les projets Windows Forms et WPF.</p>    <p>Par exemple, si je prends la méthode <strong>MFEnumDevices</strong> qui prend comme paramètre :</p>    <ul>     <li>un pointeur sur une méthode de rappel : CBENUMDEVICES*cb</li>      <li>un pointeur sur un entier non signé : UINT32*count, qui contiendra le nombre de caméras disponibles </li>      <li>et qui retourne un <a href="https://en.wikipedia.org/wiki/HRESULT">HRESULT</a>.        <br /></li>   </ul>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5078fb2e-2950-461d-9c3a-49fbc1c34630" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">typedef</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#6f008a">CALLBACK</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">CBENUMDEVICES</span><span style="background:#ffffff;color:#000000">)(</span><span style="background:#ffffff;color:#0000ff">const</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">WCHAR</span><span style="background:#ffffff;color:#000000">* friendlyname);</span><br> <span style="background:#ffffff;color:#0000ff">extern</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#a31515">&quot;C&quot;</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#6f008a">WIN32MEDIACAPTURE_API</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">HRESULT</span><span style="background:#ffffff;color:#000000"> MFEnumDevices(</span><span style="background:#ffffff;color:#2b91af">CBENUMDEVICES</span><span style="background:#ffffff;color:#000000"> *cb, </span><span style="background:#ffffff;color:#2b91af">UINT32</span><span style="background:#ffffff;color:#000000"> *count);</span></div> </div> </div>    <p>qui se traduit en C# par :</p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:82012054-c00d-4087-88b0-bef460630dbe" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">delegate</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000">([</span><span style="background:#ffffff;color:#2b91af">Out</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#2b91af">MarshalAs</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">UnmanagedType</span><span style="background:#ffffff;color:#000000">.LPWStr)] </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> device);</span><br> <span style="background:#ffffff;color:#000000">            [</span><span style="background:#ffffff;color:#2b91af">DllImport</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#a31515">&quot;Win32MediaCapture.dll&quot;</span><span style="background:#ffffff;color:#000000">, CallingConvention = </span><span style="background:#ffffff;color:#2b91af">CallingConvention</span><span style="background:#ffffff;color:#000000">.Cdecl)]</span></div> </div> </div>    <p>que l’appel se fait comme cela : </p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f46c396b-d289-4108-bd15-5b0cb256883b" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> EnumDevices()</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> Callback=</span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.GetFunctionPointerForDelegate(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000">((</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> devicename)=&gt;</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_SyncronisationContext != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        m_SyncronisationContext.Post(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> System.Threading.</span><span style="background:#ffffff;color:#2b91af">SendOrPostCallback</span><span style="background:#ffffff;color:#000000">((o) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (OnEnumDevices != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                OnEnumDevices(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">, devicename);</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <br> <span style="background:#ffffff;color:#000000">                        }), </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                    }</span><br> <span style="background:#ffffff;color:#000000">                }));</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">UIntPtr</span><span style="background:#ffffff;color:#000000"> ptr=</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UIntPtr</span><span style="background:#ffffff;color:#000000">();                </span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;EnumDevice Error&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFEnumDevices(Callback, </span><span style="background:#ffffff;color:#0000ff">ref</span><span style="background:#ffffff;color:#000000"> ptr));</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> ptr.ToUInt32();</span><br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>    <p>Il est alors préférable que l’appelant puisse l’appeler comme suit :</p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:49af0bc3-467d-4526-a6a1-b7cbcc8323e0" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000"> m_mediaCapture = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">(picMediaCapture.Handle);</span><br> <span style="background:#ffffff;color:#000000">                    m_mediaCapture.OnEnumDevices += (asender, deviceName) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            lstEnumDevices.Items.Add(deviceName);</span><br> <span style="background:#ffffff;color:#000000">                        };</span><br> <span style="background:#ffffff;color:#000000">                    m_CountDevice = m_mediaCapture.EnumDevices();   </span></div> </div> </div>    <p><em>Code complet de la classe FRDPE.MediaFoundation.Wrapper.MediaCapture :</em></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:73312cce-b78d-4e6f-a556-408d2baeddd3" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">namespace</span><span style="background:#ffffff;color:#000000"> FRDPE.MediaFoundation.Wrapper</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> m_HwndPreview;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#2b91af">SynchronizationContext</span><span style="background:#ffffff;color:#000000"> m_SyncronisationContext;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">delegate</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">InitializeCompletedEventHandler</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Object</span><span style="background:#ffffff;color:#000000"> sender,</span><span style="background:#ffffff;color:#2b91af">InitializeCompletedEventArgs</span><span style="background:#ffffff;color:#000000"> e);</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">event</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">InitializeCompletedEventHandler</span><span style="background:#ffffff;color:#000000"> OnInitializationCompleted;</span><br> <br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">delegate</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Object</span><span style="background:#ffffff;color:#000000"> sender, </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> device);</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">event</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000"> OnEnumDevices;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">SynchronizationContext</span><span style="background:#ffffff;color:#000000"> Dispatcher {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">get</span><span style="background:#ffffff;color:#000000"> { </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> m_SyncronisationContext; } </span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">set</span><span style="background:#ffffff;color:#000000"> { m_SyncronisationContext=</span><span style="background:#ffffff;color:#0000ff">value</span><span style="background:#ffffff;color:#000000">;} </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">InitializeCompletedEventArgs</span><span style="background:#ffffff;color:#000000">:</span><span style="background:#ffffff;color:#2b91af">EventArgs</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000"> Status;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> InitializeCompletedEventArgs(</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000"> status)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                Status=status;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> MediaCapture(</span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> hwndPreview)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckPointer(hwndPreview);</span><br> <span style="background:#ffffff;color:#000000">            m_HwndPreview = hwndPreview;</span><br> <span style="background:#ffffff;color:#000000">            m_SyncronisationContext = </span><span style="background:#ffffff;color:#2b91af">SynchronizationContext</span><span style="background:#ffffff;color:#000000">.Current;</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> EnumDevices()</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> Callback=</span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.GetFunctionPointerForDelegate(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">EnumDeviceHandler</span><span style="background:#ffffff;color:#000000">((</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> devicename)=&gt;</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_SyncronisationContext != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        m_SyncronisationContext.Post(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> System.Threading.</span><span style="background:#ffffff;color:#2b91af">SendOrPostCallback</span><span style="background:#ffffff;color:#000000">((o) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (OnEnumDevices != </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <br> <span style="background:#ffffff;color:#000000">                                OnEnumDevices(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">, devicename);</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <br> <span style="background:#ffffff;color:#000000">                        }), </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                    }</span><br> <span style="background:#ffffff;color:#000000">                }));</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">UIntPtr</span><span style="background:#ffffff;color:#000000"> ptr=</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">UIntPtr</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;EnumDevice Error&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFEnumDevices(Callback, </span><span style="background:#ffffff;color:#0000ff">ref</span><span style="background:#ffffff;color:#000000"> ptr));</span><br> <br> <br> <br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> ptr.ToUInt32();</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> InitializeAsync(</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> numDevice)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> callback = </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.GetFunctionPointerForDelegate(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><br> <span style="background:#ffffff;color:#000000">                    FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">InitializeCompletedHandler</span><span style="background:#ffffff;color:#000000">((</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> statusInfo) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_SyncronisationContext!=</span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        m_SyncronisationContext.Post(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> System.Threading.</span><span style="background:#ffffff;color:#2b91af">SendOrPostCallback</span><span style="background:#ffffff;color:#000000">((o) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (OnInitializationCompleted!=</span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                </span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000"> status = (</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000">)statusInfo;                                </span><br> <span style="background:#ffffff;color:#000000">                                OnInitializationCompleted(</span><span style="background:#ffffff;color:#0000ff">this</span><span style="background:#ffffff;color:#000000">, </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">InitializeCompletedEventArgs</span><span style="background:#ffffff;color:#000000">(status));</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <br> <span style="background:#ffffff;color:#000000">                        }), </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                    }</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                }));</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckPointer(callback);</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not initialize MediaFoundation&quot;</span><span style="background:#ffffff;color:#000000">, </span><br> <span style="background:#ffffff;color:#000000">                    Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFInitialize(m_HwndPreview, callback, numDevice));</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Exception</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            }            </span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> StartPreviewAsync(</span><span style="background:#ffffff;color:#0000ff">uint</span><span style="background:#ffffff;color:#000000"> rotation)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not Start Preview&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFStartPreview(rotation));</span><br> <br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> StopPreviewAsync()</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not Stop Preview&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFStopPreview());</span><br> <br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">       </span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> SetProperty(</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000"> property,</span><span style="background:#ffffff;color:#0000ff">long</span><span style="background:#ffffff;color:#000000"> value)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">switch</span><span style="background:#ffffff;color:#000000"> (property)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Brightness:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the brightness&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetBrightness(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Contrast:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the contrast&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetContrast(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Hue:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the Hue&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetHue(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Saturation:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the saturation&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetSaturation(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Sharpness:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the Sharpness&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetSharpness(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gamma:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the gamma&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetGamma(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_ColorEnable:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the Color&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetColorEnable(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_WhiteBalance:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the WhiteBalance&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetWhiteBalance(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_BacklightCompensation:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the Backlight Compensation&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetBacklightCompensation(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gain:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(</span><span style="background:#ffffff;color:#a31515">&quot;Could not set the gain&quot;</span><span style="background:#ffffff;color:#000000">, Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFSetGain(value));</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">default</span><span style="background:#ffffff;color:#000000">:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> GetProperty(</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000"> property)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000"> Caps = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">Capabilities</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr=0;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> ErrorMessage=</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000">.Empty;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">switch</span><span style="background:#ffffff;color:#000000"> (property)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Brightness:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the brightness&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetBrightness(Caps);                    </span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Contrast:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the contrast&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetContrast(Caps);            </span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Hue:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the hue&quot;</span><span style="background:#ffffff;color:#000000">; </span><br> <span style="background:#ffffff;color:#000000">                    hr= Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetHue(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Saturation:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the saturation&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr = Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetSaturation(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Sharpness:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the Sharpness&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetSharpness(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gamma:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the gamma&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetGamma(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_ColorEnable:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the color&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetColorEnable(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_WhiteBalance:</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the white balance&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetWhiteBalance(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_BacklightCompensation:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the Backlight Compensation&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetBacklightCompensation(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">case</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gain:</span><br> <span style="background:#ffffff;color:#000000">                    ErrorMessage=</span><span style="background:#ffffff;color:#a31515">&quot;Could not get the Gain&quot;</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                    hr=Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.MFGetGain(Caps);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">default</span><span style="background:#ffffff;color:#000000">:</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">break</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (hr == 0x80070490)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#008000">//Not supported</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">;</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">else</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.CheckAndThrowException(ErrorMessage,hr);</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> Caps;</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">enum</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Brightness    = 0,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Contrast    = ( VideoProcAmp_Brightness + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Hue    = ( VideoProcAmp_Contrast + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Saturation    = ( VideoProcAmp_Hue + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Sharpness    = ( VideoProcAmp_Saturation + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Gamma    = ( VideoProcAmp_Sharpness + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_ColorEnable    = ( VideoProcAmp_Gamma + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_WhiteBalance    = ( VideoProcAmp_ColorEnable + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_BacklightCompensation    = ( VideoProcAmp_WhiteBalance + 1 ) ,</span><br> <span style="background:#ffffff;color:#000000">            VideoProcAmp_Gain    = ( VideoProcAmp_BacklightCompensation + 1 ) </span><br> <span style="background:#ffffff;color:#000000">        };</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">enum</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            Error=0,</span><br> <span style="background:#ffffff;color:#000000">            EngineInitialized,</span><br> <span style="background:#ffffff;color:#000000">            PreviewStarted,            </span><br> <span style="background:#ffffff;color:#000000">            PreviewStopped            </span><br> <span style="background:#ffffff;color:#000000">        };</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">    </span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>    <p>Ce qu’il faut juste noter ici :</p>    <ul>     <li>Le constructeur prend un pointeur IntPtr qui sera un HANDLE (HWDN) de fenêtre.</li>      <li>Qu’on convertit les délégués en pointeurs de fonctions à l’aide de la méthode statique <strong>GetFunctionPointerForDelegate</strong>, de la classe <strong>Marshal</strong>. </li>      <li>Une fois rappelé par la librairie C/C++, on invoque un évènement auquel se serait abonné le client Windows Forms ou WPF, tout prenant la précaution d’usage, de bien se synchroniser avec le thread appelant à l’aide de l’objet <a href="https://msdn.microsoft.com/en-us/library/system.threading.synchronizationcontext(v=vs.110).aspx">SynchronisationContext</a>.</li>      <li>Qu’on utilise une la méthode <strong>CheckAndThrowException</strong>(), pour vérifier et lever une exception en fonction du HRESULT retourné.</li>   </ul>    <p><strong>Note</strong> : pour de plus amples informations concernant l’interopérabilité entre C/C++ et C# via l’attribut <strong>DLLImport</strong>, reportez vous à mon précédant <a href="https://blogs.msdn.com/b/devosaure/archive/2014/02/25/utilisation-du-windows-runtime-dans-une-librairie-c-pour-une-application-desktop.aspx">billet</a>.</p>    <p>Une dernière classe nommée <strong>Helper</strong>, permet de :</p>    <ul>     <li>vérifier la validité des pointeurs, </li>      <li>vérifier la validité des HRESULTs </li>      <li>de lever des exceptions, avec le bon message d’erreur associé au HRESULT</li>   </ul>    <p><em>Code complet de la classe Helper</em></p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:7167d6c0-91f9-492e-976d-0635647e9a51" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">namespace</span><span style="background:#ffffff;color:#000000"> FRDPE.MediaFoundation</span><br> <span style="background:#ffffff;color:#000000">{</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">class</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Helper</span><br> <span style="background:#ffffff;color:#000000">    {</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#808080">///</span><span style="background:#ffffff;color:#008000"> </span><span style="background:#ffffff;color:#808080">&lt;summary&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#808080">///</span><span style="background:#ffffff;color:#008000"> Check the Pointer</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#808080">///</span><span style="background:#ffffff;color:#008000"> </span><span style="background:#ffffff;color:#808080">&lt;/summary&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#808080">///</span><span style="background:#ffffff;color:#008000"> </span><span style="background:#ffffff;color:#808080">&lt;param name=&quot;ptr&quot;&gt;&lt;/param&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> CheckPointer(</span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> ptr)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">unsafe</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (ptr.ToPointer() == </span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ArgumentNullException</span><span style="background:#ffffff;color:#000000">();</span><br> <span style="background:#ffffff;color:#000000">                }</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> GetFunctionPointeurFromInitializeCompletedHandler(</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000"> mediaCapture)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.GetFunctionPointerForDelegate(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">InitializeCompletedHandler</span><span style="background:#ffffff;color:#000000">((</span><span style="background:#ffffff;color:#0000ff">int</span><span style="background:#ffffff;color:#000000"> statusInfo) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">var</span><span style="background:#ffffff;color:#000000"> s = statusInfo;</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (mediaCapture!=</span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (mediaCapture.Dispatcher!=</span><span style="background:#ffffff;color:#0000ff">null</span><span style="background:#ffffff;color:#000000">)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                mediaCapture.Dispatcher.Post(</span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> System.Threading.</span><span style="background:#ffffff;color:#2b91af">SendOrPostCallback</span><span style="background:#ffffff;color:#000000">((o) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                                    {</span><br> <span style="background:#ffffff;color:#000000">                                        </span><br> <span style="background:#ffffff;color:#000000">                                        </span><br> <span style="background:#ffffff;color:#000000">                                    }), statusInfo);</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                    }));</span><br> <br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> FormatErrorMessage(</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> Message,</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000">.Format(</span><span style="background:#ffffff;color:#a31515">&quot;{0} : 0x{1:X}L&quot;</span><span style="background:#ffffff;color:#000000">, Message, hr);</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Boolean</span><span style="background:#ffffff;color:#000000"> FAILED(</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> (hr &gt; 0);</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">Boolean</span><span style="background:#ffffff;color:#000000"> SUCCEEDED(</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000"> (hr == 0);</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">public</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">static</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> CheckAndThrowException(</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> message,</span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> hr)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.FAILED(hr))</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000"> InternalMessage;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000"> size = 0;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> ptr = </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000">.Zero ;</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <span style="background:#ffffff;color:#000000">                    size = (</span><span style="background:#ffffff;color:#2b91af">Int32</span><span style="background:#ffffff;color:#000000">)FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.GetErrorMessageSize(hr);</span><br> <br> <span style="background:#ffffff;color:#000000">                    ptr = </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.AllocHGlobal(size);</span><br> <br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">UInt32</span><span style="background:#ffffff;color:#000000"> errorHR = FRDPE.Win32.Import.</span><span style="background:#ffffff;color:#2b91af">MediaFoundation</span><span style="background:#ffffff;color:#000000">.GetErrorMessage(hr, ptr);</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.FAILED(errorHR))</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ApplicationException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.FormatErrorMessage(</span><span style="background:#ffffff;color:#a31515">&quot;Catastrophic failure : No pointer !!!&quot;</span><span style="background:#ffffff;color:#000000">, errorHR));</span><br> <span style="background:#ffffff;color:#000000">                    }</span><br> <br> <span style="background:#ffffff;color:#000000">                    InternalMessage = </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.PtrToStringUni(ptr);</span><br> <span style="background:#ffffff;color:#000000">                    </span><br> <span style="background:#ffffff;color:#000000">                }</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">finally</span><br> <span style="background:#ffffff;color:#000000">                {</span><br> <span style="background:#ffffff;color:#000000">                    </span><span style="background:#ffffff;color:#2b91af">Marshal</span><span style="background:#ffffff;color:#000000">.FreeCoTaskMem(ptr);</span><br> <span style="background:#ffffff;color:#000000">                }</span><br> <span style="background:#ffffff;color:#000000">                </span><br> <br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#0000ff">throw</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#2b91af">ApplicationException</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Helper</span><span style="background:#ffffff;color:#000000">.FormatErrorMessage(</span><span style="background:#ffffff;color:#2b91af">String</span><span style="background:#ffffff;color:#000000">.Format(</span><span style="background:#ffffff;color:#a31515">&quot;{0} : Internal Message : {1}&quot;</span><span style="background:#ffffff;color:#000000">,message,InternalMessage), hr));</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">        }</span><br> <span style="background:#ffffff;color:#000000">    }</span><br> <span style="background:#ffffff;color:#000000">}</span></div> </div> </div>&#160;&#160; <h1><font size="5">Interface Utilisateur Windows Forms ou WPF.</font></h1>    <p>C’est la partie la plus simple, il suffit d’ajouter notre assembly FRDPE.MediaFoundation.Wrapper.dll en tant que référence.</p>    <p>Ensuite pour démarrer la prévisualisation de la vidéo, il suffit tout simplement :</p>    <ol>     <li>D’instancier notre classe <strong>MediaCapture</strong> en lui passant un HANDLE de fenêtre.</li>      <li>De s’abonner à l’évènement <strong>OnInializationCompleted</strong>, </li>      <li>D’initialiser la capture <strong>InitializeAsync</strong>(m_numDevice) avec le bon index de caméra</li>      <li>Une fois initialisé, de démarrer la capture <strong>StartPreviewAsync</strong>()</li>   </ol>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bd3e5204-2bcc-4384-b6b9-af7a8b99d72c" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">private</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">void</span><span style="background:#ffffff;color:#000000"> cmdStartPreview_Click(</span><span style="background:#ffffff;color:#0000ff">object</span><span style="background:#ffffff;color:#000000"> sender, </span><span style="background:#ffffff;color:#2b91af">EventArgs</span><span style="background:#ffffff;color:#000000"> e)</span><br> <span style="background:#ffffff;color:#000000">        {</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (m_CountDevice == 0) </span><span style="background:#ffffff;color:#0000ff">return</span><span style="background:#ffffff;color:#000000">;</span><br> <br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">IntPtr</span><span style="background:#ffffff;color:#000000"> ptr = picMediaCapture.Handle;                </span><br> <span style="background:#ffffff;color:#000000">                m_mediaCapture = </span><span style="background:#ffffff;color:#0000ff">new</span><span style="background:#ffffff;color:#000000"> MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">(ptr);</span><br> <span style="background:#ffffff;color:#000000">                m_mediaCapture.OnInitializationCompleted += (asender, ae) =&gt;</span><br> <span style="background:#ffffff;color:#000000">                    {</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (ae.Status==MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000">.EngineInitialized)</span><br> <span style="background:#ffffff;color:#000000">                        {                           </span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                m_mediaCapture.StartPreviewAsync(m_ConfigPreview.Rotation);</span><br> <span style="background:#ffffff;color:#000000">                                </span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Exception</span><span style="background:#ffffff;color:#000000"> ex)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                </span><span style="background:#ffffff;color:#2b91af">MessageBox</span><span style="background:#ffffff;color:#000000">.Show(ex.Message);</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <span style="background:#ffffff;color:#000000">                            </span><br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000">(ae.Status==MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000">.PreviewStarted)</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">try</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <br> <span style="background:#ffffff;color:#000000">                                Brigtness = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Brightness);</span><br> <span style="background:#ffffff;color:#000000">                                Contrast = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Contrast);</span><br> <span style="background:#ffffff;color:#000000">                                Saturation = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Saturation);</span><br> <span style="background:#ffffff;color:#000000">                                Hue = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Hue);</span><br> <span style="background:#ffffff;color:#000000">                                Sharpness = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Sharpness);</span><br> <span style="background:#ffffff;color:#000000">                                Gamma = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gamma);</span><br> <span style="background:#ffffff;color:#000000">                                ColorEnable = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_ColorEnable);</span><br> <span style="background:#ffffff;color:#000000">                                BacklightCompensation = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_BacklightCompensation);</span><br> <span style="background:#ffffff;color:#000000">                                Gain = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_Gain);</span><br> <span style="background:#ffffff;color:#000000">                                WhiteBalance = m_mediaCapture.GetProperty(MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">VideoProcAmpProperty</span><span style="background:#ffffff;color:#000000">.VideoProcAmp_WhiteBalance);</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000">(</span><span style="background:#ffffff;color:#2b91af">Exception</span><span style="background:#ffffff;color:#000000"> ex)</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                </span><span style="background:#ffffff;color:#2b91af">MessageBox</span><span style="background:#ffffff;color:#000000">.Show(ex.Message);</span><br> <span style="background:#ffffff;color:#000000">                                </span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#0000ff">finally</span><br> <span style="background:#ffffff;color:#000000">                            {</span><br> <span style="background:#ffffff;color:#000000">                                FormatTrackBar();</span><br> <span style="background:#ffffff;color:#000000">                            }</span><br> <br> <br> <span style="background:#ffffff;color:#000000">                            </span><br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (ae.Status == MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000">.PreviewStopped)</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#2b91af">MessageBox</span><span style="background:#ffffff;color:#000000">.Show(</span><span style="background:#ffffff;color:#a31515">&quot;Preview Stopped&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                        </span><span style="background:#ffffff;color:#0000ff">else</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#0000ff">if</span><span style="background:#ffffff;color:#000000"> (ae.Status == MF.</span><span style="background:#ffffff;color:#2b91af">MediaCapture</span><span style="background:#ffffff;color:#000000">.</span><span style="background:#ffffff;color:#2b91af">AsyncStatus</span><span style="background:#ffffff;color:#000000">.Error)</span><br> <span style="background:#ffffff;color:#000000">                        {</span><br> <span style="background:#ffffff;color:#000000">                            </span><span style="background:#ffffff;color:#2b91af">MessageBox</span><span style="background:#ffffff;color:#000000">.Show(</span><span style="background:#ffffff;color:#a31515">&quot;Engine Error&quot;</span><span style="background:#ffffff;color:#000000">);</span><br> <span style="background:#ffffff;color:#000000">                        }</span><br> <span style="background:#ffffff;color:#000000">                    };</span><br> <br> <span style="background:#ffffff;color:#000000">                m_mediaCapture.InitializeAsync(m_numDevice);</span><br> <br> <span style="background:#ffffff;color:#000000">                </span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">catch</span><span style="background:#ffffff;color:#000000"> (</span><span style="background:#ffffff;color:#2b91af">Exception</span><span style="background:#ffffff;color:#000000"> ex)</span><br> <span style="background:#ffffff;color:#000000">            {</span><br> <br> <span style="background:#ffffff;color:#000000">                </span><span style="background:#ffffff;color:#2b91af">MessageBox</span><span style="background:#ffffff;color:#000000">.Show(ex.Message);</span><br> <span style="background:#ffffff;color:#000000">            }</span><br> <span style="background:#ffffff;color:#000000">            </span><br> <br> <br> <span style="background:#ffffff;color:#000000">        }</span></div> </div> </div>    <p>Pour visualiser la vidéo il nous faut un <strong>Handle</strong> de fenêtre. Avec les Windows Form,s c’est pas trop compliqué, il suffit tout simplement comme dans l’exemple fournit, d’ajouter un <strong>PictureBox</strong> qui possède la propriété Handle. D’ailleurs tous les objets qui possèderaient cette propriété, comme l’objet Form lui même, sont de bons candidats.</p>    <p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/6320.image_4B829C95.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/6320.image_5F00_4B829C95.png"><img title="image" style="display: inline; background-image: none;" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/46/55/metablogapi/3107.image_thumb_73B76658.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-46-55-metablogapi/3107.image_5F00_thumb_5F00_73B76658.png" width="866" height="464" /></a></p>    <p>Vous noterez également&#160; dans le code associé à cet article, qu’il est possible de modifier certaines propriétés de la caméra, comme, le contraste, la luminosité, la saturation, Hue, Gamma, Sharpness, la rotation, etc..</p>    <p>Si vous souhaitez utiliser cette librairie avec WPF, qui n’a plus réellement de notion de Handle associé aux objets, il suffira d’utiliser l’objet <strong>WindowsFormsHost</strong>, comme illustré dans l’extrait XAML suivant :</p>    <div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5f7c8c62-8dd2-406a-a558-905709d3af55" class="wlWriterEditableSmartContent" style="margin: 0px; padding: 0px; float: none; display: inline;"> <div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"> <div style="background-color: #ffffff; max-height: 500px; overflow: auto; padding: 2px 5px; white-space: nowrap"><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">Window</span><span style="background:#ffffff;color:#ff0000"> x</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#ff0000">Class</span><span style="background:#ffffff;color:#0000ff">=&quot;ClientWPFMediaCapture.MainWindow&quot;</span><br> <span style="background:#ffffff;color:#000000">       </span><span style="background:#ffffff;color:#ff0000"> xmlns</span><span style="background:#ffffff;color:#0000ff">=&quot;https://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</span><br> <span style="background:#ffffff;color:#000000">       </span><span style="background:#ffffff;color:#ff0000"> xmlns</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#ff0000">x</span><span style="background:#ffffff;color:#0000ff">=&quot;https://schemas.microsoft.com/winfx/2006/xaml&quot;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#ff0000"> xmlns</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#ff0000">wf</span><span style="background:#ffffff;color:#0000ff">=&quot;clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms&quot;</span><span style="background:#ffffff;color:#000000"> </span><br> <span style="background:#ffffff;color:#000000">       </span><span style="background:#ffffff;color:#ff0000"> Title</span><span style="background:#ffffff;color:#0000ff">=&quot;MainWindow&quot;</span><span style="background:#ffffff;color:#ff0000"> Height</span><span style="background:#ffffff;color:#0000ff">=&quot;350&quot;</span><span style="background:#ffffff;color:#ff0000"> Width</span><span style="background:#ffffff;color:#0000ff">=&quot;525&quot;&gt;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">Grid</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">Grid.ColumnDefinitions</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">ColumnDefinition</span><span style="background:#ffffff;color:#ff0000"> Width</span><span style="background:#ffffff;color:#0000ff">=&quot;86*&quot;/&gt;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">ColumnDefinition</span><span style="background:#ffffff;color:#ff0000"> Width</span><span style="background:#ffffff;color:#0000ff">=&quot;431*&quot;/&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;/</span><span style="background:#ffffff;color:#a31515">Grid.ColumnDefinitions</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">Grid.RowDefinitions</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">RowDefinition</span><span style="background:#ffffff;color:#0000ff">/&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;/</span><span style="background:#ffffff;color:#a31515">Grid.RowDefinitions</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">WindowsFormsHost</span><span style="background:#ffffff;color:#ff0000"> Margin</span><span style="background:#ffffff;color:#0000ff">=&quot;0&quot;</span><span style="background:#ffffff;color:#ff0000"> Grid.Column</span><span style="background:#ffffff;color:#0000ff">=&quot;1&quot;&gt;</span><br> <span style="background:#ffffff;color:#000000">            </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">wf</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#a31515">PictureBox</span><span style="background:#ffffff;color:#ff0000"> Width</span><span style="background:#ffffff;color:#0000ff">=&quot;100&quot;</span><span style="background:#ffffff;color:#ff0000"> Height</span><span style="background:#ffffff;color:#0000ff">=&quot;100&quot;</span><span style="background:#ffffff;color:#000000"> </span><span style="background:#ffffff;color:#ff0000"> x</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#ff0000">Name</span><span style="background:#ffffff;color:#0000ff">=&quot;pctMediaCapture&quot;&gt;&lt;/</span><span style="background:#ffffff;color:#a31515">wf</span><span style="background:#ffffff;color:#0000ff">:</span><span style="background:#ffffff;color:#a31515">PictureBox</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;/</span><span style="background:#ffffff;color:#a31515">WindowsFormsHost</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#000000">        </span><span style="background:#ffffff;color:#0000ff">&lt;</span><span style="background:#ffffff;color:#a31515">Button</span><span style="background:#ffffff;color:#ff0000"> Content</span><span style="background:#ffffff;color:#0000ff">=&quot;Preview&quot;</span><span style="background:#ffffff;color:#ff0000"> HorizontalAlignment</span><span style="background:#ffffff;color:#0000ff">=&quot;Left&quot;</span><span style="background:#ffffff;color:#ff0000"> Height</span><span style="background:#ffffff;color:#0000ff">=&quot;19&quot;</span><span style="background:#ffffff;color:#ff0000"> Margin</span><span style="background:#ffffff;color:#0000ff">=&quot;6,14,0,0&quot;</span><span style="background:#ffffff;color:#ff0000"> VerticalAlignment</span><span style="background:#ffffff;color:#0000ff">=&quot;Top&quot;</span><span style="background:#ffffff;color:#ff0000"> Width</span><span style="background:#ffffff;color:#0000ff">=&quot;57&quot;</span><span style="background:#ffffff;color:#ff0000"> Click</span><span style="background:#ffffff;color:#0000ff">=&quot;cmdStartPreview_Click&quot;/&gt;</span><br> <span style="background:#ffffff;color:#000000">    </span><span style="background:#ffffff;color:#0000ff">&lt;/</span><span style="background:#ffffff;color:#a31515">Grid</span><span style="background:#ffffff;color:#0000ff">&gt;</span><br> <span style="background:#ffffff;color:#0000ff">&lt;/</span><span style="background:#ffffff;color:#a31515">Window</span><span style="background:#ffffff;color:#0000ff">&gt;</span></div> </div> </div>&#160;&#160;&#160;&#160; <br />    <p><a href="https://onedrive.live.com/#cid=9607F0BF305F86D2&amp;id=9607F0BF305F86D2%217309"><font size="3">Télécharger le code</font></a> </p> </font>  <p><font size="3"></font></p>  <p><font size="3">Eric </font></p>  <ul></ul>]]></content:encoded>
    </item>
  </channel>
</rss>