如何解决对话框崩溃问题? [英] How to resolve dialog box crash issue?

查看:131
本文介绍了如何解决对话框崩溃问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端服务器应用程序,

我创建了一个Dialog类,我实现了一个按钮

和我在Dialog类中实现了我的客户端类,

当我点击按钮时客户端需要连接服务器和

服务器应用程序开始阅读来自客户端的消息,



它正在连接,当从客户端应用程序读取数据时崩溃,

任何人都可以解释我如何解决这个问题吗?



谢谢



我尝试过:



我的客户申请是: -

  #include     stdafx.h 
#include Client.h

LPDWORD dwBytes;

HANDLE m_hPipe;

客户端::客户端(无效
{

}
void Client :: CreateFile()
{
m_hPipe = :: CreateFile(L < span class =code-string> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ / span>,NULL,OPEN_EXISTING, 0 ,NULL);
if (m_hPipe == INVALID_HANDLE_VALUE)
{
cout<< 文件创建失败:;
}
else
{
cout<< 文件已成功创建:\ n;
cout<< 向服务器发送消息:\ n;
:: ConnectNamedPipe(m_hPipe,NULL);
}
}
BOOL Client :: WriteFile()
{
// m_buffer [50] = reinterpret_cast< unsigned char =>(欢迎使用服务器...........!);
m_buffer = L 欢迎......!;
LPDWORD dwBytes = 0 ;
bool Result = :: WriteFile(m_hPipe,& m_buffer, sizeof (m_buffer), dwBytes, 0 );
if (FALSE == Result)
{
cout<< 写入文件失败:\ n;
}
else
{
cout<< 消息写入服务器:\ n;
}
返回 true ;
}
客户端::〜客户端(无效
{
}

我在Dialog类中实现此类类似

  void  CSampleApplicationDlg :: OnBnClickedButton1()
{
Obj-> CreateFile();
Obj-> WriteFile();
睡眠( 10000 );
// TODO:在此处添加您的控制通知处理程序代码
}

解决方案

我认为这与您之前初始化字符数组的问题大致相同。你没有向我们展示 m_buffer 的定义,但是如果它是

 wchar_t m_buffer [50] 
m_buffer = L欢迎......!;



那么你就会遇到问题。您正在尝试将字符指针分配给字符数组,这将无法正常工作,如错误C2440:'=':无法从'wchar_t *'转换为'unsigned char *' [ ^ ]。



你需要回到C / C ++参考并研究数组和指针之间的区别,以及如何初始化它们,以避免这样的问题。


< blockquote> OnBnClickedButton1()中的代码应该在一个单独的线程中运行。



提示:完成后使用PostThreadMessage,如文章 postThreadMessage揭秘解释通知你的对话。


首先使用调试器(在两台计算机上)找出它崩溃的位置,以及它发生时会发生什么 - 通常在那里是一个例外或错误消息/数字,它可以为您提供有价值的线索。



我们无法为您做任何事情:我们无法访问yoru机器,或者完全是服务器代码!


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[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

void CSampleApplicationDlg::OnBnClickedButton1()
{
	Obj->CreateFile();
	Obj->WriteFile();
	Sleep(10000);
	// TODO: Add your control notification handler code here
}

解决方案

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.


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.


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!


这篇关于如何解决对话框崩溃问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