Click here to Skip to main content
15,894,646 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: convert UCHAR array to UINT array Pin
Richard MacCutchan29-Jul-10 22:28
mveRichard MacCutchan29-Jul-10 22:28 
QuestionHow to add edit control to CTreeListControl Pin
Sakhalean29-Jul-10 4:00
Sakhalean29-Jul-10 4:00 
AnswerRe: How to add edit control to CTreeListControl Pin
Richard MacCutchan29-Jul-10 5:02
mveRichard MacCutchan29-Jul-10 5:02 
QuestionHow to add Publisher name for an application Pin
Cvaji29-Jul-10 3:46
Cvaji29-Jul-10 3:46 
AnswerRe: How to add Publisher name for an application Pin
Cvaji29-Jul-10 4:10
Cvaji29-Jul-10 4:10 
GeneralRe: How to add Publisher name for an application Pin
Yusuf29-Jul-10 8:57
Yusuf29-Jul-10 8:57 
AnswerRe: How to add Publisher name for an application Pin
Luc Pattyn29-Jul-10 4:12
sitebuilderLuc Pattyn29-Jul-10 4:12 
QuestionClient Connected listbox in vc++ mfc Pin
dilara semerci29-Jul-10 3:30
dilara semerci29-Jul-10 3:30 
Hey guys,
I have a project which connects the TVs(with socket connection) to a computer and saves the log files. I achieve the connection by multithreading but I want to see whether the connection is established or not in the main dialog page that i built in VC++ MFC. Here are my codes:
void CDilaraDlg::OnBnClickedConnect()
{
    int Selected = 0; //number of the servers selected from the list
	
	for(int i=0; i< m_ctlServerList.GetCount();i++)
	{
		if(m_ctlServerList.GetCheck(i) == 1 ) 
		{
			Selected++; 
		}
	}
	//no line is selected:
	if(Selected == 0) 
		AfxMessageBox(L"No Server is Selected!");

	CString *diziPtr= new CString[Selected]; 
    char str[2];
	CString svar;
	for(int i=0; i< m_ctlServerList.GetCount();i++)
	{
		if(m_ctlServerList.GetCheck(i) == 1 ) 
		{
			_itoa_s(i,str,10);
			svar = str;
			*diziPtr = lines[i]+_T(":")+svar+_T("-")+m_savepath;
			++diziPtr;	
		}
	}

	m_fails.ResetContent();
	m_success.ResetContent();
	
	CString abc;
	for(int i=0;i<Selected;i++)
	{  
		--diziPtr; 	
		Client_Thread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ClientThread,(void *)diziPtr,0,&Client_ThreadID);
		
	} 

m_fails and m_success stand for the control variables of two list boxes that i want to write down the succeed and failed connections.
For the multithreading :
DWORD WINAPI ClientThread(void * num)
{   

	signal( SIGINT, &signal_handler );
    signal( SIGTERM,&signal_handler );  
    signal( SIGABRT,&signal_handler );  

	CString ipport= *(CString * ) num;	
    CString ipAddress,savepath;
	CString ports,socknums;
	int port,socknum;
   	
	AfxExtractSubString(ipAddress, ipport, 0, ':'); //first substr upto : is the ip
	AfxExtractSubString(ports, ipport, 1, ':');//second substr after : is the port

    port = _wtoi(ports);

	AfxExtractSubString(socknums, ipport, 2, ':');//third substr after : is the threadno

	AfxExtractSubString(savepath, ipport, 1, '-');//second substr after - is the savepath

    socknum = _wtoi(socknums);
	CStringA ip(ipAddress);
    Socket sockClient(socknum);

	//creating the ip_port.txt file and write the time in it
	sockClient.timefile(ipAddress,ports,savepath);

	if(sockClient.ConnectToServer(ip, port,socknum)==0) 
	return -1;

    sockClient.RecvData(ipAddress,ports,socknum,savepath);

	return 0;
   
}  

in the ConnectToServer function of the Socket, it returns 0 if the connection is not achieved and 1 otherwise.
int Socket::ConnectToServer( const char *ipAddress, int port,int i)  // server'a bağlanmak için gerekli fonksiyon
{   
    myAddress.sin_family = AF_INET;                                   
    myAddress.sin_addr.s_addr = inet_addr( ipAddress );             
    myAddress.sin_port = htons( port );                               
    
	if (connect( mySocket[i], (SOCKADDR*) &myAddress, sizeof( myAddress )) ==SOCKET_ERROR ) // hata kontrolü
    {
		CString msg = _T("ClientSocket: Failed to connect: Error Value: ");
		CString error;
		int a = WSAGetLastError();
		error.Format(_T("%d"),a);
		msg+=error;
		AfxMessageBox(msg);
        system("pause");	
		
		return 0; //connection fails
	} 
	return 1;
}


How to get 0 or 1 return values in my dialog.cpp to do the listbox operations? or any other suggestions??
Thanks
AnswerRe: Client Connected listbox in vc++ mfc Pin
Moak29-Jul-10 3:52
Moak29-Jul-10 3:52 
GeneralRe: Client Connected listbox in vc++ mfc Pin
dilara semerci30-Jul-10 2:28
dilara semerci30-Jul-10 2:28 
GeneralRe: Client Connected listbox in vc++ mfc Pin
Moak30-Jul-10 3:35
Moak30-Jul-10 3:35 
QuestionNumber of bytes read coming different while debugging the program and while running it. Pin
learningvisualc28-Jul-10 23:43
learningvisualc28-Jul-10 23:43 
AnswerRe: Number of bytes read coming different while debugging the program and while running it. Pin
Code-o-mat29-Jul-10 0:00
Code-o-mat29-Jul-10 0:00 
AnswerRe: Number of bytes read coming different while debugging the program and while running it. Pin
Luc Pattyn29-Jul-10 0:52
sitebuilderLuc Pattyn29-Jul-10 0:52 
QuestionMessage Removed Pin
28-Jul-10 21:57
AmbiguousName28-Jul-10 21:57 
AnswerRe: How to call a user-defined function in VC++.NET?? Pin
Cedric Moonen28-Jul-10 22:03
Cedric Moonen28-Jul-10 22:03 
GeneralRe: How to call a user-defined function in VC++.NET?? Pin
AmbiguousName28-Jul-10 22:13
AmbiguousName28-Jul-10 22:13 
GeneralRe: How to call a user-defined function in VC++.NET?? Pin
Sauro Viti28-Jul-10 22:42
professionalSauro Viti28-Jul-10 22:42 
AnswerRe: How to call a user-defined function in VC++.NET?? Pin
Maximilien29-Jul-10 1:12
Maximilien29-Jul-10 1:12 
QuestionHow to play flash movies with transparent background color in a Window? Pin
itmagina28-Jul-10 14:52
itmagina28-Jul-10 14:52 
QuestionC - DLL Export Pin
dataminers28-Jul-10 11:50
dataminers28-Jul-10 11:50 
AnswerRe: C - DLL Export Pin
Luc Pattyn28-Jul-10 12:10
sitebuilderLuc Pattyn28-Jul-10 12:10 
GeneralRe: C - DLL Export Pin
«_Superman_»28-Jul-10 18:15
professional«_Superman_»28-Jul-10 18:15 
GeneralRe: C - DLL Export Pin
Peter_in_278028-Jul-10 19:13
professionalPeter_in_278028-Jul-10 19:13 
QuestionRe: C - DLL Export Pin
norish28-Jul-10 15:36
norish28-Jul-10 15:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.