-
December 28th, 2008, 05:33 PM
#1
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.
-
December 28th, 2008, 05:59 PM
#2
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.
-
December 28th, 2008, 09:35 PM
#3
Re: Load Dll from Embedded Resource
Originally Posted by marceln
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
-
December 29th, 2008, 12:59 PM
#4
Re: Load Dll from Embedded Resource
Would you have a csharp example of how to load the library?
-
December 29th, 2008, 01:08 PM
#5
Re: Load Dll from Embedded Resource
Originally Posted by gleesonger
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
-
December 29th, 2008, 04:35 PM
#6
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.
-
December 29th, 2008, 04:37 PM
#7
Re: Load Dll from Embedded Resource
Originally Posted by gleesonger
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
-
December 29th, 2008, 04:38 PM
#8
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
-
December 29th, 2008, 06:11 PM
#9
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 )...
-
December 29th, 2008, 06:15 PM
#10
Re: Load Dll from Embedded Resource
Originally Posted by marceln
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
-
December 29th, 2008, 06:20 PM
#11
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.
-
December 29th, 2008, 06:23 PM
#12
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.
-
December 29th, 2008, 06:27 PM
#13
Re: Load Dll from Embedded Resource
Brilliant couldn't be easier.
Thanks very much.
-
December 29th, 2008, 07:13 PM
#14
Re: Load Dll from Embedded Resource
Originally Posted by MadHatter
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
-
December 29th, 2008, 07:14 PM
#15
Re: Load Dll from Embedded Resource
Originally Posted by darwen
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|