User forums > Using Code::Blocks
writing a dll
thomas:
--- Quote ---In all honesty you dont ned a .h file at all. Its just a convienence factor. What you DO need is in the DLL project itself your functions need defined as
void __declspec(dllexport) myFunction();
and in the project using those functions you need a declaration in the form of
void __declspec(dllimport) myFunction();
--- End quote ---
And that is what this header does. In fact, dllexport is the only thing needed to build a DLL at all. DllMain() is entirely optional and useless (I even consider it harmful), and dllimport is only a compiler optimisation.
What you do need, however, is a consistent way to declare your functions and variables for both the library and a program using the library -- at least, if you plan to do anything more serious than "Hello DLL".
This is what the macro is about, it adds dllexport where it's needed, and only there, and leaves everything else intact and in sync.
Seronis:
Few questions:
1. How do you consider dllmain() to be harmful? (as compared to just being used/not used)
2. dllimport is -only- an optimization?
thomas:
1. Read MSDN's description. :)
2. It allows the compiler to eleminate a thunk in the DLL, so using that attribute effectively saves one pointer worth of memory per exported function plus some (insignificant) setup. If you omit it alltogether, nothing evil will happen, your program will work the same.
arturapps:
Thanks people!
I´m going to write a header for using with my dlls wright now !
Seronis:
--- Quote from: thomas on March 14, 2008, 05:11:34 pm ---1. Read MSDN's description. :)
--- End quote ---
Well I already consider msdn to be harmful, but i'll read the description later anyways =-)
Navigation
[0] Message Index
[*] Previous page
Go to full version