c - My dll is exporting every function without my consent! -


i using mingw compiler , code blocks ide. facing problem in don't understand how come dll exports every function without me using __declspec(dllexport) these functions. here 2 sample files, main.h , main.cpp:

main.h:

#ifndef __main_h__ #define __main_h__ #include windows.h  #ifdef build_dll     #define dll_export __declspec(dllexport) #else     #define dll_export __declspec(dllimport) #endif  #ifdef __cplusplus extern "c" { #endif  void somefunction(const lpcstr sometext);  #ifdef __cplusplus } #endif  #endif // __main_h__ 

main.cpp:

#include "main.h"   void somefunction(const lpcstr sometext) {     messageboxa(0, sometext, "dll fxn message", mb_ok | mb_iconinformation); }  bool flag = false;  extern "c" bool winapi dllmain(hinstance hinstdll, dword fdwreason, lpvoid lpvreserved) {     switch (fdwreason)     {         case dll_process_attach:             // attach process             // return false fail dll load             break;         case dll_process_detach:             // detach process             break;         case dll_thread_attach:             // attach thread             break;         case dll_thread_detach:             // detach thread             break;     }      flag = true;      return true; // succesful } 

in example, somefunction exported , able dynamically call application externally, although haven't prototyped as

void __declspec(dllexport) somefunction(const lpstr sometext); 

not this, global variable flag exported in auto generated .def file.

what happening here? please , correct me if making technical mistake.

the mingw linker makes symbol public unless make them hidden default. can overridden, gcc man-page:

-fvisibility=default|internal|hidden|protected  ...  explanation of benefits offered ensuring elf symbols            have correct visibility given "how write shared            libraries" ulrich drepper (which can found @            <http://people.redhat.com/~drepper/>)---however superior solution            made possible option marking things hidden when            default public make default hidden , mark things            public.  norm dll's on windows ,            -fvisibility=hidden , "__attribute__ ((visibility("default")))"            instead of "__declspec(dllexport)" identical            semantics identical syntax.  great boon            working cross-platform projects. 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -