Click to See Complete Forum and Search --> : store data in window procedure
dave2k
November 14th, 2005, 09:27 AM
ok, my hook sends my window procedure a message very frequently. My problem is that my window procedure needs to return straight away, else the program i am hooking comes to a grinding halt. This would be ok, but it usually takes a few seconds for my program to process the data being sent to it.
my hook uses copy data message to send the data.
so i was wondering what sort of mechanism i need to set up in my program to process these messages.
do you think some sort of list?
the stored data is each time a string of around 50 characters.
thanks.
Marc G
November 14th, 2005, 10:38 AM
Why don't you post your messages from your hook to your window instead of sending them? PostMessage will return immediately, while SendMessage will wait for the result.
dave2k
November 14th, 2005, 11:09 AM
wm_copydata works soley with SendMessage unfortunately
usman999_1
November 14th, 2005, 11:30 AM
You can either create a thread :), not everytime you want to send a message but just once (on app start-up probably) and this thread should have do the sending i.e. your main thread on some event will copy data to the synchronized vector/list of strings, notify the thead (SetEvent) and thread will takeout the data from the vector/list and send it.
Another way is to use IOCP, this way you dont have to worry about the synchronisation of the data, but is little more of a work to setup an IOCP.
Hope this helps,
Usman.
dave2k
November 14th, 2005, 11:32 AM
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/dataexchange/datacopy/usingdatacopy.asp
here if shows a program getting the data, and putting it in it's own data structure. the trouble here is, my windows procedure is going to be called sometimes more than once when my program is processing the first message, meaning the struct variable is going to get overwritten.
how can i protect against this? maybe a deque of structs?
the only problem is, i wouldn't know how to tell the struct processing code when to start..
argh - confusing!
usman999_1
November 14th, 2005, 11:42 AM
If you are not using static data (where only one instance of the data exists thoughout the application), there should be no problem even if you are in the middle of processing the first message and you get a second message. And the application, that processes the WM_COPYDATA will process those message sequentially i.e. even if there are multiple threads/applications sending a message (WM_COPYDATA for example) to one window at the same time (even on multi-processor systems) the WndProc (to which those messages are destined) will process those messages sequentially i.e. one after another.
Hope this helps,
Usman.
dave2k
November 14th, 2005, 11:57 AM
so i don't even need a thread then?
in my winproc i just sent my winproc a message with the struct data?
usman999_1
November 14th, 2005, 12:03 PM
The reason i asked you to use thread was to sortof process the message quickly (as you said something that other (hooked) application comes to a halt if you take time to process the message), if thats not the case then i dont think you need to use threads there.
Hope this helps,
Usman.
miteshpandey
November 14th, 2005, 12:05 PM
Try the following maybe it will work:
Your application's window procedure:
.....
.....
case WM_COPYDATA:
::PostMessage(hWnd, USER_DEFINED_MESSAGE, 0, LPARAM);
break;
.....
.....
.....
The LPARAM should be what you received in your application's window procedure for the WM_COPYDATA and you will handle the sent data inside your user message handler.
In this you are utilizing the application's message queue instead of a list or queue.
I have not tried it but maybe it will help.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.