Hello

i use 1 thread in mysource for get data,... ,but sometimes i get wrong data
it is more when i twiddle with my software windows(i mean compile file)

i think this is a synchronization problem

how fix this problem ?

thnx for my help!


somecode i use
Code:
void _stdcall dll_callback(unsigend char*d ,int l)
{
   if(d[0]==0x19){
       PostThreadMessage( m_ThreadId ,DATA_MESSAGE_1 ,(WPARAM)d ,l);

   }

   if(d[1]==0x20){
      PostThreadMessage( m_ThreadId ,DATA_MESSAGE_2 ,(WPARAM)d  ,l);
   }
}


DWORD Receive_Data(/* int id */)
{
    CSingleLock Lock(&c_s);
    
    while( 1 )
    {
          MSG  msg;
          if(GetMessage(&msg ,NULL ,0 ,0 ))
		  {
                  Lock.Lock();
			unsigned char *BUF=(unsigned char *)msg.wParam;
			switch(msg.message)
			{
			  case DATA_MESSAGE_1 :
				  dump("Data1:" ,BUF ,msg.lParam);
			  break;


			  case DATA_MESSAGE_2 :
				  dump("Data2:" ,BUF ,msg.lParam);
			  break;
			}
                 Lock.Unlock();
		}
    }
    return 0;
}

int Thread_Init()
{

m_hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) Receive_Data ,(void*)0 ,NULL ,&m_ThreadId;
if(!m_hThread){
log("!CreateThread\n");
	 return false ;
}

return true;
}