DLL's

This is a discussion on DLL's within the C++ Programming forums, part of the General Programming Boards category; DLL's (dynamic link liabrarys) made in c++??...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    32

    Post DLL's

    DLL's (dynamic link liabrarys) made in c++??

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Sometimes.

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Good answer.

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    They are the the operating systems way of converting your source code into Win32 instructions that are executed in kernal mode. I don't know much else about it though.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    They can be written in C......

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    >They are the the operating systems way of converting your source code into Win32 instructions that are executed in kernal mode. I don't know much else about it though.

    Maybe some dll's but that's not their purpose. They just provide dynamic linking to libraries (functions), rather than the static ones that are linked to your exe when linking, they don't have to have anything to do with kernel mode.

    >They can be written in C......

    and more often than not are (or externed "C") to prevent name mangling issues.

  7. #7
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    In the .net PE file Assembly you have dll's and exe's (as well as a manafest), but how are these different? The dll's and the exe's that is. And especially in .net.

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Originally posted by Troll_King
    In the .net PE file Assembly you have dll's and exe's (as well as a manafest), but how are these different? The dll's and the exe's that is. And especially in .net.
    DLLs are simply dynamically loaded lumps of code.....Instead of the code being linked into your executable by your compiler, the extra code is exported from the dll at run time......The benefit of this is that you can have 10 programs all reading off the same dll, therefore less disk space. Also if there is a bug with a distributed application, its a lot easy to distribute another dll than the whole exe. Also, Dlls arent exeutable as they have no main() or WinMain().

    You are right that windows uses a lot of dlls (hal.dll,kernal32.dll.....) but Operating Systems are not their only use

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    12
    I see, okay that clears up a few of the issues I was wondering about dll's. Can you give me a sample C++ program that would compile into a dll in vc6?

  10. #10
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    OK here's your very first dll.....

    Create a new project, but create a "Win32 Dynamic Link Library" instead of a normal console......use the following code;

    Code:
    #include <windows.h>
    #include <iostream>
    using std::cout;
    using std::endl;
    #include <string>
    using std::string;
    
    #define DllExport extern "C" __declspec (dllexport) 
    
    
    
    DllExport void Greeting(int nNameNo){
    string str("");
    
    	str += "Hello ";
    	
    	switch(nNameNo){
    	case 0:
    		str += "Dean";	
    		cout << str.c_str();
    		break;
    	case 1:
    		str += "Mars Terminal";	
    		cout << str.c_str();
    		break;
    	case 2:
    		str += "Troll_King";	
    		cout << str.c_str();
    		break;
    	default:
    		str += "Whoever you are";	
    		cout << str.c_str();
    		break;
    	}
    
    
    }
    Now build it.....In the debug folder, you will have a .dll and a .lib file...

    Now create a standard console project.....Go to project->settings->link and add the name of the library you just created with all the other libs in the edit box called "Object Library Modules"

    Now create a header for this project and call it "dean.h". Enter the following;

    Code:
    #define DllImport extern "C" __declspec (dllimport)
    
    DllImport void Greeting(int nNameNo);
    now include a c++ file into your project.....enter the following code;

    Code:
    #include <windows.h>
    #include <iostream>
    using std::cout;
    using std::endl;
    using std::cin;
    #include "dean.h"
    
    int main(){
    	char cResp;
    	int nNameNo = 0;
    	while(1){
    		cout << "Press 'x' to use dll, 'z' to exit" << endl;
    		cin.get(cResp);
    		if(cResp == 'x'){
    			Greeting(nNameNo);
    			cout << endl;
    			++nNameNo;
    			if(nNameNo > 2) nNameNo = 0;
    		}
    		if(cResp == 'z')break;
    		cin.ignore();
    	}
    
    	return 0;
    }
    Now just compile it (do not build).....

    Now go to the folder of this console project and add the .lib you created earlier......then go into the projects debug and add the actual dll...

    Now build......it should build ok....

    Now run the .exe you created.........as long as the .dll is in the same dir...it should work....give it a try
    Last edited by Fordy; 02-22-2002 at 02:48 AM.

  11. #11
    Registered User
    Join Date
    Jan 2002
    Posts
    12
    That doesn't look too bad, thanks. Anyone mind doing an example now in C# using Assemblies? I see that Prezel has a whole chapter dedicated to this in his 5th edition. God knows if I'll ever read it though. I think that using dll's might be a lot easier with .NET because I think you can use System.Reflection and not have to move files and the lot. Probably nobody knows about it though.
    Last edited by Mars Terminal; 02-22-2002 at 02:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Protection of DLLs
    By Poche in forum C# Programming
    Replies: 5
    Last Post: 06-04-2009, 08:30 PM
  2. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  3. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  4. Can't load string from resource DLL's string table
    By s_k in forum Windows Programming
    Replies: 4
    Last Post: 07-15-2003, 06:43 AM
  5. question about DLL's and class functions
    By btq in forum Windows Programming
    Replies: 2
    Last Post: 02-25-2003, 05:08 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21