12-27-2006 10:35 PM
12-28-2006 03:08 AM - edited 12-28-2006 03:08 AM
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:
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
12-28-2006 08:49 AM
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;
}