LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does LabView dll not work in C Thread?

Hello Everybody,

I want to use a LAbView Application as Dll in a Console Application.
There is an Example Available (DLL_Example.zip)in (Displaying the Front Panel of a LabVIEW-Built DLL Function)

When I use this Example in a Windows Console Application, it Works fine (It is important for me, to see the LV Window!)

Code example:
/***********************************************************/
/* Example Start *******************************************/
/***********************************************************/
int main(int argc, char* argv[])
{
double Y = 4;
double X = 5;
double Result = 0;

SimpleCalculator(1, Y, X, &Result);
printf("Result = %f", Result);
return 0;
}
/***********************************************************/
/* Example Stop *******************************************/
/***********************************************************/

When I use the function "SimpleCalculator" in a Thread, the LabView Window never appear, what's wrong?

Code example:
/***********************************************************/
/* Example Start *******************************************/
/***********************************************************/
DWORD WINAPI LVThread(LPVOID lpParameter)
{
double Y = 4;
double X = 5;
double Result = 0;

SimpleCalculator(1, Y, X, &Result);
printf("Result = %f", Result);
return 0;
}

int main(int argc, char* argv[])
{
DWORD ThreadID;
CreateThread(NULL,0,LVThread, NULL, 0, &ThreadID);

getchar();
return 0;
}
/***********************************************************/
/* Example Stop *******************************************/
/***********************************************************/

I'm using Microsoft Visual Studio 6.0. and LabView 7.0

Thanks for every help.
0 Kudos
Message 1 of 2
(2,657 Views)


@bobby wrote:
Hello Everybody,

I want to use a LAbView Application as Dll in a Console Application.
There is an Example Available (DLL_Example.zip)in (Displaying the Front Panel of a LabVIEW-Built DLL Function)

When I use this Example in a Windows Console Application, it Works fine (It is important for me, to see the LV Window!)

Code example:
/***********************************************************/
/* Example Start *******************************************/
/***********************************************************/
int main(int argc, char* argv[])
{
double Y = 4;
double X = 5;
double Result = 0;

SimpleCalculator(1, Y, X, &Result);
printf("Result = %f", Result);
return 0;
}
/***********************************************************/
/* Example Stop *******************************************/
/***********************************************************/

When I use the function "SimpleCalculator" in a Thread, the LabView Window never appear, what's wrong?

Code example:
/***********************************************************/
/* Example Start *******************************************/
/***********************************************************/
DWORD WINAPI LVThread(LPVOID lpParameter)
{
double Y = 4;
double X = 5;
double Result = 0;

SimpleCalculator(1, Y, X, &Result);
printf("Result = %f", Result);
return 0;
}

int main(int argc, char* argv[])
{
DWORD ThreadID;
CreateThread(NULL,0,LVThread, NULL, 0, &ThreadID);

getchar();
return 0;
}
/***********************************************************/
/* Example Stop *******************************************/
/***********************************************************/

I'm using Microsoft Visual Studio 6.0. and LabView 7.0

Thanks for every help.




Check out luciangeeks's explanation elsewhere on this forum in several threads about the message loop needing to be pumped by the intial thread starting up the LabVIEW runtime system. In Windows console applications the hidden startup code linked in from the C runtime library to intialize the environment before passing control to the console applications main function also contains a message loop, polling the Windows message queue to among other things translate those messages into keychars so that the C runtime library function getchar() and friends can work as expected. It also makes the console application look responsive to the Windows system so that Windows doesn't think it would need to shutdown the application. LabVIEW DLLs really running as GUI components can't work without an active message loop making sure those system messages are retrieved and distributed to the according (usually hidden) VI windows. However the setup in Windows makes it such that a DLL sort of inherits the message loop of the thread which first entered that DLL. If that thread does not have a message loop, LabVIEW windows simply can't work properly and this means that the LabVIEW code is not managed properly and therefore won't run.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 2
(2,601 Views)