指针指向不正确
Pointer Not Pointing Correctly?
我在一个线程中运行这段代码,假设receivedPosts和td->window是有效的:
std::vector<Post> *receivedPosts_n = new std::vector<Post>;
*receivedPosts_n = receivedPosts;
SendMessage(td->window, WM_TIMER, IDT_TIMER_FIND_NEW_POSTS_CALLBACK,
(LPARAM) receivedPosts_n);
我在IDT_TIMER_FIND_NEW_POSTS_CALLBACK (hwnd是td->窗口)运行这段代码:
case IDT_TIMER_FIND_NEW_POSTS_CALLBACK:
{
std::vector<Post> *currentPosts_ptr = (std::vector<Post> *)lParam;
//This vector turns up as undefined
std::vector<Post> currentPosts = *currentPosts_ptr;
}
break;
但是问题是*currentPosts_ptr变成了一个无效的指针,即它指向随机内存。
指针有什么问题?
谢谢。
MSDN文档说对于WM_TIMER消息lParam的值是
一个指向应用程序定义的回调函数的指针,在安装计时器时传递给SetTimer函数。
如果您需要发送自定义消息,那么使用专门为这种情况设计的WM_USER通过0x7FFF是更好的主意。
相关文章:
- 使用2个键的cpp-stl::优先级队列排序不正确
- 正弦级数方程计算不正确
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- 密码登录程序将永远循环并显示不正确的结果
- 在C++中返回不正确的楼层函数值
- 形状对象的旋转和缩放不正确C++
- C++ 读取文件读取文件不正确
- 关于类的 Python 文档 - 对C++的引用不正确
- 特征 LLT 模块给出不正确的结果?
- glibcxx STL 在实现 std::valarray::sum() 时是否不正确?
- 对于指向C++类的不透明C指针,正确的typedef是什么
- 字符指针的长度使用 strlen() 不正确
- 使用 const 指针的 C 样式字符返回不正确的结果
- 指向 VS2015 Update 2 中非静态数据成员的指针不正确
- 在具有 64 位 CPU 的 32 位 Win8 上运行 32 位 Orwell Dev-C++ - 输入指针返回不正确
- 将 const 传递给接受 const 指针的函数是不正确的
- 没有错误,但输出不正确.可能存在指针问题
- 如何在作用域指针类中正确使用动态分配的不透明指针
- 指针指向不正确
- Visual Studio 2008-vftable指针不正确?调试模式崩溃,发布即可