Thread: Odd declaration

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Perhaps you're debugging an old version of the program? If the source file is more recent than the executable, it will often tell you the wrong line numbers.

    Also, if you have optimisation enabled, it will do strange things, jumping around between random-seeming lines.

    Of course, you're probably familiar with both of these points, but I can't think of anything else at the moment. Perhaps you might want to post a bit more code, or better yet a debugger session (if you're using a command-line debugger).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    34
    Yeah, I tried rebuilding and different optimizations and neither worked.

    Code:
    PortThread[3]= AfxBeginThread(StartCryptoPortThread, &Port[3],THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
    
    UINT C_Control::StartCryptoPortThread( LPVOID pParam )
    {
    	char*	buffer;
    	int		size = 0;
        C_RS_422_Port* pObject = ( C_RS_422_Port*)pParam;
    
        if (pObject == NULL )
    		return 1;   // if pObject is not valid
    	else
    	{
    		//C_Control::GetOutboundMessage(buffer,size);
    		
    		pObject->Send_Crypto_Key_1();    // do something with 'pObject'
    
    		return 0;   // thread completed successfully
    	}
    }
    
    void Crypto_Dlg::OnBnClickedCryptoPortAct()
    {
    	CString  sString;
    	CButton* pButton;
    	const bool Active = TRUE;
    
    	pButton = (CButton*)GetDlgItem(IDC_Crypto_Port_Act);
    	pButton->GetState();
    	if (pButton->GetCheck())
    	{
    		pButton->SetCheck(0);
    		pButton->SetState(0);
    		GetDlgItemText(IDC_Crypto_Port_Act,sString);
    		if (!sString.Compare("Activate"))
    		{			
    			Executive.Set_Activate(3, Active);
    			SetDlgItemText(IDC_Crypto_Port_Act,"Deactivate");
    		}
    		else
    		{
    			Executive.Set_Activate(3,!Active);
    			SetDlgItemText(IDC_Crypto_Port_Act,"Activate");
    		}
    		m_b_Crypto_Port_Act = TRUE;
    	}
    
    	if (m_b_Crypto_Port_Act)
    	{
    		Executive.On_Crypto_Apply_Event();
    		m_b_Crypto_Port_Act = FALSE;
    	}
    	
    	if(!Executive.b_Port_Open[3] && ((CButton* )GetDlgItem(IDC_Crypto_Port_Act))->GetCheck()  )
    	{
    		Executive.OpenPort(3, m_Port_Number);
    	}
    
    //	UpdateData(TRUE);
    //	UpdateWindow();
    }
    
    void C_Control::On_Crypto_Apply_Event()
    {
    	// this function controls the thread starting and stopping.
    	// the threads are synchronized on a start and a stop event.
    	// the thread functions that this functions controls are 
    	// those that write data to the ports and to the log files
    	
    
    	
    		// if port is currently inactive - start and set timing
    		if (!b_Port_Status[3])
    		{
    			goto startports;
    		}
    
    		else // port already active
    		{
    			Activate_Crypto_Port(4, FALSE);
    			goto startports;
    		}
    		startports: 
    		Activate_Crypto_Port(4, TRUE);
    		Port[3].StartTransmission.SetEvent();
    
    }
    
    bool C_Control::Activate_Crypto_Port(int PortNumber, bool ActiveYN)
    {
    	// this function starts or suspends a port thread depending
    	// on the state  of ActiveYN and opens the log files the first
    	// time a port is activated
    	static int Times_Through[4] = {0,0,0,0};
    	
    	DWORD SuspendCount;
    	if (ActiveYN) //activate
    	{
    		if (Times_Through[PortNumber-1]==0)
    		{
    			// Open the log files only the first time a write event happens
    //	 		Port[PortNumber-1].OpenLogFiles(FileNames[PortNumber-1]);
    			Times_Through[PortNumber-1]=1;
    		}
    
    		SuspendCount=PortThread[PortNumber-1]->ResumeThread();
    		//code based on SuspendCount
    	
    }
    
    UINT C_RS_422_Port::Send_Crypto_Key_1()
    {
    	DWORD aword = ::WaitForMultipleObjects(2,EventHandles,FALSE,INFINITE);
    //more code
    }
    There's all the relevant code without going too overboard. Also, the first time SuspendCount is declared in this section, it will be assigned a valid number.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM