[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Need a Second Set of Eyes on Some Simple dll Code (Few 100 lines)

Posted on 2008-01-28
24
Medium Priority
?
625 Views
Last Modified: 2008-03-06
I am running into continued problems with a project that utilizes a simple dll in C++, which is turning into a you-know-what storm and am looking for some help.  

Could one of you experts take a gander at my code and see if you see any big no-nos or errors?  I work for a small company and don't really have any other peers which can review it with me.  There isn't that much code, and most if it is just standard windows file manipulation stuff.

I will post the link to the code zip file in the next post if anyone is interested.  Thanks for any and all help.

--Charly
0
Comment
Question by:dleehanson
  • 13
  • 9
  • 2
24 Comments
 
LVL 1

Author Comment

by:dleehanson
ID: 20759693
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20759696
You can post the zip file, but it would be better if you could just paste the code here in this thread.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20759724
Also, could you describe the exact problems you're experiencing ?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 1

Author Comment

by:dleehanson
ID: 20760039
The problems we are experiencing is that everything will run fine for 3-4 days, then the MS Server 2003 server crashes giving a stop error, which I'll have to look up again.  We are pretty sure that the problem is with the 3rd party application calling the dll, but there is a finger pointing war in which I need to be confident that the problem is not a result of my code in the dll.

I'll post the code right away.

--Charly
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760113
ZebraPrinter class:
---------------------------------
ZebraPrinter.h
---------------------------------
#pragma once
#define TEXT_SIZE 32
 
// Class ZebraPrinter -------------------------------------------//
 
class ZebraPrinter
{
public:
	ZebraPrinter(void);
	~ZebraPrinter(void);
	bool Load();
	bool Reload();
	int AppNumber();
	char shareName[TEXT_SIZE];
	char printerName[TEXT_SIZE];
	char countFile[TEXT_SIZE];
private:
	int appNumber;
	bool FindString(char toFind[], char toLook[]);
	char *ReturnString(char toFind[], char toLook[]);
	int StrCompare(char Str1[], char Str2[]);
};
 
---------------------------------
ZebraPrinter.cpp
---------------------------------
 
#include "stdafx.h"
#include "ZebraPrinter.h"
#define SETTINGS_FILE "\\\\SUNNY\\applicator2\\pciElectric.ini"
//#define SETTINGS_FILE "\\\\ADC-EGFNTS1\\applicator1\\pciElectric.ini"
 
#pragma warning(disable : 4996)						//Disable security deprecation warnings
 
// Class Code ----------------------------------------------------//
 
ZebraPrinter::ZebraPrinter(void){
	appNumber = 0;
}
 
ZebraPrinter::~ZebraPrinter(void){
}
 
bool ZebraPrinter::Load() {
	return(Reload());
}
 
bool ZebraPrinter::Reload() {
	FILE *iniFile;
	char *iniText;
	char tempText[TEXT_SIZE];
	bool fail = false;
	long fileSize;
	int  i;
 
	iniFile = fopen(SETTINGS_FILE,"r");
	// The file exists, otherwise we're screwed
	if (iniFile != 0) {
		// Get filesize
		fseek(iniFile,0,SEEK_END);
		fileSize = ftell(iniFile)-1;
 
		// Rewind file pointer
		rewind(iniFile);
		// Allocate memory, return -1 if an error occurs
		if( (iniText = (char *)malloc( fileSize+1 * sizeof( char ) )) == NULL )
			fail = true;
 
		// Read the file into the array
		for (i=0;i<=fileSize;i++) {
			iniText[i] = fgetc(iniFile);
		}
		i = 0;
		fclose(iniFile);
		iniFile = NULL;
 
		//// Look for "[PCI Labeler]"
		if (!FindString("[PCI Labeler]\0",iniText)) {
			fail = true;
		} else {
			// Return what is after "ShareName="
			sprintf(shareName,"%s",ReturnString("ShareName=\0",iniText));
			sprintf(countFile,"%s",ReturnString("CountFile=\0",iniText));
			sprintf(printerName,"%s",ReturnString("PrinterName=\0",iniText));
			sprintf(tempText,"%s",ReturnString("AppNumber=\0",iniText));
			appNumber = atoi(tempText);
		}
		free(iniText);
		iniText = NULL;
	} else {
		fail = true;
	}
	return(fail);
}
 
 
// FindString Function -------------------------------------------//
// PRE: toFind is a character array that contains text that one
//		wants tosearch for, either NULL or EOF terminated.
//		toLook is a character array that contains the text that
//		one wants to look through, either NULL or EOF terminated.
// PST: If the string is found true is returned, else false.
// ---------------------------------------------------------------//
bool ZebraPrinter::FindString (char toFind[], char toLook[]) {
	char tempText[TEXT_SIZE];
	char endChar;
	bool foundtxt = false;
	int stringLength;
	int i = 0, j = 0, k = 0;
 
	stringLength = strlen(toFind);
 
	// String is not too large
	if (stringLength < TEXT_SIZE) {
		// Figure out what the last character is
		while ((toFind[i] != EOF) && (toFind[i] != '\0')) {
			endChar = toFind[i++];
		}
		if (i > 0) {
			endChar = toFind[i-1];
		}
		i = 0;
		// Look for the character string
		while ((toLook[i] != EOF) && (toLook[i] != '\0') && !foundtxt) {
			if (toLook[i] == toFind[0]) {
				j = i;
				k = 0;
				while ((toLook[j] != EOF) && (toLook[j] != endChar) && (k < stringLength)) {
					tempText[k++] = toLook[j++];
					tempText[k] = '\0';
				}
				// Add the last character if there's still room
				if (toLook[j] != EOF) {
					tempText[k++] = toLook[j++];
					tempText[k] = '\0';
				}
				if (!StrCompare(tempText,toFind)) {
					foundtxt = true;
				}
			}
			i++;
		}
	}
	return foundtxt;
}
 
// ReturnString Procedure ----------------------------------------//
// PRE: 
// PST: 
// ---------------------------------------------------------------//
char* ZebraPrinter::ReturnString (char toFind[], char toLook[]) {
	static char tempText[TEXT_SIZE];
	char endChar;
	bool foundtxt = false;
	int i = 0, j = 0, k = 0, l = 0;
	
 
	// Figure out what the last character is
	while ((toFind[i] != EOF) && (toFind[i] != '\0')) {
		endChar = toFind[i++];
	}
	if (i > 0) {
		endChar = toFind[i-1];
	}
 
	i = 0;
	// Look for the character string
	while ((toLook[i] != EOF) && (toLook[i] != '\0') && !foundtxt) {
		if (toLook[i] == toFind[0]) {
			j = i;
			k = 0;
			while ((toLook[j] != EOF) && (toLook[j] != endChar) && (k < TEXT_SIZE)) {
				tempText[k++] = toLook[j++];
				tempText[k] = '\0';
			}
			// Add the last character if there's still room
			if (toLook[j] != EOF) {
				tempText[k++] = toLook[j++];
				tempText[k] = '\0';
			}
			if (!StrCompare(tempText,toFind)) {
				foundtxt = true;
				l = 0;
				while ((toLook[j] != EOF) && (toLook[j] != '\n') && (l < TEXT_SIZE)) {
					tempText[l++] = toLook[j++];
					tempText[l] = '\0';
				}
			}
		}
		i++;
	}
 
	return(tempText);
}
 
// StrCompare Function -------------------------------------------//
// PRE: Both character arrays exist and are null terminated
// PST: If Str1 is greater than Str2, a 1 is returned
//			If Str1 is less than Str2, a -1 is returned
//			If they are equal, a 0 is returned
// ---------------------------------------------------------------//
int ZebraPrinter::StrCompare(char Str1[], char Str2[]) {
	int i = 0;
 
	while (Str1[i] != '\0' && Str2[i] != '\0') {
		if (Str1[i] > Str2 [i]) {
			return 1;
		} else if (Str1[i] < Str2 [i]) {
			return -1;
		}
		i++;
	}
	return 0;
}
 
// NumLines Procedure --------------------------------------------//
int ZebraPrinter::AppNumber(){
	return(appNumber);
}

Open in new window

0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760150

---------------------------------
pciElectric.h
---------------------------------
 
#include "ZebraPrinter.h"
 
//Define Rockwell-Friendly string structure
struct RA_STRING
{
	unsigned long Len;
	char  Data[82];
};
 
---------------------------------
pciElectric.cpp
---------------------------------
 
#include "stdafx.h"
#include "pciElectric.h"
#include "RA_ExternalRoutines.h"					//Include file for External Routine interface
 
#pragma warning(disable : 4996)						//Disable security deprecation warnings
 
#define L_ARRAY_SIZE 64
#define M_ARRAY_SIZE 32
#define S_ARRAY_SIZE 16
 
// ---------------------------------------------------------------//
// Defines the entry point for the DLL application.
// ---------------------------------------------------------------//
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  switch (ul_reason_for_call) {
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;
}
 
//Function prototypes
int getCount(char sFQN[]);
char* PalletCreate(char lineFName[],char palletCode[], char timeBuffer[]);
char* ReceivePallet(char lineFName[],char palletCode[], char timeBuffer[]);
 
 
// ---------------------------------------------------------------//
// This function takes the given line number, searches the [sharename]\In\ 
// directory for that line's .DAT & .TRG files.  Once those files are found, 
// the function reads in the data and creates 4 files: labeler.prn, 
// labelSpool.DAT, PLLTCREATE*.DAT, and PLLTCREATE*.TRG.  Finally, the 
// function enters the current pallet's unique pallet ID into the string 
// reference it was given by SoftLogix.
//
// @param	pERCtrl			JXR control structure which relays the status of 
//							the ladder program
// @param	LineNumber		Line number the current pallet came from
// @param	outPalletID		A reference to a string which the ladder program 
//							can access to get the current pallet ID
// ---------------------------------------------------------------//
extern "C" __declspec(dllexport) void ZebraPrint(EXT_ROUTINE_CONTROL* pERCtrl, int LineNumber, RA_STRING* outPalletID)
{
	FILE *plltCreateFile;					//DAT file for ADC to grab
	char fqnCreate[L_ARRAY_SIZE];			//PLLTCREATE*.DAT + path
 
	FILE *spoolerData;						//DAT File for the Spooler to grab
	char fqnSpooler[L_ARRAY_SIZE];			//PLLTCREATE*.TRG + path
 
	FILE *lineFile;							//File which ADC places to activate product (ie. [sharename]\In\Line*.TRG)
	char fqnLine[L_ARRAY_SIZE];				//Line*.TRG + path
 
	FILE *datFile;							//File which ADC places to activate product (ie. [sharename]\In\Line*.DAT)
	char fqnDat[L_ARRAY_SIZE];				//Line*.DAT + path
 
	FILE *prnFile;							//File which points to labelSpool.DAT and printer
	char fqnPrn[L_ARRAY_SIZE];				//labeler.prn + path
 
	int palletCount;						//Pallet count read from [sharename]\Pallet.num
 
	__time64_t ltime;
	struct tm *today;
	char timeBuffer[S_ARRAY_SIZE];			//Current Year (ie. 2007 is 7)
 
	char palletCode[M_ARRAY_SIZE];			//Unique string identifier for a given pallet
	char tempString[L_ARRAY_SIZE];
 
	static ZebraPrinter Zebra;				//Our ZebraPrinter object
	
	BOOL bFail = false;						//Function call has failed
 
	//Start off error-free
	pERCtrl->ctrlWord.ER = 0;  
	pERCtrl->ctrlWord.ErrorCode = 0; 
 
	pERCtrl->ctrlWord.EN = pERCtrl->ctrlWord.EnableIn;
	pERCtrl->ctrlWord.EnableOut = pERCtrl->ctrlWord.EnableIn;
	
	// Number of parameters expected is 2 (exclude ctrl struct*), and
	// Check type of parameters against what is expected
	if(pERCtrl->ctrlWord.NumParams != 2)
		bFail = TRUE;
	else if(pERCtrl->paramDefs[0].paramType != IntegerValue)
		bFail = TRUE;
	else if(pERCtrl->paramDefs[1].paramType != StructureAddress)
		bFail = TRUE;
 
	//Function called correctly, continue
	if(!bFail)
	{
		// If this is its first scan, lets read in the .ini file and configure
		if(pERCtrl->ctrlWord.FirstScan)
		{
			// On error, .Reload returns 1
			if(Zebra.Load()) 
			{
				//Set Error bit to indicate error occurred
				pERCtrl->ctrlWord.ER = 1;  
				pERCtrl->ctrlWord.ErrorCode = 1;  //Problem with ZebraPrinter object
			}
			else
			{
				// Set Error bit to zero if successful.
				pERCtrl->ctrlWord.ER = 0;
			}
 
		}//end FirstScan
 
		// If the rung is enabled work can be done.
		if(pERCtrl->ctrlWord.EnableIn) 
		{
			//Make sure we have a valid line number
			if(LineNumber > 0) 
			{
				//See if line*.trg & line*.dat exist
				sprintf(fqnLine,"%sIn\\line%d.trg",Zebra.shareName,LineNumber);
				sprintf(fqnDat,"%sIn\\line%d.dat",Zebra.shareName,LineNumber);
 
				//Try opening the files
				lineFile = fopen(fqnLine,"r");
				datFile = fopen(fqnDat,"r");
 
				//Check for each file individually to see both got opened
				if( (lineFile != NULL) && (datFile != NULL) )
				{
					//Now that we know we have both there, close this one since it's empty
					fclose(lineFile);
					lineFile = NULL;
 
					//Close datFile
					fclose(datFile);
					datFile = NULL;
 
					//The path\filename for the counter file
					strcpy(tempString,Zebra.shareName);
					strcat(tempString,Zebra.countFile);
 
					//Retrieve count value from the file
					palletCount = getCount(tempString);
 
					//Let's get the time and date
					ltime = time(NULL);
					today = _localtime64(&ltime);
					strftime(timeBuffer, M_ARRAY_SIZE, "%Y%m%d", today);
 
					//Figure out the pallet code
					sprintf(palletCode,"E%c%d%.6d",timeBuffer[3],Zebra.AppNumber(),palletCount);
 
					//Put the palletCode into the palletID string reference
					strcpy(outPalletID->Data, palletCode);
					outPalletID->Len = strlen(palletCode);
 
					//Create the path\filename of the pallet for ADC
					sprintf(fqnCreate,"%sOut\\PLLTCREATE%s.DAT\0",Zebra.shareName,palletCode);
					
					//Create the path\filename of the pallet for Spooler
					sprintf(fqnSpooler,"%sOut\\labelSpool.DAT\0",Zebra.shareName);
 
 
					//*********************************************
					//// PLLTCREAT dat file
					if( (plltCreateFile = fopen(fqnCreate,"w")) == NULL) 
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 2;  //Problem with PLLTCREAT file
 
					}//PLLTCREAT dat can't be created
					else
					{
						//New stuff
						sprintf(fqnLine,"%sIn\\line%d.dat",Zebra.shareName,LineNumber);
						fprintf(plltCreateFile,"%s\n",PalletCreate(fqnLine,palletCode,timeBuffer));
 
						fclose(plltCreateFile);
						plltCreateFile = NULL;
 
						//Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
 
					}//PLLTCREAT dat file can be created
 
 
					//*********************************************
					//// LabelSpoolerData dat file
					if( (spoolerData = fopen(fqnSpooler,"w")) == NULL) 
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 3;  //Problem with labelSpooler.DAT file
 
					}//LabelSpoolerData dat can't be created
					else
					{
						fprintf(spoolerData,"%s\n",PalletCreate(fqnLine,palletCode,timeBuffer));
 
						fclose(spoolerData);
						spoolerData = NULL;
 
						// Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
 
					}//LabelSpoolerData dat file can be created
 
 
					//// Create the file that says there is a file to print
					sprintf(fqnPrn,"%sOut\\labeler.prn",Zebra.shareName);
 
					if( (prnFile = fopen(fqnPrn,"w")) == NULL)
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 4;  //Problem with labeler.prn file
					}
					else
					{
						fprintf(prnFile,"%s\n%s\n",fqnSpooler,Zebra.printerName);
						fclose(prnFile);
						prnFile = NULL;
 
						// Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
					}
 
					sprintf(fqnCreate,"%sOut\\PLLTCREATE%s.TRG\0",Zebra.shareName,palletCode);
 
					//// PLLTCREAT trg file can be opened
					if( (plltCreateFile = fopen(fqnCreate,"w")) == NULL) 
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 5;  //Problem with PLLTCREAT trg file		
					}
					else
					{
						fclose(plltCreateFile);
						plltCreateFile = NULL;
 
						// Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
					}
				}
				//.trg & .dat files are missing
				else
				{
					//makes sure lineFile is closed
					if(lineFile != NULL)
					{
						fclose(lineFile);
						lineFile = NULL;
					}
					//makes sure datFile is closed
					else if(datFile != NULL)
					{
						fclose(datFile);
						datFile = NULL;
					}
				}
 
				//Function call done successfully
				pERCtrl->ctrlWord.DN = 1;
 
			}//LineNumber > 0
		}
		// Rung is not enabled
		else
		{
			pERCtrl->ctrlWord.DN = 0;
 
			//Clear out any old palletIDs from the palletID reference
			memset(outPalletID->Data, 0, sizeof(outPalletID->Data));
			outPalletID->Len = 0;
		}
 
	}//incorrect call
 
}//end ZebraPrint function
 
 
// ---------------------------------------------------------------//
// This function is called at the beginning of the year, resetting
// the pallet count to zero.  It does this by opening 
// [sharename]\pallet.num and replacing any numbers present with a zero.
//
// @param	pERCtrl			JXR control structure which relays the status 
//							of the ladder program
// ---------------------------------------------------------------//
extern "C" __declspec(dllexport) void EraseCount(EXT_ROUTINE_CONTROL* pERCtrl)
{
	FILE *countFile;						//File where pallet count is kept (ie. [sharename]\pallet.num)
	char fileName[L_ARRAY_SIZE];			//Pallet.num path
 
	static ZebraPrinter Zebra;				//Our ZebraPrinter object
	
	BOOL bFail = false;						//Whether or not the function call has failed
 
	//Start off error-free
	pERCtrl->ctrlWord.ER = 0;  
	pERCtrl->ctrlWord.ErrorCode = 0; 
 
	pERCtrl->ctrlWord.EN = pERCtrl->ctrlWord.EnableIn;
	pERCtrl->ctrlWord.EnableOut = pERCtrl->ctrlWord.EnableIn;
	
	//Make sure we aren't getting passed any parameters (exclude ctrl struct*)
	if(pERCtrl->ctrlWord.NumParams != 0)
		bFail = TRUE;
 
	//Function called correctly
	if(!bFail)
	{
		// If the rung is enabled work can be done.
		if (pERCtrl->ctrlWord.EnableIn)
		{
			// On error, .Reload returns 1
			if (Zebra.Load()) 
			{
				//Set Error bit to indicate error occurred
				pERCtrl->ctrlWord.ER = 1;  
				pERCtrl->ctrlWord.ErrorCode = 1;  //Problem with .ini file
			}
			else
			{
				// Set Error bit to zero if successful.
				pERCtrl->ctrlWord.ER = 0;
			}
 
			//Assemble the path to the pallet.num file
			sprintf(fileName,"%s%s\0",Zebra.shareName,Zebra.countFile);
			countFile = fopen(fileName,"w");
 
			//pallet.num file successfully opened
			if(countFile != 0)
			{
				fprintf(countFile,"0");
				fclose(countFile);
				countFile = NULL;
 
				// Set Error bit to zero if successful.
				pERCtrl->ctrlWord.ER = 0;
			}
			//Unable to open pallet.num file
			else 
			{
				//Set Error bit to indicate error occurred
				pERCtrl->ctrlWord.ER = 1;  
				pERCtrl->ctrlWord.ErrorCode = 6;  //Problem with pallet.num file
			}
 
			//Function call done successfully
			pERCtrl->ctrlWord.DN = 1;
		}
		//Rung not enabled
		else
		{
			//Reset the JXR's done bit
			pERCtrl->ctrlWord.DN = 0;
		}
 
	}//function called incorrectly
 
}//end EraseCount function
 
 
// ---------------------------------------------------------------//
// This function takes the given line number and pallet ID and generates
// 2 files: PLLTRCPT*.DAT and PLLTRCPT*.TRG. These are taken in by ADC to
// fully receive the new pallet into the system.
//
// @param	pERCtrl			JXR control structure which relays the status of 
//							the ladder program
// @param	LineNumber		Line number the current pallet came from
// @param	inPalletID		A reference to a string which the ladder program 
//							can access to get the current pallet ID
// ---------------------------------------------------------------//
extern "C" __declspec(dllexport) void RecPallet(EXT_ROUTINE_CONTROL* pERCtrl, int LineNumber, RA_STRING* inPalletID)
{
	static ZebraPrinter Zebra;				//Our ZebraPrinter object
	
	BOOL bFail = false;						//Function call has failed
 
	FILE *lineFile;							//File which ADC places to activate product (ie. [sharename]\In\Line*.TRG)
	char fqnLine[L_ARRAY_SIZE];				//Line*.TRG + path
 
	FILE *datFile;							//File which ADC places to activate product (ie. [sharename]\In\Line*.DAT)
	char fqnDat[L_ARRAY_SIZE];				//Line*.DAT + path
 
	FILE *plltReceiptFile;					//DAT file for ADC to grab
	char fqnReceipt[L_ARRAY_SIZE];			//PLLTCREATE*.DAT + path
 
	__time64_t ltime;
	struct tm *today;
	char timeBuffer[S_ARRAY_SIZE];			//Current Year (ie. 2007 is 7)
 
	//Start off error free
	pERCtrl->ctrlWord.ER = 0;  
	pERCtrl->ctrlWord.ErrorCode = 0; 
 
	pERCtrl->ctrlWord.EN = pERCtrl->ctrlWord.EnableIn;
	pERCtrl->ctrlWord.EnableOut = pERCtrl->ctrlWord.EnableIn;
	
	// Number of parameters expected is 2 (exclude ctrl struct*), and
	// Check type of parameters against what is expected
	if(pERCtrl->ctrlWord.NumParams != 2)
		bFail = TRUE;
	else if(pERCtrl->paramDefs[0].paramType != IntegerValue)
		bFail = TRUE;
	else if(pERCtrl->paramDefs[1].paramType != StructureAddress)
		bFail = TRUE;
 
	//Function called correctly, continue
	if(!bFail)
	{
		// If this is its first scan, lets read in the .ini file and configure
		if(pERCtrl->ctrlWord.FirstScan)
		{
			// On error, .Reload returns 1
			if(Zebra.Load()) 
			{
				//Set Error bit to indicate error occurred
				pERCtrl->ctrlWord.ER = 1;  
				pERCtrl->ctrlWord.ErrorCode = 1;  //Problem with ZebraPrinter object
			}
			else
			{
				// Set Error bit to zero if successful.
				pERCtrl->ctrlWord.ER = 0;
			}
 
		}//end FirstScan
 
		// If the rung is enabled work can be done.
		if(pERCtrl->ctrlWord.EnableIn) 
		{
			//Make sure we have a valid line number
			if(LineNumber > 0) 
			{
				//See if line*.trg & line*.dat have been created by ADC
				sprintf(fqnLine,"%sIn\\LINE%d.TRG", Zebra.shareName, LineNumber);
				sprintf(fqnDat,"%sIn\\LINE%d.DAT", Zebra.shareName, LineNumber);
 
				//Try opening the files
				lineFile = fopen(fqnLine,"r");
				datFile = fopen(fqnDat,"r");
 
				//Check for each file individually to see that both got opened
				if( (lineFile != NULL) && (datFile != NULL) )
				{
					//Now that we know we have both there, close them
					fclose(lineFile);
					lineFile = NULL;
 
					fclose(datFile);
					datFile = NULL;
 
					//Let's get the time and date
					ltime = time(NULL);
					today = _localtime64(&ltime);
					strftime(timeBuffer, M_ARRAY_SIZE, "%Y%m%d", today);	
 
					//**********************************************
					//Create the PLLTRCPT*.TRG for ADC
					sprintf(fqnReceipt,"%sOut\\PLLTRCPT%s.TRG\0", Zebra.shareName, inPalletID->Data);
 
					//// PLLTRCPT trg file can be opened
					if( (plltReceiptFile = fopen(fqnReceipt,"w")) == NULL) 
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 7;  //Problem with PLLTRCPT trg file		
					}
					else
					{
						//Close it since it will be empty
						fclose(plltReceiptFile);
						plltReceiptFile = NULL;
 
						//Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
					}
 
					//**********************************************
					//Create the PLLTRCPT*.DAT for ADC
					sprintf(fqnReceipt,"%sOut\\PLLTRCPT%s.DAT\0", Zebra.shareName, inPalletID->Data);
 
					////Try to open the PLLTRCPT dat file
					if( (plltReceiptFile = fopen(fqnReceipt,"w")) == NULL) 
					{
						//Set Error bit to indicate error occurred
						pERCtrl->ctrlWord.ER = 1;  
						pERCtrl->ctrlWord.ErrorCode = 8;  //Problem with PLLTRCPT dat file
					}
					//PLLTRCPT dat file can be created
					else
					{
						//New stuff
						sprintf(fqnLine,"%sIn\\LINE%d.DAT", Zebra.shareName, LineNumber);
						fprintf(plltReceiptFile,"%s\n",ReceivePallet(fqnLine, inPalletID->Data, timeBuffer));
 
						fclose(plltReceiptFile);
						plltReceiptFile = NULL;
 
						//Set Error bit to zero if successful.
						pERCtrl->ctrlWord.ER = 0;
					}
 
				}//.trg and/or .dat files are missing
				else
				{
					//makes sure lineFile is closed
					if(lineFile != NULL)
					{
						fclose(lineFile);
						lineFile = NULL;
					}
					//makes sure datFile is closed
					else if(datFile != NULL)
					{
						fclose(datFile);
						datFile = NULL;
					}
				}
 
				//Function call done successfully
				pERCtrl->ctrlWord.DN = 1;
 
			}//LineNumber > 0
		}
		// Rung is not enabled
		else
		{
			pERCtrl->ctrlWord.DN = 0;
 
			//Clear out any old palletIDs from the palletID reference
			//memset(outPalletID->Data, 0, sizeof(outPalletID->Data));
			//outPalletID->Len = 0;
		}
 
	}//incorrect call
	
}//end RecPallet function
 
 
// ---------------------------------------------------------------//
// This function takes a data file path, pallet code, and time buffer 
// and formats all of it to a string, which is stored in a specific format,
// that the label spooler and ADC can understand to create a pallet in the
// system.
//
// @param	lineFName[]		Path\Filename to the product activation data 
//							provided by ADC
// @param	palletCode[]	The current pallet's unique identifier code
// @param	timeBuffer[]	The current year (ie. 7 for 2007)
// @return	char*			The formatted string data for the label .DAT files
// ---------------------------------------------------------------//
char* PalletCreate(char lineFName[],char palletCode[], char timeBuffer[])
{
	static char *fileText;
	FILE *lineFile;
 
	char fieldText[S_ARRAY_SIZE][M_ARRAY_SIZE];
 
	int fileSize, i, j, k;
 
	//Try to open line file
	lineFile = fopen(lineFName,"r");
 
	//Able to successfully open lineFile
	if (lineFile != 0) 
	{
		// Get filesize
		fseek(lineFile,0,SEEK_END);
		fileSize = ftell(lineFile)-1;
 
		// Rewind file pointer
		rewind(lineFile);
 
		if( (fileText = (char *)malloc( fileSize+1 * sizeof( char ) + S_ARRAY_SIZE )) == NULL ) 
		{
			return(0);
		} 
		else 
		{
			// Read the file into the array
			for(i=0;i<=fileSize;i++) 
			{
				fileText[i] = fgetc(lineFile);
				if((fileText[i] == EOF) || (fileText[i] == '\0')) 
				{
					break;
				}
 
			}//end for
 
			//Terminate the file text
			fileText[i] = '\0';
 
			//Close up lineFile
			fclose(lineFile);
			lineFile = NULL;
 
			i = 0;
			j = 0;
 
			// Parse the file
			do 
			{
				for(k=0;k<M_ARRAY_SIZE;k++)
				{
					//Tests for Line Feed or Asterisk
					if((fileText[i] == 10) || (fileText[i] == '*'))
					{
						fieldText[j][k] = '\0';
						break;
					}
 
					fieldText[j][k] = fileText[i++];
 
					if((fileText[i] == ' ') && (fileText[i+1] == ' '))
					{
						fieldText[j][k] = '\0';
						break;
					}
 
				}//end for
 
				j++;
 
			}while((fileText[i++] != EOF) && (j < S_ARRAY_SIZE));
 
			//Reached EOF, format the results
			sprintf(fileText,"%s*%s*%s*PLLTCREATE*%s\n%s*PC*%s*%s*%s*%s***%s*%s\n",fieldText[0],timeBuffer,fieldText[2],fieldText[4],fieldText[7],fieldText[9],fieldText[10],fieldText[11],fieldText[14],fieldText[15],palletCode);
		}
	}
 
	//Return the formatted string results
	return(fileText);
 
}//end PalletCreate function
 
 
// ---------------------------------------------------------------//
// This function takes a data file path, pallet code, and time buffer 
// and formats all of it into a string, which is stored in a specific 
// format that ADC can understand to receive a pallet fully into the 
// system.
//
// @param	lineFName[]		Path\Filename to the product activation data 
//							provided by ADC
// @param	palletCode[]	The current pallet's unique identifier code
// @param	timeBuffer[]	The current year (ie. 7 for 2007)
// @return	char*			The formatted string data for the PLLTRCPT*.DAT file
// ---------------------------------------------------------------//
char* ReceivePallet(char lineFName[],char palletCode[], char timeBuffer[])
{
	static char *fileText;
	FILE *lineFile;
 
	char fieldText[S_ARRAY_SIZE][M_ARRAY_SIZE];
 
	int fileSize, i, j, k;
 
	//Try to open line file
	lineFile = fopen(lineFName,"r");
 
	//Able to successfully open lineFile
	if (lineFile != 0) 
	{
		// Get filesize
		fseek(lineFile,0,SEEK_END);
		fileSize = ftell(lineFile)-1;
 
		// Rewind file pointer
		rewind(lineFile);
 
		if( (fileText = (char *)malloc( fileSize+1 * sizeof( char ) + S_ARRAY_SIZE )) == NULL ) 
		{
			return(0);
		} 
		else 
		{
			// Read the file into the array
			for(i=0;i<=fileSize;i++) 
			{
				fileText[i] = fgetc(lineFile);
				if((fileText[i] == EOF) || (fileText[i] == '\0')) 
				{
					break;
				}
 
			}//end for
 
			//Terminate the file text
			fileText[i] = '\0';
 
			//Close up lineFile
			fclose(lineFile);
			lineFile = NULL;
 
			i = 0;
			j = 0;
 
			// Parse the file
			do 
			{
				for(k=0;k<M_ARRAY_SIZE;k++)
				{
					//Tests for Line Feed or Asterisk
					if((fileText[i] == 10) || (fileText[i] == '*'))
					{
						fieldText[j][k] = '\0';
						break;
					}
 
					fieldText[j][k] = fileText[i++];
 
					if((fileText[i] == ' ') && (fileText[i+1] == ' '))
					{
						fieldText[j][k] = '\0';
						break;
					}
 
				}//end for
 
				j++;
 
			}while((fileText[i++] != EOF) && (j < S_ARRAY_SIZE));
 
			//Reached EOF, format the results
			sprintf(fileText,"%s*%s*%s*PLLTRCPT*%s\n", fieldText[0], timeBuffer, palletCode, fieldText[4]);
		}
	}
 
	//Return the formatted string results
	return(fileText);
 
}//end ReceivePallet function
 
 
// ---------------------------------------------------------------//
// The value within the file passed as a variable is returned incremented 
// by 1. The value within the file is also incremented.
//
// @param	sFQN[]		The file holding the current count information 
//						(ie. [sharename]\Pallet.num)
// @return	int			The new pallet count
// ---------------------------------------------------------------//
int getCount(char sFQN[]){
 
	FILE *countFile;
	char iText[S_ARRAY_SIZE];
 
	//Start at a base count of zero
	int myCount = 0;
	int i = 0;
 
	//Try to open up the count file
	countFile = fopen(sFQN,"r");
 
	//If the file exists, read what's there and increment by 1
	if (countFile != 0)
	{
		//Read in up to 10 characters from the file
		for(i=0;i<10;i++)
		{
			//Read in a character
			iText[i] = fgetc(countFile);
 
			//Search for EOF or a carriage return
			if((iText[i] == EOF) || (iText[i] == '\n'))
			{
				break;
			}
 
		}//end for
 
		//Close up the count file
		fclose(countFile);
		countFile = NULL;
 
		//Convert ASCII character to number equivalent and increment by 1
		myCount = atoi(iText) + 1;
	}
 
	//Open up the coutn file for writing, and write the new count number
	countFile = fopen(sFQN,"w");
	fprintf(countFile,"%d",myCount);
 
	//Close the count file
	fclose(countFile);
	countFile = NULL;
 
	//Return the new count
	return (myCount);
 
}//end getCount

Open in new window

0
 
LVL 40

Expert Comment

by:evilrix
ID: 20760184
>> then the MS Server 2003 server crashes giving a stop error
Can you post the crash dump, if any, that is generated. That will tell me heap loads more than the source code :)
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760219
I have the memory dump file, but it is 20.5mb zipped, and it looks like the file size limit on ee stuff is 2mb.  I'll give it a try and see if it uploads.  Sorry if this angers the EE gods...
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760339
Ok, it looked like it didn't upload.  Is there any other easy way to get the dump file to you guys?

--Charly
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760640
I don't know if this is helpful, but this is the stop error we are getting when the machine reboots:

Error code 00000050, parameter1 8b55ff8f, parameter2 00000000, parameter3 f7659eef, parameter4 00000000.

I am also uploading the dump file to a file sharing website so I should be able to link that shortly.

--Charly
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760728
Here is a link to the relevant dump file:

http://www.4shared.com/account/file/36202785/e698b12e/1-25-08_Dump_File.html?sId=5dQ3frF2s7mMFLnd

Let me know if it doesn't work.  Thanks again for the help.

--Charly
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20760815
Here is another spreadsheet which was assembled by Server 2003's system log files:

http://www.4shared.com/account/file/36203493/ac1afc66/Server_Log_Files.html?sId=5dQ3frF2s7mMFLnd

--Charly
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20760855
>> I have the memory dump file, but it is 20.5mb zipped, and it looks like the file size limit on ee stuff is 2mb
A mini-dump will be fine :)
http://support.microsoft.com/kb/315263

>>Error code 00000050, parameter1 8b55ff8f, parameter2 00000000, parameter3 f7659eef, parameter4 00000000.
Looks like it is PAGE_FAULT_IN_NONPAGED_AREA
http://msdn2.microsoft.com/en-us/library/ms841534.aspx
http://msdn2.microsoft.com/en-us/library/ms793437.aspx
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20761339
I don't have access to the server in question right now as I am offsite, but I think I have this file sharing site set up right now.

Dump File:
http://www.4shared.com/file/36202785/e698b12e/1-25-08_Dump_File.html

The password is "ee"

--Charly
0
 
LVL 40

Accepted Solution

by:
evilrix earned 2000 total points
ID: 20761565
Ok, this seems to be a driver related problem. The faulting module is VirtualBackplane.sys, which is loaded in to the process space of Ethernet_IP_IO.exe. Google suggests this is a driver for a SoftLogix5800 Controller.

http://www.ab.com/en/epub/catalogs/12762/2181376/2416247/1239772/2185363/

If you know what this device is I'd suggest you download the latest drivers for this device and see if it fixes the issue.

