Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: help: menu command programming. Pin
trustno13-Dec-02 8:04
trustno13-Dec-02 8:04 
GeneralRe: help: menu command programming. Pin
jhwurmbach3-Dec-02 21:03
jhwurmbach3-Dec-02 21:03 
GeneralFile association Pin
act_x2-Dec-02 11:52
act_x2-Dec-02 11:52 
GeneralRe: File association Pin
Selevercin2-Dec-02 12:08
Selevercin2-Dec-02 12:08 
Generaltitle bar Pin
Anonymous2-Dec-02 11:21
Anonymous2-Dec-02 11:21 
GeneralRe: title bar Pin
Pavel Klocek2-Dec-02 11:26
Pavel Klocek2-Dec-02 11:26 
GeneralRe: title bar Pin
Anonymous2-Dec-02 11:35
Anonymous2-Dec-02 11:35 
GeneralSocket help.. Pin
RobJones2-Dec-02 11:02
RobJones2-Dec-02 11:02 
Hello,
I am having problems with CAsyncSocket.. The errors occurs when I accept a socket.. I then have a function that resolves the IP address of the socket.. It then compairs the IP address with all of the IP address in an array.. then it returns a CString value of the IP address. After that I try to send data to the socket and I receive the following error..

The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

(Press Retry to Debug the Application)

Here is my Resolve function.. (It's returning the correct value)..

CString CMainFrame::OnCompareAddress(CMySocket* pSocket)
{
	CString strAddress,strListAddress, strDns, strName;
	unsigned int iPort;
	
	pSocket->GetPeerName(strAddress, iPort);

	int iCount = m_array.GetSize();
	while(iCount > 0)
	{	
		ProcessMessages();

		sfriend pFriend; // Structure in my array
		pFriend = m_array.GetAt(iCount-1);
		CString strDns = pFriend.strDns;

		// Resolve the host name "DNS" name to a IP Address
		hostent *pHost = gethostbyname(strDns);
		if ( pHost != 0 )
		{
			// Copy the IP address into sockaddr_in structure
			// There is only one hostent structure per thread, so we need to copy it before we call the function
			// again.
			sockaddr_in addr;
			memset( &addr, 0, sizeof(addr) );
			addr.sin_family = AF_INET;
			memcpy( &addr.sin_addr, pHost->h_addr, pHost->h_length );
			
			strListAddress = inet_ntoa(addr.sin_addr);
		}
		else
			iCount = 0;

		// If the IP Addresses match, return the host name from our array;
		if(!strAddress.CompareNoCase(strListAddress))
		{
			strName = strDns;
			iCount = 0;
		}
		else
			iCount --;
	}

	if(!strName.IsEmpty())	// not empty, send DNS name..
		return strName;
	else					// Empty, send the ip address of the socket..
		return strAddress;
}


My accept function..

void CMainFrame::OnAccept()
{
	CMySocket* pSocket = new CMySocket();
	pSocket->SetParent(this);

	if (!m_sListen.Accept(*pSocket))
		delete pSocket;
	else
	{
		// Socket was Accepted successfully..

		// Put the pointer at the tail of our pointer list..
		m_pConnectionList.AddTail(pSocket);
		
		// Get the DNS name of the socket..
		CString strName = OnCompareAddress(pSocket); // If I make strName = DNS or IP address it works.. WEIRD

		int nFound = 0;
		
		int iCount = m_array.GetSize();
		while(iCount > 0)
		{
			sfriend pFriend;
			pFriend = m_array.GetAt(iCount-1);
			CString strDns = pFriend.strDns;
					
			if(!strDns.CompareNoCase(strName))	// We have a match
			{
				nFound = 1;
				iCount = 0;
			}
			else								// No match try again
				iCount --;
		}

		if(nFound = 0 /* Not Found */)
		{
			CString strMessage;
			strMessage = "(NOT_IN_LIST): ";
								
			int iLen = strMessage.GetLength();
			pSocket->Send((LPCSTR)strMessage,iLen);

			OnCloseConnection(pSocket);
		}
		else // We found the friend, lets send them our status..
			OnSendMyStatus(pSocket);
	}
}


Any Ideas??
Rob
GeneralRe: Socket help.. Pin
valikac2-Dec-02 14:29
valikac2-Dec-02 14:29 
GeneralCode Timing Question Pin
_Kal-El_2-Dec-02 11:00
_Kal-El_2-Dec-02 11:00 
GeneralRe: Code Timing Question Pin
Kannan Kalyanaraman2-Dec-02 20:24
Kannan Kalyanaraman2-Dec-02 20:24 
GeneralFILETIME conversion/comparison Pin
#realJSOP2-Dec-02 10:34
mve#realJSOP2-Dec-02 10:34 
GeneralRe: FILETIME conversion/comparison Pin
Nitron2-Dec-02 11:08
Nitron2-Dec-02 11:08 
GeneralRe: FILETIME conversion/comparison Pin
Jamie Hale2-Dec-02 11:33
Jamie Hale2-Dec-02 11:33 
GeneralRe: FILETIME conversion/comparison Pin
Michael Dunn2-Dec-02 12:15
sitebuilderMichael Dunn2-Dec-02 12:15 
GeneralQueue problem (part2) Pin
ian_ok2-Dec-02 10:24
ian_ok2-Dec-02 10:24 
GeneralRe: Queue problem (part2) Pin
Christian Graus2-Dec-02 10:55
protectorChristian Graus2-Dec-02 10:55 
GeneralResizing a CFormView class Pin
Georgi Atanasov2-Dec-02 10:12
Georgi Atanasov2-Dec-02 10:12 
GeneralRe: Resizing a CFormView class Pin
Maximilien2-Dec-02 10:50
Maximilien2-Dec-02 10:50 
GeneralWrite to parallel port Pin
Shay Harel2-Dec-02 10:03
Shay Harel2-Dec-02 10:03 
Generalhelp: right mouse click pop up menu Pin
trustno12-Dec-02 8:50
trustno12-Dec-02 8:50 
GeneralRe: help: right mouse click pop up menu Pin
valikac2-Dec-02 8:57
valikac2-Dec-02 8:57 
GeneralRe: help: right mouse click pop up menu Pin
Jason Henderson2-Dec-02 9:16
Jason Henderson2-Dec-02 9:16 
GeneralRe: help: right mouse click pop up menu Pin
Nitron2-Dec-02 10:00
Nitron2-Dec-02 10:00 
GeneralWizardsheet - propertypage and AfxMessageBox Pin
André Dewispelaere2-Dec-02 8:35
André Dewispelaere2-Dec-02 8:35 

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.