Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need help with dlls

Need help with dlls

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VanHlebar
    wrote on last edited by
    #1

    I have an application that I really want to move a good portion of the code out into a dll. This is all code that is static and will not change over over the life of the application and contains mostly static data (strings and such). I know what I want to do, but I can't figure out how to write the dll correctly to be able to access the one exported function. Does anyone have any good books that you would recommend to assist me in understanding the process of creating the dll, then the code needed to be able to use the exported function. Thanks for the help, -Eric PS I have tried understanding the help files in evc++ and msdn about using _declspec but when I attempt to use GetProcAddress() I always get NULL returned.

    J T 2 Replies Last reply
    0
    • V VanHlebar

      I have an application that I really want to move a good portion of the code out into a dll. This is all code that is static and will not change over over the life of the application and contains mostly static data (strings and such). I know what I want to do, but I can't figure out how to write the dll correctly to be able to access the one exported function. Does anyone have any good books that you would recommend to assist me in understanding the process of creating the dll, then the code needed to be able to use the exported function. Thanks for the help, -Eric PS I have tried understanding the help files in evc++ and msdn about using _declspec but when I attempt to use GetProcAddress() I always get NULL returned.

      J Offline
      J Offline
      Jim Crafton
      wrote on last edited by
      #2

      make you public header for your function(s) foo.h

      #ifndef _FOO_H__
      #define _FOO_H__

      #ifdef USE_MY_LIBRARY
      #define MY_LIB_API __declspec(dllimport)
      #else
      #define MY_LIB_API __declspec(dllexport)
      #endif

      #extern "C" {
      MY_LIB_API void MyFunc( int aValue );
      }

      #endif

      implement the function in some file that is compiled for your DLL say Foo.c #include "Foo.h" void MyFunc( int aValue ) { //do something } when you compile the DLL make sure that USE_MY_LIBRARY is NOT defined. this will ensure that you are using the __declspec(dllexport) form of the function and will automatically export the function for you. You should end up with a DLL that exports a single function (assuming these are the only files). The extern "C" guarantees that you will not have name mangling. You can use the DLL with either LoadLibrary() and GetProcAddress(), which is the hard way, or you can make sure that your DLL project emits a .lib file and in the project that uses the DLL, link with this .lib file. If you choose the latter method, make sure that USE_MY_LIBRARY is defined. Cheers and hope this helps ¡El diablo está en mis pantalones! ¡Mire, mire!

      1 Reply Last reply
      0
      • V VanHlebar

        I have an application that I really want to move a good portion of the code out into a dll. This is all code that is static and will not change over over the life of the application and contains mostly static data (strings and such). I know what I want to do, but I can't figure out how to write the dll correctly to be able to access the one exported function. Does anyone have any good books that you would recommend to assist me in understanding the process of creating the dll, then the code needed to be able to use the exported function. Thanks for the help, -Eric PS I have tried understanding the help files in evc++ and msdn about using _declspec but when I attempt to use GetProcAddress() I always get NULL returned.

        T Offline
        T Offline
        TOMTEFAR
        wrote on last edited by
        #3

        Another way of doing it would be for you to learn COM+ wich is the standard that Microsoft uses for Dll's. I find COM+ the easiest way of doing it. Preferably by using ATL but you can do it with MFC aswell. Any respectible book about MFC or ATL would do for you. Just make sure that the MFC book contains chapters about COM/Automation/OLE. /Martin

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups