I Have A Client Server Applications,
and I created a Dialog Class and I implemented one button
and I Implemented My Client Class in Dialog class,
when I click button the client need to connect with the server and
the server application start reading messages from client,
It is connecting and while Reading Data from the Client Application is Crashing,
Can any one explain me how to resolve this issue?
Thanks
What I have tried:
My Client Application is :-
#include"stdafx.h"
#include "Client.h"
LPDWORD dwBytes;
HANDLE m_hPipe;
Client::Client(void)
{
}
void Client::CreateFile()
{
m_hPipe = ::CreateFile(L"\\\\.\\pipe\\mypipe",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(m_hPipe==INVALID_HANDLE_VALUE)
{
cout<<"File Creation Failed:";
}
else
{
cout<<"File Created Sucessfully:\n";
cout<<"Sending Message to the Server:\n";
::ConnectNamedPipe(m_hPipe,NULL);
}
}
BOOL Client::WriteFile()
{
m_buffer = L"Welcome...!";
LPDWORD dwBytes = 0;
bool Result = ::WriteFile(m_hPipe,&m_buffer,sizeof(m_buffer),dwBytes,0);
if(FALSE == Result)
{
cout<<"Write file failed:\n";
}
else
{
cout<<"Message wrote to the Server:\n";
}
return true;
}
Client::~Client(void)
{
}
And I Implemented this Class in Dialog class Like
void CSampleApplicationDlg::OnBnClickedButton1()
{
Obj->CreateFile();
Obj->WriteFile();
Sleep(10000);
}