• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3466
  • Last Modified:

CString to LPARAM SendMessageW

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
Ocrana
Asked:
Ocrana
  • 5
  • 4
1 Solution
 
jkrCommented:
The easiest way probably is

CString str;
LPCTSTR pstr = (LPCTSTR) str;
LPARAM lparam = (LPARAM) pstr;
0
 
jkrCommented:
Or, in short:

CString str;

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

or


pWnd->SendMessage(WM_SOMETHING,0,(LPARAM)((LPCTSTR)str));
0
 
OcranaAuthor Commented:
Hi,
 also in Unicode code?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
jkrCommented:
Yes, that should work for both UNICODE and ANSI.
0
 
OcranaAuthor Commented:
sorry, I get allways a compile error that the types cannot converted C2440
0
 
jkrCommented:
What is the exact error and on which line do you get it when using

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

?
0
 
OcranaAuthor Commented:
I get in the line:

LPCTSTR pstr = (LPCTSTR) initializePath;

the C2440 Error.
0
 
jkrCommented:
That is pretty odd. What is the *exact* error message?
0
 
OcranaAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now