Using DLLs after compiled...

This is a discussion on Using DLLs after compiled... within the Windows Programming forums, part of the Platform Specific Boards category; I have created a DLL and I want to use it. What do I do to calla certain function in ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question Using DLLs after compiled...

    I have created a DLL and I want to use it. What do I do to calla certain function in the .dll?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    ok heres a quick program...


    The DLL shoud look as follows:

    dll.h
    Code:
    #ifndef _IMPORTING_MY_DLL_
    #define FUNCTION __declspec(dllexport)
    #else
    #define FUNCTION __declspec(dllimport)
    
    FUNCTION void myfunc(void);
    dll.cpp
    Code:
    #include <stdio.h>
    #include "dll.h"
    
    void myfunc(void)
    {
        printf("Using function inside a dll.");
    }
    ok now make sure to link to the lib that you created with the DLL, and to move the dll.h to a place the program can find it.

    the program should do as follows

    main.cpp
    Code:
    #define _IMPORTING_MY_DLL_
    #include "dll.h"
    
    /*edit*/
    
    // Replace Mydire with the lib directory, and mylib with the lib name
    #pragma comment(lib,"mydir\mylib.lib");
    
    /*edit*/
    
    int main(void)
    {
        myfunc();
        return 0;
    }
    Last edited by no-one; 02-04-2002 at 04:36 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question How do I...?

    I want to get the function from the actual .dll file.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    you mean call it or ?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Yes...

    Yes, I mean call the function. For example, the function make a message box.
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    well as long as you have __declspec(dllexport) before the function declaration in the dll, heres is all you have to do,

    Link to the lib,
    and redeclare the function with __declspec(dllimport) in the calling program before you use it and it should work perfectly,

    like this

    __declspec(dllimport) int myfunc(char* t,char* s);

    int main(void)
    {
    myfunc("BOOYA!","Grandma!...BOOYA!!");
    }

    see the example i gave above if its not clear(its a fully functional program).

    also use a define in the dll header to do the switching form import to export for ease of use..

    ::edit:: you can use comment(lib,"C:\libs\mylib.lib") to link to the library.
    Last edited by no-one; 02-04-2002 at 04:37 PM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  7. #7
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Talking Thanks!

    That worked!
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-12-2008, 12:10 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Some doubts on DLLs
    By BrownB in forum Windows Programming
    Replies: 1
    Last Post: 05-30-2007, 02:25 AM
  4. standart dlls
    By keeper in forum C++ Programming
    Replies: 3
    Last Post: 07-05-2006, 07:32 PM
  5. Operator overloading in template classes
    By moejams in forum C++ Programming
    Replies: 5
    Last Post: 07-21-2003, 05:16 PM

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