Thread: making a dll

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    England, Norwich
    Posts
    38

    Question making a dll

    Hello,

    i'm trying to figure out how to make a dll that can be used by a diffrent program that is writion in a diffrent programming langwich i have had alook round the internet but i cna find how to do it.

    btw i'm useing dev-c++
    Last edited by MK4554; 04-04-2006 at 01:38 PM.

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    You'll then need to use LoadLibrary() and GetProcAddress(). There might be other ways but this is how I would do it; google them.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    England, Norwich
    Posts
    38
    erm yeh thats how you load the dll into another program but i'm trying to also figgure out how to make it becuse i used dev-cpp dll and i couldnt get it to work btw i was trying to include it to vb6


    thanks
    1 or 0, Alive Or Dead!
    -------------------------
    OS: Windows XP
    Complier: MinGW
    IDE: Dev-cpp

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    you have to surround all the functions with extern "C" to prevent the compiler from mangling the names
    Code:
    #ifdef _cplusplus
    extern "C" {
    #endif
    // your code here
    #ifdef _cplusplus
    }
    #endif
    Or just simply put the functions in a *.c file so that it gets compiled as C and not C++.

    Don't forget to export the symbols

    For more information google for Mixed Language Programming
    Last edited by Ancient Dragon; 04-04-2006 at 02:07 PM.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    England, Norwich
    Posts
    38
    ok thanks thats helpful but can anyone show me what a basic dll looks like so i know my one is right?
    1 or 0, Alive Or Dead!
    -------------------------
    OS: Windows XP
    Complier: MinGW
    IDE: Dev-cpp

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    A basic dll has only one function -- DllMain() which is similar to main() in a normal C/C++ program. And you compiler will generate the code for that. You will want to manually create a header file that contains the prototypes of the functions you want to export. This is for other C/C++ programs that will use your dll, but won't probably need it for VB6. I don't know how you will declare the function in VB6.

    This will export one function -- foo().

    Code:
    // This is the C source file
    // includes here
    #include <all includes here>
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    __declspec( dllexport ) int foo()
    {
       return 0;
    
    }
    #ifdef __cplusplus
    }
    #endif
    Last edited by Ancient Dragon; 04-04-2006 at 03:41 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DLL Making and Symbols - 2 Queries
    By Tronic in forum C++ Programming
    Replies: 9
    Last Post: 12-31-2004, 01:11 AM
  2. C++ .NET - "inconsistent dll linkage" - What's that?
    By BrianK in forum Windows Programming
    Replies: 2
    Last Post: 03-16-2004, 10:16 AM
  3. Using class with DLL
    By greg2 in forum C++ Programming
    Replies: 2
    Last Post: 09-12-2003, 05:24 AM
  4. DLL & free() Heap Access Violation
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 08-13-2002, 10:45 PM
  5. Exporting Object Hierarchies from a DLL
    By andy668 in forum C++ Programming
    Replies: 0
    Last Post: 10-20-2001, 01:26 PM