Results 1 to 3 of 3
  1. #1
    cru0's Avatar
    Join Date
    Oct 2009
    Gender
    male
    Posts
    102
    Reputation
    10
    Thanks
    11
    My Mood
    Amazed

    Exclamation how to make dlls-tut (long)

    Code:
    Introduction
    
    Trying to find out how to build DLLs for a beginner or even experienced programmer can be complicated to configure and use. This article is to post a simple method of building a DLL and then using that DLL in a project with no effort other than needing to include the header file. All you will need is the class already designed and ready to become a DLL file. Even though this is probably some novice stuff, it is believed some experience in working with the MSVS projects are needed. In addition, the advanced person might find some finer points here that could be useful.
    Background
    
    Some people might find it hard to research on the Internet useful ways of building DLLs the very simple way. The information in this document is actually a collection of information found on this site and other sites on building DLLs so it is nothing new (only pulling together their efforts). A few articles relate in detail on how to build DLLs and highlights the finer points of what a DLL actually is and how to use it. I suggest reading them first to find broader definitions.
    
    However, it seems that a lot of effort to the novice "DLL Builder" is lacking or too complicated to understand thereof. You may have heard from someone it is easy to build DLLs but trying to figure out how it all pulls together can be an effort in its own. Some articles do not seem to also highlight the importance of directory locations. A DLL, its library and header file(s) must all be in a findable directory that can either be a Windows directory or somewhere where the compiler can find them. Otherwise you may encounter frustrating compiler problems if one or all of the DLLs file are not found, which usually results in an unusable circumstance.
    Using the code
    
    There are no code attachments other than comment areas. This should be simple enough to figure out by working alongside in your MSVS environment. What you will need to do is:
    
       1. Have a class already prepared that needs to be a DLL file.
       2. Start a new DLL project
       3. Insert MACRO definitions in your �StdAfx.h� file.
       4. Add easy including of the DLL libraries in the main �foo.h� file.
       5. Add some project preprocessor MACROs.
       6. Make batch files for the �Post Builds� - to appropriately copy library, header and DLL files to findable directory(s). 
    
    Details
    
       1. It is assumed that you already created your class, so this step is bypassed.
       2. First is the easy part. Start up �Microsoft Visual Studio Visual C++�. Select �File->New� to pull up the creation dialog. Under the �Projects� tab button, select �MFC AppWizard (DLL)�. Enter the project name and directory to be used then click �OK�. The rest of the options are not necessary, so select what you want to do in the rest of the Wizard and click �Finish�.
    
          What typically happens after you started the new project is that a source code and header file has been created for you. These are not really needed if you already have the code you are going to build. Only the preset definitions for the project are needed from this step. It is suggested that you just empty the files created by highlighting and deleting the source and header files created by the Wizard. Do not edit the �StdAfx� files yet as these are needed.
    
          The point in this step is to simply copy and paste your class (�foo�) into the header and source files created. It should be a simple concept to grasp, but if you are skeptical you can alternatively just add your �foo� source file and header file into the project so that it is built.
    
          You will next begin the editing part. You must be able to make the build compile as a DLL file correctly for usage. DLL files use a combination of Exporting and Importing. When this is the build project you will need to �Export�. When it is being included in another project that does not use the source code, you will need to �Import�. This is probably the harder part of understanding the DLL as it is not necessarily implemented for you and requires a little effort before understanding. As a side note, the �resource.h� is only required by DLLs that have dialogs in them. In this case, you will have to remember that you may have several �resource.h� files then and will have to include a full path statement to each �resource.h� file. This article will show in the following example what is probably the best method (keeping in mind that if a project needs this resource file it must manually be added to the project including the full path to it).
       3. Edit the �StdAfx.h� file and include the following MACROS and header file �resource.h�.
          Collapse
    
          StdAfx.h
          //
    
          // MSVS included headers, definitions, etc.
    
          //
    
    
          // Somewhere near the bottom
    
          //This is the project macro preprocessor definition 
    
          //you will be adding shortly.
    
          #ifdef DLL_EXPORTS
          //This is to be used for the class header file.
    
          #define DLL_BUILD_MACRO __declspec(dllexport)
          #else
          #define DLL_BUILD_MACRO __declspec(dllimport)
          #endif
    
          #ifndef _DLL_BUILD_ //Why do this? Is it necessary? Yes.
    
          #define _DLL_BUILD_ DLL_BUILD_MACRO
          #endif
    
          //make sure resources are included here, if desired, 
    
          //to prevent ambiguous
    
          //callings to different resource.h files.
    
          #include �resource.h�
    
    
          //
    
          // Rest of file
    
          //
    
       4.
              * Next we go ahead and edit the main header file of your DLL code. Only a few simple lines need be added to support accurate DLL building and usage:
                Collapse
    
                foo.h
                #ifndef _FOO_H_
                #define _FOO_H_
    
                //
    
                // Miscellanous here
    
                //
    
    
                /*This part automatically includes any libraries when called.
                When this file is built within the DLL project, 
                it will not be called because
                of our preprocessor macro definition �_FOO_DLL_�.
                However, when this file is called from another project, 
                not part of this build,
                it appropriately chooses the correct library and 
                includes them for you.
                WHAT this means is that you will not have to 
                add the library to the project link settings
                for a project that requires this DLL. This helps to 
                avoid the tedious task of
                linking to several custom DLLs.
    
                Note there are two different libraries here and 
                probably not necessary but give
                you an idea of how to separate debug versions 
                from release versions.*/
    
                #ifndef _FOO_DLL_
                #ifdef _DEBUG
                //You will be building a debug program that 
    
                //uses this file, so in this case we
    
                //want the debug library.
    
                #pragma comment( lib, �food.lib� ) 
                #else
                //You will be building a release program that
    
                //uses this file, so in this case we
    
                //want the release library.
    
                #pragma comment( lib, �foo.lib� ) 
                #endif
                #endif
                #ifndef _DLL_BUILD_
                #define _DLL_BUILD_ //Makes sure there are no compiler errors.
    
                #endif
    
                class _DLL_BUILD_ foo
                private:
                //
    
                // Your members
    
                //
    
                public:
                //
    
                // Your functions
    
                //
    
                };
    
                #endif
    
              * To continue, edit the �foo.cpp� file and make sure you include the appropriate headers.
                Collapse
    
                foo.cpp
    
                #include �stdafx.h� //place first
    
                #include �foo.h�
    
    
                //
    
                //Your code
    
                //
    
       5.
              * This next step requires that you actually add the MACROS into the project settings. In the menu tool bar, go to �Project->Settings�� or press Alt+F7 alternatively. Click the �C/C++� tab. Under �Preprocessor definitions:� add the macro definitions �_FOO_DLL_� and �DLL_EXPORTS� at the end of the list of other macro definitions. Be sure to separate each new MACRO with a coma (�,�). Make sure to do this for the release version too, as you will have to redo these next steps for each type of build. Make sure to build with any �debug info� and/or �browse info� if this is a debug version and if you want to debug the DLL later using the MSVS debugger.
              * Next you will want to prepare for the last step. Go to the �Post-build step� tab under the same dialog. Under �Post-buid command(s):� click an empty space and enter �Debug.bat�. For the release version go to in the left pane and in the combo box �Settings For:� select �Win32 Release�. Enter like you did before in �Post-Build command(s)� but not �Debug.bat� and instead �Release.bat�. This is it for all the project settings. 
       6. Now to build the batch files. Create a blank file. You will be adding command line codes that will copy your files to a findable directory. The point here is that if you may have a ton of DLLs and it will be easier to have all the needed components in one directory. This is easier versus linking to several directories. Below are the suggestions used in this article that maybe you will want to consider for adding other options:
          Collapse
    
          Debug.bat
          Copy �Debug\foo.lib� �c:\<libraries dir>\food.lib�
          REM copy the dll file to the windows system32 
          REM directory to make the DLL easily
          REM accessible.  Note that you will have to install or include the
          REM dll file in your distribution package for the program that uses it.
          Copy �Debug\foo.dll� �c:\%system dir%\system32�
          Copy �foo.h� �c:\<headers dir>�
    
          Release.bat
          Copy �Release\foo.lib� �c:\<libraries dir>�
          REM copy the dll file to the windows system32 directory 
          REM to make the DLL easily accessible.
          REM Note that you will have to install or include the dll 
          REM file in your distribution package.
          REM Unfortanetly this will overwrite any other DLL files 
          REM such as the Release/Debug version,
          REM so accurate update compilations are needed.  
          REM You will have to note this yourself
          REM before distributing to the public.
          Copy �Release\foo.dll� �c:\%system dir%\system32�
          Copy �foo.h� �c:\<headers dir>�
    
    You are completely finished. Providing you have already pre-tested your class and considered where your library, header and DLL files are being copied you should receive no problems at all. Your class should be a DLL file that can be easily used in future projects without much work. All you have to do with this information is to know that you only need to include the header file and everything is done for you. Everything is made as easy and simple as possible for you on in out.
    sorry for long but it helps i riped it save in wordpad or vist this site

    CodeProject: Making DLLs easy to build and use. Free source code and programming help
    is that advertising? sorry didnt know its just the tutorial also *neater*
    both have post about dlls and im learning it, its same as c++
    but saves times learning about how o set it up
    functions you will need to learn by your self
    Last edited by cru0; 12-25-2009 at 10:54 PM.

  2. The Following 3 Users Say Thank You to cru0 For This Useful Post:

    Akisuzi (01-01-2010),KayNineKid (01-02-2010),nanisaywhat (01-08-2010)

  3. #2
    KayNineKid's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    Cloud 9; CA: Overdose.
    Posts
    134
    Reputation
    10
    Thanks
    50
    My Mood
    Amused
    Hey It's KayNineKid From ******** ^^

    My sig from like 2008..lol

  4. #3
    zmansquared's Avatar
    Join Date
    Oct 2008
    Gender
    male
    Location
    Kickin it at Microsoft
    Posts
    2,088
    Reputation
    36
    Thanks
    221
    My Mood
    Cheerful
    that was sorta a waste of time. sorry but thanks
    Need Help With Coding or Something??? MSN me
    zmansquared@hotmail.com


    I am the one and only Microsoft Fag!!!

    Quote:
    Originally Posted by Arhk
    All games should be hacked, if we don't do it someone else will. Hackers force the progress, of better programming methods.
    ~


    Take this Pic everyone!



    next-

Similar Threads

  1. How To Make Dll With Source [EASY]
    By [Banned]mark0108 in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 89
    Last Post: 12-15-2010, 02:28 AM
  2. how to make. dll for warrock???
    By rgomez72 in forum WarRock Discussions
    Replies: 1
    Last Post: 07-28-2010, 12:46 PM
  3. how to make dll
    By warball8 in forum Combat Arms Help
    Replies: 4
    Last Post: 06-09-2010, 07:39 AM
  4. Replies: 72
    Last Post: 08-09-2009, 05:45 AM
  5. How to make hacks TUT
    By morzan364 in forum Combat Arms Hacks & Cheats
    Replies: 8
    Last Post: 04-13-2009, 07:00 PM