Can you embed a .dll into an executable?

wyrd

Senior Contributor
Joined
Aug 23, 2002
Messages
1,405
Location
California
I was wondering if there was a way to embed user referenced .dlls into your executable, rather than just having it copied to your local bin folder.

It'd be nice to have a single .exe, rather than an .exe + .dlls. :P
 
I'm not sure if I follow you. Your saying you have a DLL (a bunch of classes compiled together) that someone else made and want to put in your executable? Don't think that could be done - least not that I can figure, the DLL's would have to be decompiled, added as individual classes to your project and then recompiled with the project to make a single EXE. Now if the DLL was yours then just take the root classes and add them to your project, but I don't think that's what your saying.
 
You can add resources to your project, such as text documents and images. I don't see why a .dll would be any different.
 
Because a dll has to be loaded in to memory, entry points found and all sorts of other issues like that. I see this question a lot and always find myself wondering what benefit a 1mb exe has over a 100k exe and a few dlls?
 
I suppose you could add them as a resource and on execution write them out to disk....
Wouldn't that defeat the point of DLLs - easier updating, better reuse etc?
 
Last edited:
divil said:
Because a dll has to be loaded in to memory, entry points found and all sorts of other issues like that. I see this question a lot and always find myself wondering what benefit a 1mb exe has over a 100k exe and a few dlls?

With small apps, people like a single executable. Makes it easier to share with friends.. and just more convenient.
 
You could create a simple setup program or use Winzip to create a self-extracting EXE. Otherwise, no, there's no way to get a DLL embedded into your EXE without some work.

You could, theoretically, embed the DLL. At runtime you could get the DLL as a resource and write it to disk. I'm not sure if that would work 100% or if you'd need to also load the DLL yourself. if you're using C++ you're a bit luckier as you can use LoadLibrary to load a standard DLL yourself, though I don't think a .NET managed DLL would work like that.

-ner
 
Surely anyone who wanted a single exe with no dependancies would have chosen the appropriate language and compiler, i.e. MSVC++, to start off with?
 
divil said:
Surely anyone who wanted a single exe with no dependancies would have chosen the appropriate language and compiler, i.e. MSVC++, to start off with?

Programming in unmanaged C++ just so you could have everything in a single .exe would be nutty.
 
Since that's the only way to do it effectively, it's not really nutty. More like "required". :-\ What does this program do, anyway? If it's so small, creating it in C++ should be no problem (assuming you're familiar with C++).
 
Back
Top