sk-man
asked on
string in LPARAM
Hello
I Use PostMessage to broadcast a WindowsMessage. I want to post a string, but it seems like I can only post integers.
I try this:
char test[] = "abc";
PostMessage(HWND_BROADCAST , 49888, 2, test); //Errormessage: cannot convert parameter 4 from 'char [4]' to 'LPARAM'
But it dowsnt work.
How do i send a string in the LPARAM?
Please help
I Use PostMessage to broadcast a WindowsMessage. I want to post a string, but it seems like I can only post integers.
I try this:
char test[] = "abc";
PostMessage(HWND_BROADCAST
But it dowsnt work.
How do i send a string in the LPARAM?
Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It is a pointer address, and it's only valid within the same process as you post the message (as SteH said).
You can't pass strings over directly. You have to pass some form of handle or pointer, and have the string stored elsewhere.
You can't pass strings over directly. You have to pass some form of handle or pointer, and have the string stored elsewhere.
ASKER
OK, so I'll figure something else out.
A CMemFile could be a solution. Since it is in memory it is fast and can be used across process boundaries.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
BTW, see also http://codeguru.earthweb.com/win32/ipcdemo.shtml on this issue.
you can also look at this problem from this point of view: why pass the string to the other process? let the other process get the string when it nedds it. so you can simply export a function from your c++ dll that will get the desired string and call that function from c# form. if you want all processes to access the same value of the string, put it in a 'shared' section of your dll
A.
A.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Split: SteH {http:#9825676} & jkr {http:#9825791}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Split: SteH {http:#9825676} & jkr {http:#9825791}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
Tinchos
EE Cleanup Volunteer
Um, actually "WM_COPYDATA" is the only way to send strings across process boundaries using windows messaging.
Sorry jkr
Maybe I'm not quite familiar with this topic in particular, but I thought that Steh's comments should also be awarded some points.
However, mine is just a recommendation, post yours and moderators will decide when they come to close it.
Cheers
Tincho
Maybe I'm not quite familiar with this topic in particular, but I thought that Steh's comments should also be awarded some points.
However, mine is just a recommendation, post yours and moderators will decide when they come to close it.
Cheers
Tincho
Hum, then, to be blunt: I *think* I was closest to the requested solution (using messaging)
@jkr,
you are right. You gave the correct answer to the question. Mine could be at most interpreted as a hint how it can be solved in another way. Sometimes one is looking for a solution the way one is ued to. And one is not aware that there are other possiblities available.
you are right. You gave the correct answer to the question. Mine could be at most interpreted as a hint how it can be solved in another way. Sometimes one is looking for a solution the way one is ued to. And one is not aware that there are other possiblities available.
ASKER
I do this in a c++ dll:
------------------------
char* test = new char[10];
strcpy (test, "abc");
PostMessage(HWND_BROADCAST
In a C# form i have the WinProc function where i catch the message:
--------------------------
string test = m.LParam.ToString();
This gives me "60107080" which looks like a ptr. address to me.