The full BugCheck report is below.

-Rx.

*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************
 
PAGE_FAULT_IN_NONPAGED_AREA (50)
Invalid system memory was referenced.  This cannot be protected by try-except,
it must be protected by a Probe.  Typically the address is just plain bad or it
is pointing at freed memory.
Arguments:
Arg1: 8b55ff8f, memory referenced.
Arg2: 00000000, value 0 = read operation, 1 = write operation.
Arg3: ba70ceef, If non-zero, the instruction address which referenced the bad memory
	address.
Arg4: 00000000, (reserved)
 
Debugging Details:
------------------
 
*** ERROR: Module load completed but symbols could not be loaded for VirtualBackplane.sys
Page 78505 not present in the dump file. Type ".hh dbgerr004" for details
Page 7860b not present in the dump file. Type ".hh dbgerr004" for details
 
PEB is paged out (Peb.Ldr = 7ffd500c).  Type ".hh dbgerr001" for details
 
PEB is paged out (Peb.Ldr = 7ffd500c).  Type ".hh dbgerr001" for details
 
READ_ADDRESS:  8b55ff8f 
 
FAULTING_IP: 
VirtualBackplane+2eef
ba70ceef 035104          add     edx,dword ptr [ecx+4]
 
MM_INTERNAL_CODE:  0
 
