How would I integrate a dll into a exe programmatically

Posted on 2005-04-29
Last Modified: 2008-02-20
Basically i want to package a dll into an exe so when the exe makes a call to the dll it instead calls the function from within itself.
I know their is software out their to do this, but i wish to further understanding of these concepts and have custom control of it.

I am an advanced Visual Basic programmer, a beginner c++, and beginner in asm; beginner meaning experienced enough to write simple programs without help. Ive done quite a bit dissassembling and this where ive gotten my ASM knowledge from. If anything a general procedure of going about this would be appreciated.
Question by:tim102096
    LVL 48

    Expert Comment

    The only thing you forgot to mention is the language in which you want to implement this.
    If this is C++, see the following article:

    Using this way, it is possible to embed Dll into exe resources. At run time, Dll is extracted from resources and saved to file. After this exe file can call functions from Dll using LoadLibrary and GetProcAddress.
    This same way is used for embedded drivers, most utilities from work with their own drivers extracted from resources.
    LVL 8

    Expert Comment

    >>Basically i want to package a dll into an exe so when the exe makes a call to the dll it instead calls the function from within itself.

    that is what happens, a dll loads into exe's process space. so at runtime that function is in the process.

    there is also some thing called static library, if you use them then the function becomes part of exe at compile more specifically linking time itself.

    what exactly do you mean by ,  "i want to package a dll into an exe" ??

    LVL 3

    Expert Comment


    Not sure this will help, but I'll offer this suggestion until you can clarify a few things.

    Clarifications needed:  
    1. Programming language you are using?  
    2.  Is the DLL coded by you or a third party DLL?

    Suggestion:  For now, I'll assume that you wrote the DLL and offer you this suggestion.
    Instead of compiling the DLL, move the code to a class module within your application.

    Of course, this is a totally worthless suggestion if you don't have the code to the DLL.  But we'll try to help once we get some more info from you.

    Good luck.


    Author Comment

    1. Visual Basic is the main one.
    2. DLLS are coded by third party (msvbvm6.dll, etc.)

    I have played around with static dll injection and dynamic dll injection adn succeeded, however this only works if the program is being run in memory as a process. I want to pack them into the actual exe on disc. Theirs a program called PE Packer which i beleive does very similar to what i wish to do.

    Author Comment

    I understand that i could inject the dlls into the end of the exe by declaring a blank data segment, then extract them using code to disc, however i wish to have them completely inside the exe and run from within the exe without ever copying the file to disc. This is for cleaness and to keep clutter out of the directory becuase several other functions are processing any extra files in the directories.
    LVL 19

    Accepted Solution

    There exists a program called IMPLIB.EXE that Microsoft put out a while back.  I think it may ship as part of the Platform SDK or Visual Studio.

    Anyway, here's what you do:

    1.  Run implib.exe against the DLL to convert it to a .LIB file.
    2.  You'll need the header file for the DLL or have function definitions that you intend to use.
    3.  Add the .LIB as part of your project.
    4.  Include the header file or add the appropriate function prototypes.
    5.  Compile, link with the .LIB, and it should be good to go.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now