Thread: The use of a DLL?

  1. #1
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321

    The use of a DLL?

    Everytime you install a game, DLL's are all thats in the directory, and you see no source files. I was wondering what the use of a DLL is and how I would implement one in my engine?

    Thanks.

    Beene

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You posted this kind of thing awhile ago:

    http://cboard.cprogramming.com/showthread.php?t=81050

    Try reading.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You create a Win32 project and specify DLL.

    If you declare your classes/functions as _declspec(dllexport) then that class will be exported. If you declare your classes/functions as _declspec(dllimport) then that class will be imported.

    So you want to use export in the header for creating the DLL and import when you are using the header. In order to use the same header you could do this:

    Code:
    #ifdef DLL_EXPORTS
    #define DLL_API __declspec(dllexport)
    #else
    #define DLL_API __declspec(dllimport)
    #endif
    
    class DLL_API MyClass { };
    If you are creating the DLL then define DLL_EXPORTS inside of your preprocessor options for your project. When you are using the DLL this will not be defined and so the classes/functions will be imported.

    You load a DLL using LoadLibrary and then you can gain function pointers to various functions inside of the DLL. But if you want to use a class from a DLL you just do what I instructed, include the correct header, link with the import lib that was created when you made the DLL, and you can use the class just like a normal C++ class.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. Using class with DLL
    By greg2 in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2003, 05:24 AM
  5. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 05:29 AM