IMAGE_NAME:  VirtualBackplane.sys
 
DEBUG_FLR_IMAGE_TIMESTAMP:  46c061b5
 
MODULE_NAME: VirtualBackplane
 
FAULTING_MODULE: ba70a000 VirtualBackplane
 
DEFAULT_BUCKET_ID:  DRIVER_FAULT
 
BUGCHECK_STR:  0x50
 
PROCESS_NAME:  EtherNet_IP_IO.
 
CURRENT_IRQL:  1
 
TRAP_FRAME:  b955eae8 -- (.trap 0xffffffffb955eae8)
ErrCode = 00000000
eax=77e6ba30 ebx=8991c1dc ecx=8b55ff8b edx=7efb0418 esi=89e2bb58 edi=8991c030
eip=ba70ceef esp=b955eb5c ebp=b955ec24 iopl=0         nv up ei ng nz na pe nc
cs=0008  ss=0010  ds=0023  es=0023  fs=0030  gs=0000             efl=00010286
VirtualBackplane+0x2eef:
ba70ceef 035104          add     edx,dword ptr [ecx+4] ds:0023:8b55ff8f=????????
Resetting default scope
 
LAST_CONTROL_TRANSFER:  from 808689ee to 8087b6be
 
STACK_TEXT:  
b955ea80 808689ee 00000050 8b55ff8f 00000000 nt!KeBugCheckEx+0x1b
b955ead0 80837d0a 00000000 8b55ff8f 00000000 nt!MmAccessFault+0x813
b955ead0 ba70ceef 00000000 8b55ff8f 00000000 nt!KiTrap0E+0xdc
WARNING: Stack unwind information not available. Following frames may be wrong.
b955ec24 ba70ad6b 003a9040 00000005 01a0fecc VirtualBackplane+0x2eef
b955ec58 8092e6a2 89e2bb58 00000001 003a9040 VirtualBackplane+0xd6b
b955ed00 80940844 00000334 00000000 00000000 nt!IopXxxControlFile+0x255
b955ed34 80834d3f 00000334 00000000 00000000 nt!NtDeviceIoControlFile+0x2a
b955ed34 7c82ed54 00000334 00000000 00000000 nt!KiFastCallEntry+0xfc
01a0fe58 00000000 00000000 00000000 00000000 0x7c82ed54
 
 
STACK_COMMAND:  kb
 
FOLLOWUP_IP: 
VirtualBackplane+2eef
ba70ceef 035104          add     edx,dword ptr [ecx+4]
 
SYMBOL_STACK_INDEX:  3
 
SYMBOL_NAME:  VirtualBackplane+2eef
 
FOLLOWUP_NAME:  MachineOwner
 
FAILURE_BUCKET_ID:  0x50_VirtualBackplane+2eef
 
BUCKET_ID:  0x50_VirtualBackplane+2eef
 
Followup: MachineOwner
---------

Open in new window

0
 
LVL 40

Expert Comment

by:evilrix
ID: 20761662
Additonal...

A Stop Error is caused due to an unhandled exception in the OS kernel. Because it is unhandled the OS doesn't know what to do so it just stops (great eh?). Unless your code is running in kernel space (unless you have specifically written it to do so, such as a system driver, it'll run in user space) it is unlikely to be your code causing the problem... at least not directly. It is conceivable that indirectly it may be the cause. For example, if it is leaking memory it might be using up system resources and as such the kernel level process is crashing. This should be considered a defect in the driver that has crashed as much as in your code since it should gracefully handle this and not just BSOD.

http://en.wikipedia.org/wiki/User_mode

Some additional info that may help you: -
http://www.microsoft.com/downloads/details.aspx?familyid=859637b4-85f1-4215-b7d0-25f32057921c&displaylang=en
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20763135
Thank you so much evilrix.  That helps me out a lot.  Yeah, SoftLogix5800 is the 3rd party software application I was referring to earlier.  If it ever your way, stay far FAR away.

Could you elaborate a little as to how you came to that conclusion?  Forgive my ignorance, but how did you generate that bugcheck report?  I'm going to have to explain to other how I was able to arrive at this conclusion.

Thanks again for all the help.  I wish I could buy you a beer or something... :)

--Charly
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20763175
Ok, the BugCheck report was generated using WinDBG.
http://en.wikipedia.org/wiki/WinDbg

It can be used to analyze crash dumps and product BugCheck reports (as you can see above). The BugCheck reason is at the top from line 7 (PAGE_FAULT_IN_NONPAGED_AREA (50)).  The line "IMAGE_NAME:  VirtualBackplane.sys" tells me it is a driver (.sys) and "PROCESS_NAME:  EtherNet_IP_IO." tells me the process space the driver is running in. The rest I figured out from Google :)

Does that help?
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20763256
>> I'm going to have to explain to other how I was able to arrive at this conclusion.
Incidentally, there is no reason you can't point them to this thread.
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20763336
Yep, that helps me out a lot, and yes I was thinking the same thing.  Thanks for such a complete answer.

--Charly
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20763344
Very welcome.

-Rx.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20766126
Did you need any more help on this Charly?
0
 
LVL 1

Author Comment

by:dleehanson
ID: 20767906
Nope, I just got busy doing other things yesterday and forgot to close out this question.  Thanks again!

--Charly
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20767930
Anytime Charly.

-Rx
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question