How should we manage the Memory of the parameters passed by OS in WindowProc

Harshithraj1871 1,556 Reputation points
2024-12-30T10:51:11.39+00:00

Hi,

Im working in Win32 desktop application in cpp.

When a Window Proc is triggered with some WM_* msg, We may receive some LPARAM and WPARAM data. These parameters are different concerning the MSG passed. This can hold variable-length data like pointers to strings, structs, or class objects.

Suppose I want to do some ASYNC operation on some WM_* while passing the LPARAM, and WPARAM to it and let the OS continue its work. Should I pass the LPARAM, and WPARAM to the ASYNC operation by value or by reference? Which is the best practice?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,704 questions
{count} votes

Accepted answer
  1. Darran Rowe 1,321 Reputation points
    2024-12-30T12:39:29.02+00:00

    Neither, copy the string.

    Windows only guarantees the existance of the backing memory until SendMessage/DispatchMessage returns.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.