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 4035436
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:05:52+00:00 2026-05-20T12:05:52+00:00

How can I create a custom windows message that passes any data to a

  • 0

How can I create a custom windows message that passes any data to a different program.

I am messaging between a GUI-program and a server-program. My background is in *nix programming and I am a bit lost in the windows world.

Currently both programs are created by Visual Studio’s wizard by chosing “MFC windowed application”. Now I want an elegant way to communicate between the programs. Google gives me Cwnd->sendmessage + registering your own messages etc. However, I cannot pass a char pointer to a different program with standard custom messages (well, I can but the memory area is wrong, and the program segfaults). So, google again gives me sendmessage(WM_COPYDATA, hparam, lparam) which is marshalled. When googling marshalling… I ran into a wall.

I assume that marshalled messages (or their data) are passed into a shared memory area which is readable only by the sender and the receiver program (correct?). And by creating a custom message that has a pointer of marshalled data as lparam, I can pass any object to another program (correct?). How do I do this in practice? I tried the following:

pWin->SendMessage(pTargetWin, WM_CUSTOM_MESSAGE, pSourceWin, pData);

Above works if pData is integer. If pData is a pointer to object, I cannot use the object because of the missing marhsalling. I know that I can do a wrapper COPYDATASTRUCT wrapper to pData and change to WM_COPYDATA. Should I do that instead?

br,
Juha

  • 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-05-20T12:05:53+00:00Added an answer on May 20, 2026 at 12:05 pm

    WM_COPYDATA does marshalling for you, provided you’ve correctly initialized the COPYDATASTRUCT that you’re passing as the LPARAM (lpData is the pointer, not dwData). Custom messages won’t do that, and you don’t want to reimplement marshalling by hand. If you need marshalling, use WM_COPYDATA. Is that what you’re asking? It sounds like you know the answer already.

    If you need to support multiple different kinds of messages, you could just stuff an enum in COPYDATASTRUCT.dwData to specify what the rest of the data means. If four bytes isn’t enough, you could define a header on your marshalled data.

    One way or another, as long as you can pass a big pile of zeroes and ones, you can communicate anything you like.

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

Sidebar

Related Questions

I want to know if i can create a custom google maps application,on which
How can I create a custom property for my .Net assembly which would then
I think I know how to create custom encrypted RSA keys, but how can
I know how to create a custom user control in WPF but how can
How can I use reflection to create a generic List with a custom class
I've created a custom exception for a very specific problem that can go wrong.
I can create a menu item in the Windows Explorer context menu by adding
In my VB.net project I created a custom cursor (Window.cur). How can I assign
I can create the following and reference it using area[0].states[0] area[0].cities[0] var area =
I can create a literal long by appending an L to the value; why

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.