CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    May 2008
    Posts
    36

    Load Dll from Embedded Resource

    How can this be done?
    At the moment I'm writing the dll out to the parent dir in a wrapper class then calling the Main method from the Main Class I would like however to keep it 'clean' and have nothing written to the disk.
    Thanks Ger.

  2. #2
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Load Dll from Embedded Resource

    Storing the dll as a resource(as RT_RCDATA) would not be a problem. But loading it will be. I actually believe it is not possible.
    Unless you temporarily save the resource to disk and use LoadLibrary(Ex) to load it, I don't see another way.

  3. #3
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by marceln View Post
    Storing the dll as a resource(as RT_RCDATA) would not be a problem. But loading it will be. I actually believe it is not possible.
    Unless you temporarily save the resource to disk and use LoadLibrary(Ex) to load it, I don't see another way.

    The you probably didn't look..... First hit

    It is a fairly common practice.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  4. #4
    Join Date
    May 2008
    Posts
    36

    Re: Load Dll from Embedded Resource

    Would you have a csharp example of how to load the library?

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by gleesonger View Post
    Would you have a csharp example of how to load the library?
    You want to load a native DLL (not a managed assembly) into a C# program that is contained in a resource????

    You will have to write some native code to do it - basically a COM interop class that leverages the code in the previous link.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  6. #6
    Join Date
    May 2008
    Posts
    36

    Re: Load Dll from Embedded Resource

    I've refrenced a COM dll and the compiler has created "Interop.SYNCTRLLib.dll" in the source directory of the executable.I would like the application as a stand alone exe.

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by gleesonger View Post
    I've refrenced a COM dll and the compiler has created "Interop.SYNCTRLLib.dll" in the source directory of the executable.I would like the application as a stand alone exe.
    That is a MANAGED DLL....this makes life simple...you just download ILMerre from Microsoft, and make a multi-assembly executable.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Load Dll from Embedded Resource

    you can use ILMerge to merge the CCW into your exe so you don't end up w/ multiple dll's w/ your exe.

    http://www.microsoft.com/downloads/d...displaylang=en

  9. #9
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: Load Dll from Embedded Resource

    Maybe I'm not up to date with the new trends, but what exactly is the purpose of having a DLL embedded in the executable? Doesn't this contradict with the whole concept of Dynamic-Linked Libraries?
    Unless you want to hide something (such as a DLL you weren't suppose to use for free, or an open source DLL that's not under LGPL )...

  10. #10
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by marceln View Post
    Maybe I'm not up to date with the new trends, but what exactly is the purpose of having a DLL embedded in the executable? Doesn't this contradict with the whole concept of Dynamic-Linked Libraries?
    Unless you want to hide something (such as a DLL you weren't suppose to use for free, or an open source DLL that's not under LGPL )...
    There are many good reasons.

    You still get the benefits of a DLL, but you now have "copy deployment" of a single file.

    You can also update individual components without a re-compile or re-link (this applies to both the native and manages conditions).

    I use this quite regularly to provide single file executables. They are very handy in situations such as carring/distributing applications on "tumb-drives".
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  11. #11
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: Load Dll from Embedded Resource

    unlike C++ dll's are the only way to link in external code.

    Also, unless you ngen the assembly, it only compiles and loads in memory what is needed. Other portions not used are stubbed out, and JITted as needed, so having everything in one image doesn't mean you're loading everything from the DLL into memory at runtime. so you get the benefit of a typical dll inside a single image.

    if you're using COM you have to generate a com callable wrapper, which is what he's wanting to hide or merge into the main executable.

  12. #12
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Load Dll from Embedded Resource

    I hate to be a killjoy here, but since it appears an interop assembly is being generated for a COM dll, the COM dll needs to be present and registered on the target machine regardless of whether the interop assembly is included in the resources of the app or not.

    And Synctrllib doesn't seem to be in a standard windows dll (what is synctrl.dll) so it'll need installing.

    As far as I'm aware COM dlls cannot be loaded into memory and called by the interop assembly. The interop assembly will use the standard COM mechanism for instansiation of objects(CoCreateInstance etc) and therefore requires that the COM dll is present on the hard drive and the necessary registry keys have been created.

    Darwen.
    Last edited by darwen; December 29th, 2008 at 06:29 PM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  13. #13
    Join Date
    May 2008
    Posts
    36

    Re: Load Dll from Embedded Resource

    Brilliant couldn't be easier.
    Thanks very much.

  14. #14
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by MadHatter View Post
    unlike C++ dll's are the only way to link in external code.
    Not sure what you indend by this, can you please elaborate...

    Also, unless you ngen the assembly, it only compiles and loads in memory what is needed. Other portions not used are stubbed out, and JITted as needed, so having everything in one image doesn't mean you're loading everything from the DLL into memory at runtime. so you get the benefit of a typical dll inside a single image.
    The MSIL is ALWAYS loaded in its entirity into memory for a given assembly, regardless of how much is actually used. You are correct about how much will be compiled (by JIT) into native code, regardless of the way in which the assembly is loaded.

    if you're using COM you have to generate a com callable wrapper, which is what he's wanting to hide or merge into the main executable.
    And that is easily done with ILMerge.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  15. #15
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Load Dll from Embedded Resource

    Quote Originally Posted by darwen View Post
    IAnd Synctrllib doesn't seem to be in a standard windows dll (what is synctrl.dll) so it'll need installing.
    Yes, ut that is (or at leads can be) handled by using the appropriate merge module, or chaining an MSI. In either case, it will not be part of the file set that ends up in the application directory (and may in fact be already loaded on the client machines)
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured