Click here to Skip to main content
15,897,273 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ : pass a string array to LPARAM Pin
pasztorpisti27-Aug-12 10:32
pasztorpisti27-Aug-12 10:32 
GeneralRe: C++ : pass a string array to LPARAM Pin
CPallini27-Aug-12 21:10
mveCPallini27-Aug-12 21:10 
GeneralRe: C++ : pass a string array to LPARAM Pin
Atlence28-Aug-12 9:02
Atlence28-Aug-12 9:02 
QuestionRe: C++ : pass a string array to LPARAM Pin
CPallini28-Aug-12 9:59
mveCPallini28-Aug-12 9:59 
AnswerRe: C++ : pass a string array to LPARAM Pin
Atlence28-Aug-12 10:28
Atlence28-Aug-12 10:28 
QuestionRe: C++ : pass a string array to LPARAM Pin
CPallini28-Aug-12 22:58
mveCPallini28-Aug-12 22:58 
AnswerRe: C++ : pass a string array to LPARAM Pin
Atlence29-Aug-12 7:29
Atlence29-Aug-12 7:29 
AnswerRe: C++ : pass a string array to LPARAM Pin
Stefan_Lang27-Aug-12 23:08
Stefan_Lang27-Aug-12 23:08 
What you did is pretend that a string is a LPARAM. That does not change the contents of the variable though! If it had a size of 20 bytes before, it's size is still 20 bytes afterward.

An analogy would be to write 'glass' on a bucket, and then pour it's contents into a glass. Of course that glass will overflow. The water inside that bucket didn't magically compress.

The only case where this would work is when you initially started with an empty bucket, then poured a glass of water in it. At that point you know that while you see a bucket, it's contents is only one glass of water, so you can write 'glass' on it and pour that water back into another glass.

The same is true for typecasting: if you had previously (ab)used that string of yours to store an LPARAM, then - and only then - it would be valid to cast that string back to LPARAM and copy it over into a variable of that type.

As a rule of thumb, never use type-casting. If you think you need a type-cast, then either the type of one (or more) of the involved variables had been wrong from the start, or you're about to break the code. The former would be like using a bucket when you never need to store more than a glass full of water, the latter would be like pouring a bucket full of water into a glass.

There are very few exceptions to that rule, e. g. when you deal with a third-party library that uses inproper argument types such as LPARAM. The clean solution would be to fix that interface and use proper argument types, but sadly you don't have that option. MS should have fixed that 10 years ago, but they didn't.

This leaves you with the onus of assuring that the variables that you wish to pass actually fits into an LPARAM. As already pointed out, it does not. So you have to find another way, and that is passing a pointer to your string, rather than the string itself.
Questionhow to send a slider's value while scrolling.? Pin
mbatra3127-Aug-12 2:41
mbatra3127-Aug-12 2:41 
AnswerRe: how to send a slider's value while scrolling.? Pin
Chris Losinger27-Aug-12 3:18
professionalChris Losinger27-Aug-12 3:18 
AnswerRe: how to send a slider's value while scrolling.? Pin
pasztorpisti27-Aug-12 4:27
pasztorpisti27-Aug-12 4:27 
Questionneed help with vector<student*>* students pointer Pin
neodeaths27-Aug-12 0:28
neodeaths27-Aug-12 0:28 
AnswerRe: need help with vector* students pointer Pin
Maximilien27-Aug-12 0:45
Maximilien27-Aug-12 0:45 
QuestionRe: need help with vector* students pointer Pin
David Crow27-Aug-12 2:34
David Crow27-Aug-12 2:34 
AnswerRe: need help with vector* students pointer Pin
Stefan_Lang27-Aug-12 23:30
Stefan_Lang27-Aug-12 23:30 
Questionfrom sync TCP/IP to async Pin
bkelly1326-Aug-12 15:42
bkelly1326-Aug-12 15:42 
AnswerRe: from sync TCP/IP to async Pin
pasztorpisti26-Aug-12 22:25
pasztorpisti26-Aug-12 22:25 
GeneralRe: from sync TCP/IP to async Pin
bkelly1327-Aug-12 2:41
bkelly1327-Aug-12 2:41 
GeneralRe: from sync TCP/IP to async Pin
pasztorpisti27-Aug-12 4:24
pasztorpisti27-Aug-12 4:24 
GeneralRe: from sync TCP/IP to async Pin
jschell27-Aug-12 8:24
jschell27-Aug-12 8:24 
QuestionAccessing extra keys on a PS2 mouse without driver Pin
David Gvozdenovic26-Aug-12 4:57
David Gvozdenovic26-Aug-12 4:57 
AnswerRe: Accessing extra keys on a PS2 mouse without driver Pin
pasztorpisti26-Aug-12 5:41
pasztorpisti26-Aug-12 5:41 
QuestionCreateProcess and Detect when tthis process Ends.. Pin
Drakesal26-Aug-12 1:25
Drakesal26-Aug-12 1:25 
AnswerRe: CreateProcess and Detect when tthis process Ends.. Pin
pasztorpisti26-Aug-12 3:18
pasztorpisti26-Aug-12 3:18 
AnswerRe: CreateProcess and Detect when tthis process Ends.. Pin
Stephen Hewitt26-Aug-12 5:01
Stephen Hewitt26-Aug-12 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.