Solved

CString to LPARAM SendMessageW

Posted on 2007-11-25
9
3,035 Views
Last Modified: 2013-12-03
Hi,

I have a class where a String is CString value. No I want to send this Cstring to a contraol with a SendMessageW function. I think I have to use a (LPARAM)mystring. But this will cause a compile error cause CString cannot convert to LPARAM. Any idea how to solve?

Ingo
0
Comment
Question by:Ocrana
  • 5
  • 4
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
The easiest way probably is

CString str;
LPCTSTR pstr = (LPCTSTR) str;
LPARAM lparam = (LPARAM) pstr;
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Or, in short:

CString str;

SendMessage(hwnd,WM_SOMETHING,0,(LPARAM)((LPCTSTR)str));

or


pWnd->SendMessage(WM_SOMETHING,0,(LPARAM)((LPCTSTR)str));
0
 

Author Comment

by:Ocrana
Comment Utility
Hi,
 also in Unicode code?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Yes, that should work for both UNICODE and ANSI.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Ocrana
Comment Utility
sorry, I get allways a compile error that the types cannot converted C2440
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What is the exact error and on which line do you get it when using

LPCTSTR pstr = (LPCTSTR) str;
LPARAM lparam = (LPARAM) pstr;

?
0
 

Author Comment

by:Ocrana
Comment Utility
I get in the line:

LPCTSTR pstr = (LPCTSTR) initializePath;

the C2440 Error.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
That is pretty odd. What is the *exact* error message?
0
 

Author Comment

by:Ocrana
Comment Utility
ups, sorry, the problem was the function itself. I had to set the (LPARAM)((LPCTSTR)str) in a function that calls the function that try to trhow the SendMessage. Cause the Function that send was a callback without access to the str.
I set the LPARAM in the function that set the callback and everything works fine. Many thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now