Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :-
C++
#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[50] = reinterpret_cast<unsigned char="">("Welcome to server...........!");
	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
C++
void CSampleApplicationDlg::OnBnClickedButton1()
{
	Obj->CreateFile();
	Obj->WriteFile();
	Sleep(10000);
	// TODO: Add your control notification handler code here
}
Posted
Updated 11-Mar-19 4:34am
v2

I think this is much the same as your previous issue with initialising character arrays. You have not shown us the definition of m_buffer, but if it is
wchar_t m_buffer[50]
m_buffer = L"Welcome...!";

then you will have a problem. You are trying to allocate a character pointer to a character array, which just will not work, as explained at Error C2440: '=' : cannot convert from 'wchar_t *' to 'unsigned char *'[^].

You need to go back to the C/C++ reference and study the difference between arrays and pointers, and how to initialise them, in order to avoid problems like this.
 
Share this answer
 
The code in theOnBnClickedButton1() should run in a separate thread.

Tip: when done use PostThreadMessage like in thes article PostThreadMessage Demystified explained to inform your dialog.
 
Share this answer
 
Start by using the debugger (on both computers) to find out where it is crashing, and what happens when it does - normally there is an exception or error message / number which can give you valuable clues.

We can't do anything for you: we have no access to yoru machines, or to the server code at all!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900