Hello everyone,
I'm having a problem using a DLL with self written DLLmain. Maybe someone can tell me what is wrong.
The DLL is
// ########## DLL ################################
#include <cvirte.h>
#include <ansi_c.h>
/*
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
printf("a process attached\n");
break;
case DLL_PROCESS_DETACH:
printf("a process detached\n");
CloseCVIRTE ();
break;
case DLL_THREAD_ATTACH:
printf("a thread attached\n");
break;
case DLL_THREAD_DETACH:
printf("a thread attached\n");
break;
}
return 1;
}
int __stdcall DllEntryPoint (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
// Included for compatibility with Borland
return DllMain (hinstDLL, fdwReason, lpvReserved);
} */
int DummyFunction(void) {
printf("InterfaceDummy: DummyFunction called\n");
return 0;
}
//##### end DLL ############################
and the program using the DLL is
#include <windows.h>
#include <cvinetv.h>
#include <ansi_c.h>
#include <cvirte.h>
#include "InterfaceDummy.h"
extern int CVIFUNC RTIsShuttingDown (void);
void CVICALLBACK SubscriberCallback(void * handle, CNVData data, void * callbackData) {
unsigned long nDims;
CNVDataType type;
static int counter=0;
printf("trigger: callback ");
if (data == 0)
return;
CNVGetDataType (data, &type, &nDims);
// Abort / Start case
if (type == CNVBool && nDims == 0) {
char value;
CNVGetScalarDataValue(data,CNVBool,&value);
if (value) {
DummyFunction();
counter++;
}
}
printf("%d\n",counter);
CNVDisposeData(data);
}
void CVIFUNC_C RTmain (void)
{
CNVSubscriber hSubscriber;
int error;
if (InitCVIRTE (0, 0, 0) == 0)
return; /* out of memory */
Sleep(20000);
printf("trigger: program started\n");
DummyFunction();
if( error = CNVCreateSubscriber("\\\\134.245.69.241\\trigger\\Trigger",SubscriberCallback,0,0,10000,0,&hSubscriber)){
printf("trigger: error occured while creating subscriber\n");
return;
}
else
printf("trigger: subscriber created\n");
while (!RTIsShuttingDown () && error==0)
{
Sleep (500);
}
if(error = CNVDispose(hSubscriber)) {
printf("trigger: error: ");
printf(CNVGetErrorDescription(error));
}
printf("trigger: program exited\n");
CloseCVIRTE ();
}
//##### end program ############################
As long as DLLmain() is commented out everything is fine. The program runs just as expected. But when I compile the DLL with the DLLmain function and start the program, the system crashes with the output:
Fatal error KERNEL.146640: Thread stack overflow. Thread ID=95
Thread stack range =0x37F9000 - 0x37F9FFF, size 4096
current ESP = 0x37F8C58
I'm using Labwindows/CVI 8.5.0. The program runs on a NI PXI-8196 RT Controller.