<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : Package the ocx into the .Net executable</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Command Bars : Package the ocx into the .Net executable]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Wed, 13 May 2026 13:02:19 +0000</pubDate>
  <lastBuildDate>Sat, 25 Jun 2005 01:19:42 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=2435</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[Package the ocx into the .Net executable : well in case anyone is interested...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=2435&amp;PID=7273&amp;title=package-the-ocx-into-the-net-executable#7273</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=1267">Wael</a><br /><strong>Subject:</strong> 2435<br /><strong>Posted:</strong> 25 June 2005 at 1:19am<br /><br /><P>well in case anyone is interested in the progress of this issue, Here is something maybe someone can work with,&nbsp;the following allows you&nbsp;to register/unregister the ocx dynamically. But the&nbsp;catch is that the ocx file will be treated as an external file and not embedded.&nbsp;hopfully there is still a way to do this while the file is being embededd.</P><P>using System;<BR>using System.Reflection;<BR>using System.Reflection.Emit;<BR>using System.Resources;<BR>using System.Runtime.InteropServices;<BR>using System.Threading;<BR>public class ocxRegServer<BR>{<BR>&nbsp;private byte&#091;&#093; m_sDllFile;<BR>&nbsp;private static ModuleBuilder myModuleBuilder;<BR>&nbsp;private Type m_tDllReg;</P><P>&nbsp;public ocxRegServer(byte&#091;&#093; dllFile)<BR>&nbsp;{<BR>&nbsp;&nbsp;m_sDllFile = dllFile;<BR>&nbsp;&nbsp;CreateDllRegType();<BR>&nbsp;}</P><P>&nbsp;public void Register()<BR>&nbsp;{<BR>&nbsp;&nbsp;InternalRegServer(false);<BR>&nbsp;}</P><P>&nbsp;public void UnRegister()<BR>&nbsp;{<BR>&nbsp;&nbsp;InternalRegServer(true);<BR>&nbsp;}</P><P>&nbsp;private void InternalRegServer(bool fUnreg)<BR>&nbsp;{<BR>&nbsp;&nbsp;string sMemberName = fUnreg ? "DllUnregisterServer" : "DllRegisterServer";</P><P>&nbsp;&nbsp;int hr = (int) m_tDllReg.InvokeMember (&nbsp; sMemberName,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BindingFlags.Invok eMethod,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Activator.CreateIn stance(m_tDllReg),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null );<BR>&nbsp;&nbsp;if (hr != 0)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;Marshal.ThrowExceptionForHR(hr);<BR>&nbsp;&nbsp;}<BR>&nbsp;}</P><P>&nbsp;private void CreateDllRegType()<BR>&nbsp;{<BR>&nbsp;&nbsp;string path;<BR>&nbsp;&nbsp;string myAsmName = "DllUnregisterServer";<BR>&nbsp;&nbsp;string myAsmFileName = myAsmName + ".dll";</P><P>&nbsp;&nbsp;if (myModuleBuilder == null)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AppDomain appDomain = Thread.GetDomain();</P><P>&nbsp;&nbsp;&nbsp;AssemblyName myAssemblyName = new AssemblyName();<BR>&nbsp;&nbsp;&nbsp;myAssemblyName.Name = myAsmName;</P><P>&nbsp;&nbsp;&nbsp;AssemblyBuilder myAssemblyBuilder =  appDomain.DefineDynamicAssembly(myAssemblyName,AssemblyBuild erAccess.RunAndSave);</P><P>&nbsp;&nbsp;&nbsp;myModuleBuilder =&nbsp;  myAssemblyBuilder.DefineDynamicModule(myAsmFileName,&nbsp;&n bsp; myAsmFileName);</P><P>&nbsp;&nbsp;&nbsp;// this line will embed the embedded CommandBars.ocx into the dynamically created assembly file<BR>&nbsp;&nbsp;&nbsp;// I am not really sure if this can be useful!.<BR> &nbsp;&nbsp;&nbsp;myModuleBuilder.DefineUnmanagedResource(m_ sDllFile);</P><P>&nbsp;&nbsp;&nbsp;myAssemblyBuilder.Save(myAsmFileName);<BR>&nbsp;&nbsp;}</P><P>&nbsp;&nbsp;// Add class to module<BR>&nbsp;&nbsp;TypeBuilder tb = myModuleBuilder.DefineType("DllRegServerClass" + Guid.NewGuid().ToString("N"));</P><P>&nbsp;&nbsp;MethodBuilder meb;</P><P>&nbsp;&nbsp;// Add PInvoke methods to class<BR>&nbsp;&nbsp;meb = tb.DefinePInvokeMethod(&nbsp;&nbsp; "DllRegisterServer",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"CommandBars.ocx",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CallingConventions.Stand ard,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typeof (int),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CallingConvention.StdCal l,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CharSet.Auto);</P><P>&nbsp;&nbsp;// Apply preservesig metadata attribute so we can handle return HRESULT ourselves<BR> &nbsp;&nbsp;meb.SetImplementationFlags(MethodImplAttributes. PreserveSig | meb.GetMethodImplementationFlags());</P><P>&nbsp;&nbsp;meb = tb.DefinePInvokeMethod(&nbsp;&nbsp; "DllUnregisterServer",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"CommandBars.ocx",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CallingConventions.Stand ard,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;typeof (int),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null,<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CallingConvention.StdCal l,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CharSet.Auto);</P><P>&nbsp;&nbsp;// Apply preservesig metadata attribute so we can handle return HRESULT ourselves<BR> &nbsp;&nbsp;meb.SetImplementationFlags(MethodImplAttributes. PreserveSig | meb.GetMethodImplementationFlags());</P><P>&nbsp;&nbsp;// Create the type<BR>&nbsp;&nbsp;m_tDllReg = tb.CreateType();<BR>&nbsp;}<BR>}</P><P>// here is the code that goes into Form1 for usage:-</P><P>private void InitializeComponent()<BR>{<BR>&nbsp;string strNameSpace=  System.Reflection.Assembly.GetExecutingAssembly().GetName(). Name.ToString();</P><P>&nbsp;// get the resource into a stream<BR>&nbsp;Stream str =  System.Reflection.Assembly.GetExecutingAssembly().GetManifes tResourceStream( strNameSpace + "."+ "CommandBars.ocx" );<BR>&nbsp;if ( str == null )<BR>&nbsp;{<BR>&nbsp;&nbsp;return;<BR>&nbsp;}</P><P>&nbsp;byte&#091;&#093; bStr = new Byte&#091;str.Length&#093;;</P><P>&nbsp;ocxRegServer reg = new ocxRegServer(bStr);<BR>&nbsp;<BR>&nbsp;if (fUnreg)<BR>&nbsp;{<BR>&nbsp;&nbsp;reg.UnRegister();<BR>&nbsp;}<BR>&nbsp;else<BR>&nbsp;{<BR>&nbsp;&nbsp;reg.Register();<BR>&nbsp;}<BR>&nbsp;<BR>&nbsp;this.components = new System.ComponentModel.Container();<BR>&nbsp;this.Size = new System.Drawing.Size(300, 300);<BR>&nbsp;this.Text = "Form1";&nbsp;<BR>}</P>]]>
   </description>
   <pubDate>Sat, 25 Jun 2005 01:19:42 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=2435&amp;PID=7273&amp;title=package-the-ocx-into-the-net-executable#7273</guid>
  </item> 
  <item>
   <title><![CDATA[Package the ocx into the .Net executable : Hi I am new to using Activex with...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=2435&amp;PID=7241&amp;title=package-the-ocx-into-the-net-executable#7241</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=1267">Wael</a><br /><strong>Subject:</strong> 2435<br /><strong>Posted:</strong> 22 June 2005 at 10:52pm<br /><br /><P>Hi I am new to using Activex with .Net and you probablly can tell from asking the following question:-</P><P>Is it possible to package &#091;i.e embedd&#093; the CommandBars.ocx into my .net application exe file?</P><P>if yes and I hope its a yes:-</P><P>Is it possible to register the ocx once the application is started and unregisters once the application has been terminated.</P><P>I am aware microsoft has a new tool called ILMerge that allows the merging of .net dll assembilies with exe's but it does not support ocx.</P><P>I have found one other tool but have not tested it because my project is in csharp and it seems&nbsp;to&nbsp;have been&nbsp;developed for VB.NET.</P><P>VB-PowerWrap 4.0&nbsp; <A href="http://www.mo&#111;nlight-software.com/" target="_blank">http://www.moonlight-software.com/</A></P><P>I hope there is a way to do this, so please let me know if you have any ideas.</P><P>Thanks in advance.</P><span style="font-size:10px"><br /><br />Edited by Wael</span>]]>
   </description>
   <pubDate>Wed, 22 Jun 2005 22:52:48 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=2435&amp;PID=7241&amp;title=package-the-ocx-into-the-net-executable#7241</guid>
  </item> 
 </channel>
</rss>