Re: Is it possible to include a dll in the exe

From: Daniel Moth (dmoth74_at_hotmail.com)
Date: 12/09/04


Date: Thu, 9 Dec 2004 11:49:07 -0000

Don't you love it when you learn something new? :-)

Jerron thanks for the offer. No need to send me one I got it working. I
started a new solution from scratch and it just worked (initially I thought
maybe it was a language thing so I tried both VB and C# and they both
worked.). I still have absolutely no idea why my original project does not
work (it still doesn't!), while it works on the desktop fine, but I think I
am going to have to let it go.

BTW, you don't need to move the Main function to its own class and you don't
need to create a static constructor in a separate one (in fact static ctors
are not guaranteed to run unless needed); I dropped the code in just before
Application.Run.

Searching the web I found other places that discuss this technique... if
anybody knows where it originated from (for future reference) feel free to
let me know

Cheers
Daniel

-- 
http://www.danielmoth.com/Blog/
"jer_m" <jmghost@msn.com> wrote in message 
news:5B44E7E9-0F98-415C-85B9-A9FDB4114E04@microsoft.com...
>
> Hi Daniel,
>
> I've done what Alex is talking about, You can even inherit your main form
> from a custom form in the dll.  I did it by.
>
> 1. creating a new class in the application
> 2. creating static constructor for that class ( this is where you would 
> put
> the code to extract your dll, you just need to extract it to the same
> location as your .exe, the clr will look for it there)
> 3. moving static void main() function out of the form and into the new 
> class.
>
> This will allow you to extract the dll before the clr tries to load it.
>
> In fact I include all of the resources as embedded resources.  This way I
> don't need to create a .cab to install the app.  We can send the same .exe 
> to
> a customer to test on their desktop as the one we put on their device, 
> with
> no install.  I also had problems debugging with the emulator with images
> built as content that were stored in folders.  The images would be 
> deployed
> to the emulator with a flat directory structure so the app couldn't locate
> them.  Embedding them into the project and extracting them in the same 
> manor
> as the custom control dll fixed this.
>
> I was working on an example that I was going to post at some point but 
> never
> got around to it, I will go ahead and send it to you
>
> Kind Regards,
> Jerron
>
> "Daniel Moth" wrote:
>
>> That is fine on the desktop and for the benefit of the archives the code
>> snippet needs to close the stream before using types from the assembly 
>> (and
>> should check if the file already exists before creating it).
>>
>> On the CF it seems the dependencies are checked before any user code gets 
>> a
>> chance to execute, so I cannot get it working. If you have a working CF
>> example please send it to me (I am interested in it from a POC point of 
>> view
>> :-).
>>
>> Cheers
>> Daniel
>> -- 
>> http://www.danielmoth.com/Blog/
>>
>>
>> "Alex Feinman [MVP]" <public_news@alexfeinman.com> wrote in message
>> news:OcEJk9V3EHA.2572@TK2MSFTNGP11.phx.gbl...
>> > You can add DLL to the project, mark it as embedded resource, then, 
>> > upon
>> > loading your application, check for the dll existence in the file 
>> > system
>> > and if it's not there, simply copy it there from the resource stream.
>> >
>> > Stream strDLL =
>> > Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNameSpace.MyDll.dll");
>> > //Case sensitive
>> > string path =
>> > Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
>> > FileStream fs = File.Create(path + "\\MyDLL.dll");
>> > int nRead = -1;
>> > byte[] buffer = new byte[4096];
>> > while(nRead != 0)
>> > {
>> >    nRead = strDLL.Read(buffer, 0, buffer.Length);
>> >    if ( nRead > 0 )
>> >        fs.Write(buffer, 0, nRead);
>> > }
>> >
>> > -- 
>> > Alex Feinman
>> > ---
>> > Visit http://www.opennetcf.org
>> > "ORC" <orc@sol.dk> wrote in message
>> > news:uZX04ES3EHA.2312@TK2MSFTNGP15.phx.gbl...
>> >> HI,
>> >>
>> >> It is possible to include a custom control dll in the exe file so that
>> >> the
>> >> dll isn't a standalone file that will have to be copied to the PDA 
>> >> along
>> >> with the exe file?
>> >>
>> >> Thanks,
>> >> Ole
>> >>
>> >>
>> >
>> >
>>
>>
>> 


Relevant Pages

  • Re: Is it possible to include a dll in the exe
    ... > from a custom form in the dll. ... > the code to extract your dll, you just need to extract it to the same ... > In fact I include all of the resources as embedded resources. ... >>>> with the exe file? ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Program protection - can not be copied
    ... The reason I cannot retrieve a dll from the image, ... That kind of thing might involve a filter driver or something ... I am trying to extract a DLL from an existing build. ... It seems that there is no any direct method to protect the program from ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Program protection - can not be copied
    ... The code in the DLL has been extracted and inserted directly into the OS image. ... That kind of thing might involve a filter driver or something similar. ... I am trying to extract a DLL from an existing build. ... > It seems that there is no any direct method to protect the program from ...
    (microsoft.public.windowsce.platbuilder)
  • Have big problem with windows control dll
    ... One project that build a windows control dll ... In the windows control c-tor is there a call to a method in the class ... So in the project referense settings for the windows control I have a ... In the exe file c-tor I have a call to a method in the class library. ...
    (microsoft.public.dotnet.languages.csharp)
  • This must be a bug in C# when using user control DLL and class library DLL
    ... One project that build a user control dll called B ... One project that build a class library dll called C ... In the exe file c-tor I have a call to a method in the class library. ... the windows control because I can drag the windows control from the toolbox ...
    (microsoft.public.dotnet.general)