Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: Macro for checking configuration type (exe/dll)

Is there a macro I can use for checking the current configuration type in visual studio? Depending on the current setting I'd like to either include a main or dllmain function:

#IFDEF CONFIGURATION_TYPE_EXE

     int main(int argc, char **argv)
     {
       ...
     }
#ELSEIF CONFIGURATION_TYPE_DLL


    BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
    {
        return TRUE;
    }

#ENDIF
like image 362
Pedro Avatar asked Oct 08 '11 15:10

Pedro


2 Answers

If it's dll then _WINDLL will be defined as inherited value. You can find it here: Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions.

#ifdef _WINDLL
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{ ... }
#else
int main(int argc, char** argv)
{ ... }
#endif
like image 53
qik Avatar answered Sep 19 '22 13:09

qik


If it's a DLL project, the _USRDLL will be defined. (see Configuration Properties\Preprocessor\Preprocessor definitions).

Be careful though, because the list is filled by wizard and will not update automatically if the project was created as something else and then configured as DLL. Also, you have to be careful if you are building a lib to be linked with a DLL.

like image 32
ruslik Avatar answered Sep 17 '22 13:09

ruslik