Дорогие сотрудники!Помогите!Я написал программу свитч на с++ отправляю батч команду с первого раза идет нормально но другой раз уже дает синтаксис эрор
вот исходник
// msocsDlg.cpp : implementation file
//
#include "stdafx.h"
#include "msocs.h"
#include "ClntSock.h"
#include "AsynLstn.h"
#include "AsynSvSk.h"
#include "msocsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMsocsDlg dialog
CMsocsDlg::CMsocsDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMsocsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMsocsDlg)
m_port = 6000;
m_boolClient = FALSE;
m_strRecv = _T("");
m_strServer = _T("192.168.200.200");
m_strSend = _T("");
m_pClientSock = NULL;
m_pLstnSock = NULL;
m_pSrvrSock = NULL;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMsocsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMsocsDlg)
DDX_Text(pDX, IDC_PORTNO, m_port);
DDV_MinMaxUInt(pDX, m_port, 1024, 10000);
DDX_Text(pDX, IDC_RECEIVE, m_strRecv);
DDX_Text(pDX, IDC_RSVRNAME, m_strServer);
DDX_Text(pDX, IDC_SEND, m_strSend);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMsocsDlg, CDialog)
//{{AFX_MSG_MAP(CMsocsDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SENDBTN, OnSendbtn)
ON_BN_CLICKED(IDC_CKCLIENT, OnCkclient)
ON_BN_CLICKED(IDC_CHKSERVER, OnChkserver)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_CLOSESOCK, OnClosesock)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMsocsDlg message handlers
BOOL CMsocsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
GetDlgItem(IDC_CLOSESOCK)->EnableWindow(FALSE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMsocsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMsocsDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMsocsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMsocsDlg::OnSendbtn()
{
UpdateData(TRUE);
if (m_strSend.GetLength() == 0)
{
AfxMessageBox ("Не отправляй пустую команду");
return;
}
if (m_boolClient)
{
if ( m_pClientSock)
{
if (m_pClientSock->Send((LPCTSTR)m_strSend, m_strSend.GetLength() +1) == SOCKET_ERROR)
{
wsprintf(m_szError, "Failed to send on client socket: %d", m_pClientSock->GetLastError());
m_pClientSock->Close();
delete m_pClientSock;
m_pClientSock = NULL;
AfxMessageBox (m_szError);
return;
}
m_strSend = "";
UpdateData(FALSE);
}
else
{
if ((m_pClientSock = new CClntSock(this)) == NULL)
{
AfxMessageBox ("Failed to allocate client socket! Close and restart app.");
return;
}
if (!m_pClientSock->Create())
{
wsprintf(m_szError, "Failed to create client socket: %d! Close and restart app.", m_pClientSock->GetLastError());
AfxMessageBox (m_szError);
return;
}
if (!m_pClientSock->Connect(m_strServer, m_port))
{
wsprintf(m_szError, "Failed to connect: %d.", m_pClientSock->GetLastError());
AfxMessageBox (m_szError);
m_pClientSock->Close();
delete m_pClientSock;
m_pClientSock = NULL;
return;
}
GetDlgItem(IDC_CLOSESOCK)->EnableWindow(TRUE);
if (m_pClientSock->Send((LPCTSTR)m_strSend, m_strSend.GetLength() +1) == SOCKET_ERROR)
{
wsprintf(m_szError, "Failed to send on client socket: %d", m_pClientSock->GetLastError());
m_pClientSock->Close();
delete m_pClientSock;
m_pClientSock = NULL;
AfxMessageBox (m_szError);
return;
}
m_strSend = "";
UpdateData(FALSE);
}
}
else
{
if ( m_pSrvrSock)
{
m_pSrvrSock->m_sendBuffer = m_strSend;
m_pSrvrSock->m_nBytesSent = 0;
m_pSrvrSock->m_nBytesBufferSize = m_strSend.GetLength() + 1;
m_pSrvrSock->DoAsyncSendBuff();
m_strSend = "";
UpdateData(FALSE);
}
else
{
AfxMessageBox ("Поставь галочку");
}
}
}
void CMsocsDlg::OnCkclient()
{
m_boolClient= TRUE;
GetDlgItem(IDC_CHKSERVER)->EnableWindow(FALSE);
}
void CMsocsDlg::OnChkserver()
{
UpdateData(TRUE);
m_boolClient= FALSE;
GetDlgItem(IDC_CKCLIENT)->EnableWindow(FALSE);
GetDlgItem(IDC_RSVRNAME)->EnableWindow(FALSE);
if (m_pLstnSock == NULL)
{
if ((m_pLstnSock = new CAsynlstn(this)) == NULL)
{
AfxMessageBox ("Failed to allocate listen socket! Close and restart app.");
return;
}
if (!m_pLstnSock->Create(m_port) )
{
wsprintf(m_szError, "Failed to create listen socket: %d! Close and restart app.", m_pLstnSock->GetLastError());
AfxMessageBox (m_szError);
return;
}
if (!m_pLstnSock->Listen())
{
wsprintf(m_szError, "Failed to listen: %d! Close and restart app.", m_pLstnSock->GetLastError());
AfxMessageBox (m_szError);
return;
}
}
}
void CMsocsDlg::OnDestroy()
{
CDialog::OnDestroy();
if (m_pLstnSock) delete m_pLstnSock;
if (m_pClientSock) delete m_pClientSock;
if (m_pSrvrSock) delete m_pSrvrSock;
}
void CMsocsDlg::OnClosesock()
{
if ( m_boolClient && m_pClientSock)
{
m_pClientSock->ShutDown();
m_pClientSock->Close();
delete m_pClientSock;
m_pClientSock = NULL;
m_strRecv = "";
m_strSend = "";
UpdateData(FALSE);
GetDlgItem(IDC_CLOSESOCK)->EnableWindow(FALSE);
}
if (!m_boolClient && m_pSrvrSock)
{
m_pSrvrSock->ShutDown();
m_pSrvrSock->Close();
delete m_pSrvrSock;
m_pSrvrSock = NULL;
m_strRecv = "";
m_strSend = "";
UpdateData(FALSE);
GetDlgItem(IDC_CLOSESOCK)->EnableWindow(FALSE);
}
}