Thread: Odd declaration

  1. #31
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    And is that declared as static, like I mentioned weeks ago?

    Did you compare &Port[3] with pParam (again, mentioned ages ago) to see if both addresses are the same?

    Guess not....
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #32
    Registered User
    Join Date
    Jul 2008
    Posts
    34
    Quote Originally Posted by LowlyIntern View Post
    It won't let me get to pObject in the debugger. I don't think thats the problem though, the pre-existing code that I'm trying to replicate and expand upon seems to handle that part just fine.
    I don't see how they wouldn't seeing as how it's a local object, it's declared in the function, and is only used once.

    Quote Originally Posted by LowlyIntern View Post
    If I understand correctly, it seems Salem and Hunter2 are asking the same basic question right now, and the answer is yes,
    >>UINT C_Control::StartCryptoPortThread( LPVOID pParam )
    is declared static. Is that what you were referring to Salem?

  3. #33
    Registered User
    Join Date
    Jul 2008
    Posts
    34
    Hey guys, thanks for all of your help and all, but one of my co-workers figured it out and it's all good now. The error resided in the code

    Code:
    UINT C_RS_422_Port::Send_Crypto_Key(int key)
    {
    	DWORD aword = ::WaitForMultipleObjects(2,EventHandles,FALSE,INFINITE);
    	
    	char Crypto_Key_1[17] = "123456789ABCDEFG";
    	char Crypto_Key_2[17] = "HIJKLMNOPQRSTUVW";
    	char Crypto_Key_Reversed[17];
    	char Crypto_Next_Byte_Confirm;
    	UINT Crypto_Key_Character = 0;
    
    	if(key==1)
    		for (int count=0; count<16; count++)
    		{
    			Crypto_Key_Character += (1 & (UINT) Crypto_Key_1[count]) << 7;
    			Crypto_Key_Character += (2 & (UINT) Crypto_Key_1[count]) << 5;
    			Crypto_Key_Character += (4 & (UINT) Crypto_Key_1[count]) << 3;
    			Crypto_Key_Character += (8 & (UINT) Crypto_Key_1[count]) << 1;
    			Crypto_Key_Character += (16 & (UINT) Crypto_Key_1[count]) >> 1;
    			Crypto_Key_Character += (32 & (UINT) Crypto_Key_1[count]) >> 3;
    			Crypto_Key_Character += (64 & (UINT) Crypto_Key_1[count]) >> 5;
    			Crypto_Key_Character += (128 & (UINT) Crypto_Key_1[count]) >> 7;
    
    			Crypto_Key_Reversed[count] = Crypto_Key_Character;
    			Crypto_Key_Character=0;
    		}
    	else
    		for (int count=0; count<16; count++)
    		{
    			Crypto_Key_Character += (1 & (UINT) Crypto_Key_2[count]) << 7;
    			Crypto_Key_Character += (2 & (UINT) Crypto_Key_2[count]) << 5;
    			Crypto_Key_Character += (4 & (UINT) Crypto_Key_2[count]) << 3;
    			Crypto_Key_Character += (8 & (UINT) Crypto_Key_2[count]) << 1;
    			Crypto_Key_Character += (16 & (UINT) Crypto_Key_2[count]) >> 1;
    			Crypto_Key_Character += (32 & (UINT) Crypto_Key_2[count]) >> 3;
    			Crypto_Key_Character += (64 & (UINT) Crypto_Key_2[count]) >> 5;
    			Crypto_Key_Character += (128 & (UINT) Crypto_Key_2[count]) >> 7;
    
    			Crypto_Key_Reversed[count] = Crypto_Key_Character;
    			Crypto_Key_Character=0;
    		}
    
    	for (int count=0; count<16; count++)
    	{
    		if(b_Crypto_ON)
    		{
    			Send_Bytes(&Crypto_Key_Reversed[count],1);
    			OutByteBufferCryptoReversed[count] = Crypto_Key_Reversed[count];
    			if(key==1)
    			{
    				OutByteBufferCrypto[count] = Crypto_Key_1[count];
    				fprintf(pFile, "%2d \t %6d ", (UINT) Crypto_Key_Reversed[count], (UINT) Crypto_Key_1[count]);
    			}
    			else
    			{
    				OutByteBufferCrypto[count] = Crypto_Key_2[count];
    				fprintf(pFile, "%2d \t %6d ", (UINT) Crypto_Key_Reversed[count], (UINT) Crypto_Key_2[count]);
    			}
    			fprintf(pFile, "\n");
    		}
    		else
    			count = 16;
    	}
    
    	if(Executive.GetLogCrypto())
    	{
    		WriteCryptoTextFile();
    	}
    
    }
    Funnily enough, I posted that function but only included the header and the first declaration, where the problem appeared to be. However it should look like this:

    Code:
    UINT C_RS_422_Port::Send_Crypto_Key(int key)
    {
    	DWORD aword = ::WaitForMultipleObjects(2,EventHandles,FALSE,INFINITE);
    	
    	char Crypto_Key_1[17] = "123456789ABCDEFG";
    	char Crypto_Key_2[17] = "HIJKLMNOPQRSTUVW";
    	char Crypto_Key_Reversed[17];
    	char Crypto_Next_Byte_Confirm;
    	UINT Crypto_Key_Character = 0;
    
    	
    	if(key==1)
    		for (int count=0; count<16; count++)
    		{
    			Crypto_Key_Character += (1 & (UINT) Crypto_Key_1[count]) << 7;
    			Crypto_Key_Character += (2 & (UINT) Crypto_Key_1[count]) << 5;
    			Crypto_Key_Character += (4 & (UINT) Crypto_Key_1[count]) << 3;
    			Crypto_Key_Character += (8 & (UINT) Crypto_Key_1[count]) << 1;
    			Crypto_Key_Character += (16 & (UINT) Crypto_Key_1[count]) >> 1;
    			Crypto_Key_Character += (32 & (UINT) Crypto_Key_1[count]) >> 3;
    			Crypto_Key_Character += (64 & (UINT) Crypto_Key_1[count]) >> 5;
    			Crypto_Key_Character += (128 & (UINT) Crypto_Key_1[count]) >> 7;
    
    			Crypto_Key_Reversed[count] = Crypto_Key_Character;
    			Crypto_Key_Character=0;
    		}
    	else
    		for (int count=0; count<16; count++)
    		{
    			Crypto_Key_Character += (1 & (UINT) Crypto_Key_2[count]) << 7;
    			Crypto_Key_Character += (2 & (UINT) Crypto_Key_2[count]) << 5;
    			Crypto_Key_Character += (4 & (UINT) Crypto_Key_2[count]) << 3;
    			Crypto_Key_Character += (8 & (UINT) Crypto_Key_2[count]) << 1;
    			Crypto_Key_Character += (16 & (UINT) Crypto_Key_2[count]) >> 1;
    			Crypto_Key_Character += (32 & (UINT) Crypto_Key_2[count]) >> 3;
    			Crypto_Key_Character += (64 & (UINT) Crypto_Key_2[count]) >> 5;
    			Crypto_Key_Character += (128 & (UINT) Crypto_Key_2[count]) >> 7;
    
    			Crypto_Key_Reversed[count] = Crypto_Key_Character;
    			Crypto_Key_Character=0;
    		}
    
    	switch (aword)
    	{
    	case 0:	
    		{
    		do{
    		g_CritSec.Lock();
    		for (int count=0; count<16; count++)
    		{
    	//		Read_Bytes(&Crypto_Next_Byte_Confirm,1);
    
    	//		if((b_Crypto_ON) & (Crypto_Next_Byte_Confirm==1))
    			if(b_Crypto_ON)
    			{
    				Send_Bytes(&Crypto_Key_Reversed[count],1);
    				OutByteBufferCryptoReversed[count] = Crypto_Key_Reversed[count];
    				if(key==1)
    				{
    					OutByteBufferCrypto[count] = Crypto_Key_1[count];
    					fprintf(pFile, "%2d \t %6d ", (UINT) Crypto_Key_Reversed[count], (UINT) Crypto_Key_1[count]);
    				}
    				else
    				{
    					OutByteBufferCrypto[count] = Crypto_Key_2[count];
    					fprintf(pFile, "%2d \t %6d ", (UINT) Crypto_Key_Reversed[count], (UINT) Crypto_Key_2[count]);
    				}
    				fprintf(pFile, "\n");
    			}
    			else
    				count = 16;
    		}
    
    		if(Executive.GetLogCrypto())
    		{
    			WriteCryptoTextFile();
    		}
    
    		fprintf(pFile, "\n");
    		}
    		while(true);
    		break;
    		}
    	case 1:
    		{
    			return(0);
    			break;
    		}
    	default:
    		return(0);
    
    	}
    }
    I guess there needs to be that do while true loop to keep the thread going infinitely. Without it, the thread breaks and trying to use it again fails. My bad.

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