Thread: Help Re-initalizing a Program

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Help Re-initalizing a Program

    I'm converting an executable to a DLL. I've got it to work, but
    it only runs once( when I enter a new value, the old value is
    stuck in memory).

    The code is a little strange. There is an include file that
    declares a structure named chemical:

    Code:
    #define NMLN   120
    #define MFLN    60
    #define SMLN   120
    
    struct chemical {
    	int	seqnum;
    	char	name[NMLN];
    	int	cas;
    	char	molform[MFLN];
    	char	smiles[SMLN];
    	int	proppnt;
    	int	db_loc;
    };

    In addition to that, the main function also delcares chemical:

    Code:
    struct chemical	chem; // one and only chemical for this program */
    I've tried setting the pointers back to \0, but its still not reinitalizing. I believe the problem has to do with reinitalizing the
    chemical structure. I've tried finding information on this, but haven't had any luck. Is there a simple way to handle this?

  2. #2
    Bioport Productions
    Join Date
    Oct 2005
    Posts
    215
    how are you instantiating the struct/class? how are you using it in your program?
    -"What we wish, we readily believe, and what we ourselves think, we imagine others think also."
    PHP Code:
    sadf 

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks for getting back to me. I've been banging my head on this project for a long time.

    I believe its getting instantiated in the include file. However, I'm new to C++ so I'm not sure if I know what I'm talking about. Its probably easiest if I post the code for you to look at.

    Its using CFAPI which is an interface for Coldfusion. pRequest is used for writing/setting variables in a Coldfusion page. I'm passing a string from Coldfusion to the dll named Smiles.



    Here's the include file:
    Code:
    #define NMLN   120
    #define MFLN    60
    #define SMLN   120
    
    struct chemical {
    	int	seqnum;
    	char	name[NMLN];
    	int	cas;
    	char	molform[MFLN];
    	char	smiles[SMLN];
    	int	proppnt;
    	int	db_loc;
    };
    Here's the main function of my DLL:

    Code:
    char ErrorList[1000];	
    char WarningList[125];	
    
    
    	
    
    // ProcessTagRequest.CPP Defines the entry point of the program
    
    
    void ProcessTagRequest( CCFXRequest* pRequest ) 
    
    {
    
         try
         {
            
    		 
    		 ErrorList[0] = '\0'; // Added By Me
    		 WarningList[0] = '\0';// Added By Me
    		
    		
    		 struct chemical	chem; // one and only chemical for this program */
    	
    
    		// prototypes */
    
    		void resmi(char *,int);
    		int setatomgr(struct chemical *);
    		void tcosmi(char *,int);
    
    			
    		char	redone[SMLN+1];
    		char	unique[SMLN+1];
    
    
    		int	result;
    
    		int	i;
    
    
    		// preset strings to zero, since we don't
    		// know where the terminators are going
     		// to occur
    
    		for (i = 0 ; i <= SMLN ; i++) {
    		redone[i] = '\0';
    		unique[i] = '\0';
    		}		 
    
    
    		// Make sure a Smiles attribute was actually passed to the tag
    		if ( pRequest->AttributeExists("Smiles")==FALSE ) {
    		pRequest->ThrowException(
    		"Error in CFX_SmilesParser Tag",
    		"No Smiles attribute specified.");
    		}
    		 
    		// Retrieve attributes passed to the tag          
            LPCSTR lpszSmiles = pRequest->GetAttribute("Smiles") ;
    
    
    		// BEGIN BASIC VALIDATION */
    
    
    		// make sure the attribute value is not empty
    
    		if (strlen(lpszSmiles) == 0) {
    
    			strcat(ErrorList,"Error: Empty Smiles String");
    		}
    
    		else if (strlen(lpszSmiles)> NMLN - 1) {
    			
    			strcat(ErrorList,"Error: The length of the Smiles string is too long");
    
    		}
    
    		else {
    
    
    
    			strcpy(chem.name,lpszSmiles);
    			strcpy(chem.smiles,lpszSmiles);
    			chem.seqnum = 1; /* one and only chemical for this program to process */
    			result = setatomgr(&chem);
    			resmi(redone,SMLN);
    			
    			if (result) {
    			resmi(redone,SMLN);
    			tcosmi(unique,SMLN);
    			}
    		
    			pRequest->SetVariable("unique",unique);
    			
    			pRequest->SetVariable("WarningList",WarningList);
    			
    		
    		}
    
    		pRequest->SetVariable("ErrorList",ErrorList);
    
            // Output optional debug info
            if ( pRequest->Debug() )
            {
               pRequest->WriteDebug( "Debug info..." ) ;
            }
         }
    
         // Catch Cold Fusion exceptions & re-raise them
         catch( CCFXException* e )
         {
              pRequest->ReThrowException( e ) ;
         }
         
         // Catch ALL other exceptions and throw them as 
         // Cold Fusion exceptions (DO NOT REMOVE! -- 
         // this prevents the server from crashing in 
         // case of an unexpected exception)
         catch( ... )
         {
              pRequest->ThrowException( 
                   "Error occurred in tag CFX_SmilesParser",
                   "Unexpected error occurred while processing tag." ) ;
         }
    
    	 
    }
    Last edited by jamez05; 10-20-2005 at 11:56 AM.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    I believe its making its own copy:

    Code:
    int	setatomgr(
    	struct chemical	*chem)
    {
    
    	/* prototypes */
    
    	int	intsmi(char *,struct chemical *,int *);
    	int	chkval();
    	int	chkaro();
    
    	/* local variables */
    
    	int	errpos;
    	int	aok;
    	int	i;
    
    	if (chem->seqnum <= 0) {
    			
    		if (strlen(ErrorList) > 1) {
    		strcat(ErrorList,",");	
    		}				
    				
    		strcat(ErrorList,"Internal error: setatomgr uninitialized chemical! ");	
    		sprintf(ErrorList,"%s%d",ErrorList,chem->seqnum);	
    
    		exit(1);
    	}
    
    	if (chem->seqnum != seqnum) {
    		/* its a new chemical. The global information
    		 * is not yet set up for this chemical (yet)
    		 */
    		aok = intsmi(chem->smiles,chem,&errpos);
    		if (!aok) {
    		
    			if (strlen(ErrorList) > 1) {
    			strcat(ErrorList,",");	
    			}				
    				
    			strcat(ErrorList,"SMILES error detected at position:");	
    									
    			i = errpos - 1; /* pointer always points to next */
    			while (i > 0) {
    			  i--;
    			}
    			strcat(ErrorList,"V");
    			sprintf(ErrorList,"%s%d",ErrorList,chem->smiles);
    			return(0); /* bad return */
    		} /* end, not ok results */
    	} /* if new chemical */
    
    
    	if (nhydro < 0) {
    		/* Implicit hydrogens are not defined yet */
    		aok = chkval();
    		aok &= chkaro();
    		if (!aok) {
    			
    			if (strlen(ErrorList) > 1) {
    			strcat(ErrorList,",");	
    			}				
    				
    			strcat(ErrorList,"Discovered problems in the structure of chemical");				
    			sprintf(ErrorList,"%s%d",ErrorList,chem->seqnum);
    			sprintf(ErrorList,"%s%d",ErrorList,chem->smiles);
    			
    			return(0); /* bad return */
    		}
    	}
    	return(1); /* good return */
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM