Solved

CString to LPARAM SendMessageW

Posted on 2007-11-25
9
3,130 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
ID: 20347051
The easiest way probably is

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

Expert Comment

by:jkr
ID: 20347056
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
ID: 20347086
Hi,
 also in Unicode code?
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 86

Expert Comment

by:jkr
ID: 20347109
Yes, that should work for both UNICODE and ANSI.
0
 

Author Comment

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

Expert Comment

by:jkr
ID: 20347180
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
ID: 20347299
I get in the line:

LPCTSTR pstr = (LPCTSTR) initializePath;

the C2440 Error.
0
 
LVL 86

Expert Comment

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

Author Comment

by:Ocrana
ID: 20347357
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Sed question 2 103
What is MicroStrategy.NET? 2 72
Is IHttpActionResult a promise pattern? 2 68
Where does legacy ASP.NET initialize language? 2 26
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

830 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