Need help with dlls
-
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.
-
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.
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!
-
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.
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