简体   繁体   English

指针指向不正确?

[英]Pointer Not Pointing Correctly?

I am running this code in a thread, assuming receivedPosts and td->window are valid: 我在一个线程中运行此代码,假设receivePosts和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);

I'm running this code at IDT_TIMER_FIND_NEW_POSTS_CALLBACK (hwnd is td->window): 我在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;

But the problem is that *currentPosts_ptr turns up as an invalid pointer, ie it points to random memory. 但是问题是* currentPosts_ptr变成一个无效的指针,即它指向随机内存。

What is wrong with the pointer? 指针出了什么问题?

Thanks. 谢谢。

MSDN documentation says that for WM_TIMER message value of lParam is MSDN文档说,对于WM_TIMER,lParam的消息值为

A pointer to an application-defined callback function that was passed to the SetTimer function when the timer was installed. 指向应用程序定义的回调函数的指针,该指针在安装计时器时传递给SetTimer函数。

If you need to send custom messages it is much better idea just to use WM_USER through 0x7FFF that were specially designed for this scenario. 如果您需要发送自定义消息,最好只使用专门针对此方案设计的WM_USER至0x7FFF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM