首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

MFC传文件

2012-03-14 
MFC传文件求助最近一直忙于做毕业设计,本来都已经差不多了的,后面经过指导老师的要求,又做了挺大的改动。。。

MFC传文件求助
最近一直忙于做毕业设计,本来都已经差不多了的,后面经过指导老师的要求,又做了挺大的改动。。。结果,就剩下传文件这块掉链子了,不知道怎么回事冒出个问题,我跟改动前的代码做了比较,琢磨了2天了,还是没有丝毫发现。。。而且,我还单独做了个测试程序,发现是没有问题的,但是为什么放到我的毕业设计里就会崩溃。。。

主要的症状是,文件的接收方会崩溃,错误如下:
---------------------------
Feiliao.exe - 应用程序错误
---------------------------
"0x004b7203" 指令引用的 "0x00000004" 内存。该内存不能为 "read"。 
要终止程序,请单击“确定”。
要调试程序,请单击“取消”。
---------------------------
确定 取消  
---------------------------
点了确定后又冒出个终止框:
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!

Program:桌面\毕业设计\飞聊修改版、可语音和视频\Feiliao.exe
File: sockcore.cpp
Line: 337

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)
---------------------------
终止(A) 重试(R) 忽略(I)  
---------------------------

后面我找到sockcore.cpp的第337行:

C/C++ code
BOOL CAsyncSocket::AsyncSelect(long lEvent){    ASSERT(m_hSocket != INVALID_SOCKET);    _AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState;    ASSERT(pState->m_hSocketWindow != NULL);//////////这就是337行    return WSAAsyncSelect(m_hSocket, pState->m_hSocketWindow,        WM_SOCKET_NOTIFY, lEvent) != SOCKET_ERROR;}

太蛋疼了。。。不知道什么情况,而且代码很多很杂,不好贴出来。那我发帖的意图就是希望找个热心人,对MFC熟悉的人,我把程序(包括我做的那个测试程序)传给你,你帮我看看是什么情况。真的就是因为这个问题卡在这里了,只要这个问题解决了,后面就可以继续做下去了。。。下月5号答辩,学校说20号要结束作品和论文,话说我论文还没下手。。。希望各路大侠紧急支援啊。。。先谢谢大家了

[解决办法]
接收方调试运行,崩溃的时候能根据堆栈定位到出错代码行
[解决办法]
跨线程使用CSocket得注意了.读一下下面几篇文章吧
http://support.microsoft.com/kb/140527/en-us
http://support.microsoft.com/kb/139692/en-us
http://support.microsoft.com/kb/175668/en-us
[解决办法]
(转)
CSocket断言错误:ASSERT(pState->m_hSocketWindow != NULL);

起因:在套接字处于连接或者发送状态时,试图关闭套接字,于是在这个断言语句处发生中断

原因分析:This assertion failure occurs because the CSocket object was either created or accepted in the context of another thread. The socket notification window was created in a different thread, and the m_hSocketWindow for the current thread is NULL, thus the assertion failure.
实际上就是跨线程使用socket

解决方案:
As already mentioned, a CAsyncSocket object should be used only in the context of a single thread. If you need to switch the thread that is accessing a SOCKET connection with another thread, then you should use a separate CAsyncSocket object in each thread, and use the Detach and Attach functions to attach the CAsyncSocket object to the SOCKET handle in the thread that is about to use the socket. Use this sequence:
1. Use Detach() to detach the CAsyncSocket object from the SOCKET handle in the thread that is currently using the CAsyncSocket object.
2. Use Attach() to attach a different CAsyncSocket object to the SOCKET handle while in the context of the MFC UI thread in which you wish to begin accessing the SOCKET connection.
[解决办法]
是不是文件传输的太快,而处理的不及时呢。
[解决办法]
我以前的毕业设计就是局域网聊天的,也有传文件的功能,如果不介意可以把程序发给我看看。发我QQ邮箱447837737@qq.com
[解决办法]
真复杂,本来是想学习来着,看到这么多问题,有点晕了。
《《http://www.rxjy.com/fengongsi/index.aspx?gs=12///

------解决方案--------------------


因为csocket是窗口消息的,所以,估计和线程操作窗口有关,

表示 观注

你的 头象,偶比较葱白!

热点排行