gpt4 book ai didi

c++ - 指针未正确指向?

转载 作者:太空宇宙 更新时间:2023-11-04 13:30:56 25 4
gpt4 key购买 nike

我在一个线程中运行这段代码,假设 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->window):

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 documentation表示对于 WM_TIMER 消息,lParam 的值是

A pointer to an application-defined callback function that was passed to the SetTimer function when the timer was installed.

如果您需要发送自定义消息,最好只使用 WM_USER through 0x7FFF专门为这种情况设计的。

关于c++ - 指针未正确指向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31492281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com