LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

main and Dllmain in one file

I have one CVI project and sometime I want to create dll and sometime I want to create exe. Can I have both main and Dllmain function in one c file?
 
 
Thanks.
CVI 2010
LabVIEW 2011 SP1
Vision Builder AI 2011 SP1
0 Kudos
Message 1 of 3
(3,748 Views)

Hi Sheetal,

you could use conditional compilation by use of some predefined macros to detect which part of code to compile based on your target type. According to the documentation, these macros are defined in the IDE depending on your target type:

  • _CVI_EXE_ is defined if the project target type is Executable.
  • _CVI_DLL_ is defined if target type is Dynamic Link Library.
  • _CVI_LIB_ is defined if target type is Static Library.
  • Project target type can be defined in Build > Target type menu item, and a list of predefined macros can be viewed in Options > Build Options menu item. You could start coding with a structure like the following, to be filled next with specific code for the different scenarios:

    #ifdef _CVI_EXE_

    int main (int argc, char *argv[])
    {
     if (InitCVIRTE (0, argv, 0) == 0)
      return -1;    /* out of memory */
     
     return 0;
    }

    #elif _CVI_DLL_

    int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    {
     switch (fdwReason) {
      case DLL_PROCESS_ATTACH:
       if (InitCVIRTE (hinstDLL, 0, 0) == 0)
        return 0;   /* out of memory */
       break;
      case DLL_PROCESS_DETACH:
       CloseCVIRTE ();
       break;
     }
     
     return 1;
    }

    int __stdcall DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    {
     /* Included for compatibility with Borland */

     return DllMain (hinstDLL, fdwReason, lpvReserved);
    }
    #endif

    It is to be said that I never used such a EXE vs. DLL option, but I successfully used conditional compilation to detect EXE vs. IDE execution and in my opinion it is a powerful option we have in our hands.

    Hope this can help you
    Roberto

    Message Edited by Roberto Bozzolo on 12-28-2006 10:12 AM



    Proud to use LW/CVI from 3.1 on.

    My contributions to the Developer Community
    ________________________________________
    If I have helped you, why not giving me a kudos?
    Message 2 of 3
    (3,746 Views)

    Thanks for your response.

    This answers my question.

    Actually I tried without using condition compilation and it seems to work both ways with exe and with dll.

    #include <cvirte.h>

    int main (int argc, char *argv[])
    {
     if (InitCVIRTE (0, argv, 0) == 0)
      return -1;    /* out of memory */
     
     return 0;
    }
    int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
    {
     switch (fdwReason)
     {
      case DLL_PROCESS_ATTACH:
       if (InitCVIRTE (hinstDLL, 0, 0) == 0)
        return 0;   /* out of memory */
       break;
      case DLL_PROCESS_DETACH:
       CloseCVIRTE ();
       break;
     }
     
     return 1;
    }

     

    Thanks.
    CVI 2010
    LabVIEW 2011 SP1
    Vision Builder AI 2011 SP1
    0 Kudos
    Message 3 of 3
    (3,733 Views)