Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:03:14+00:00 2026-06-11T16:03:14+00:00

How to send struct or pointer using SendMessage or PostMessage function?

  • 0

How to send struct or pointer using SendMessage or PostMessage function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:03:15+00:00Added an answer on June 11, 2026 at 4:03 pm

    Here is simple example:

    typedesf struct tagMY_STRUCT{
        unsigned int a;
        unsigned int b;
        unsigned int c;
    }MY_STRUCT;
    
    //Some code which sends message
    MY_STRUCT *pStruct = new MY_STRUCT;
    
    pStruct->a = 5;
    pStruct->b = 4;
    pStruct->c = 1;
    
    SendMessage(hWnd, WM_USER + 1, 0, (LPARAM)pStruct);
    
    //WndProc
    
    case (WM_USER + 1) :
    {
        MY_STRUCT *pStruct = (MY_STRUCT*)lParam);
        if(pStruct)
        {
            int a = pStruct->a;
    
            delete pStruct;
        }
    
    }
    break;
    
    • Don’t ever try to do it between processes.Study IPC basics first.

    • Don’t forget to release pointer to struct once not needed using
      delete.

    UPDATE

    As Remy Lebeau mentioned in comment, you can also allocate struct on stack instead on heap using new/malloc, because SendMessage block thread until it’s processed in WndProc.This does not apply to PostMessage which add message to window’s message queue and return immediately, so it requires heap block.

    However, if you plan to pass more complex data struct I recommend heap allocation instead of stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send and receive using pipes: send.cpp struct { long a; long
I need to send a C struct over the wire (using UDP sockets, and
While creating a netlink socket using netlink_kernel_create() a function pointer is passed as argument
I send a struct with one field (unsigned int) to a network emulator and
I must send a struct between two machines via a udp socket the information
I would like to send a struct from my client program to a server
I send binary data over websocket from python server: data = struct.pack('!BI', 2, 1)
I am trying to send an array of this struct to a DBus Server:
I have defined a custom struct which I need to send over to another
I need to send a VARIANT value to another application using COPYDATASTRUCT. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.