Link to home
Start Free TrialLog in
Avatar of jpattee
jpatteeFlag for United States of America

asked on

Using std::string as lParam


Windows API application.

I am trying to use a string to get selected text from an edit control.
The code looks like this:

    std::string szBuffer;
    SendMessage(hEdit, EM_GETSELTEXT, 0, (LPARAM)(LPSTR) szBuffer.c_str());    

The selected text is not returned to the string.
Trying other combinations of type casting results in a compile error.

What is the correct way to cast the string szBuffer in an lParam?


Thanks,
jimp
ASKER CERTIFIED SOLUTION
Avatar of Salte
Salte

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpattee

ASKER

Thanks for your detailed explanation.

I am changing the program from char arrays to strings to avoid an overflow problem.  This has probably happened 2 or 3 times in the last couple of weeks.  The dynamic allocation of strings should (hopefully) solve the problem.  So far srtings have been easy to work with.  This is the first time I have actually needed to allocate memory myself.  It takes some extra coding but it will be worth it if it eliminates the run time errors.

I will probably use the second option you gave.  I want to eliminate this problem for good.

Thanks again,
jimp