-
April 9th, 2008, 03:32 AM
#1
passing pointers between the process
Hi,
I need to pass the character array or char* to the another process through BroadcastSystemMessage() API. If I use WPARAM for this, I get the junk address in the recieving process.I am doing something like this
Sender
Code:
..
char szTemp[32]={0};
strcpy(szTemp,"TEST");
ULONG uiMsg = RegisterWindowMessage(KP_EXPORT_STATUS_MSG);
DWORD dwRecipients = BSM_APPLICATIONS;
DWORD dwFlags = BSF_FORCEIFHUNG | BSF_POSTMESSAGE;
BroadcastSystemMessage( BSF_FORCEIFHUNG|BSF_POSTMESSAGE,
&dwRecepients,
iServerFileFailure,
(WPARAM)temp,
0);
...
Reciever
Code:
ULONG uiMsg = RegisterWindowMessage(KP_EXPORT_STATUS_MSG);
DWORD dwRecipients
LRESULT CALLBACK WndMainProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if( message == uiMsg )
{
char* szTemp = (char*)wParam;
//szTemp is junk here
}
Later I figured out that, pointers are meaningless between two processes as they will be having different process space. But it works if i send an interger as WPARAM instead of pointer.
I need to pass a string to another process. Is there any workaround for this problem??
Thanks
-
April 9th, 2008, 03:43 AM
#2
Re: passing pointers between the process
Like you figured out yourself, you cannot send a pointer since it is only meaningful in 1 process.
Since it seems you are writing both applications, try to use WM_COPYDATA.
Make sure you read the remarks in that article!
-
April 9th, 2008, 03:45 AM
#3
Re: passing pointers between the process
There are several forms of Interprocess Communication on Windows Platforms.
Another option is a Win32 dll with a share data segment. The dll provides a pair of GetSet methods and you put a string buffer into the shared seg area of the dll. You would have to load the dll in both processes.
One of the options mentioned in the link above is a memory mapped file. I use this technique in one of my articles in my subject line (Win32.. Part II). There is a Log Send and Log Receive sample that uses a MMF to send a structure containing a string buffer between two processes.
-
April 9th, 2008, 03:56 AM
#4
Re: passing pointers between the process
As Arjay wrote there are many ways to send data between processes, and as Marc G pointed out using WM_COPYDATA is one of the simplest ones providing that both processes are on the same machine/desktop. But there could be also some problems with WM_COPYDATA if someone else (not your sender process) broadcasts it! See this essay:Using WM_COPYDATA
Victor Nijegorodov
-
April 9th, 2008, 03:58 AM
#5
Re: passing pointers between the process
Originally Posted by Marc G
Like you figured out yourself, you cannot send a pointer since it is only meaningful in 1 process.
Since it seems you are writing both applications, try to use WM_COPYDATA.
Make sure you read the remarks in that article!
Thanks a lot for the reply..
I gone through the link regarding WM_COPYDATA, But I dont have the handle for the window. That is why I am broadcasting the custom message. So I am afraid I cant use WM_COPYDATA.
However I am not getting why this works in the case of integers.
Thanks
-
April 9th, 2008, 04:03 AM
#6
Re: passing pointers between the process
Because in the case of integers you send the real integer and not some pointer.
-
April 9th, 2008, 04:13 AM
#7
Re: passing pointers between the process
Thanks Arjay and VictorN for reply..
Hello Mark G, I see that WPARAM is defined as UINT_PTR, so its a pointer. Doesnt it means that we are sending pointer and not the integer.
I am little confused abt it.
Thanks anyway.
-
April 9th, 2008, 07:47 AM
#8
Re: passing pointers between the process
No, UINT_PTR is defined as follows:
Code:
#if defined(_WIN64)
typedef unsigned __int64 UINT_PTR;
#else
typedef unsigned int UINT_PTR;
#endif
So, it's a 32 bit uint when building 32 bit version and it's 64 bit when building 64 bit version. It is called _PTR because it could be used to store pointers since it will have the correct size.
-
April 9th, 2008, 05:21 PM
#9
Re: passing pointers between the process
Originally Posted by sachin871
But I dont have the handle for the window.
But, is it possible for you to get a handle to the window , say using FindWindow/Ex ?
If it is a string of known length, check to see if this post about atom tables is a viable option. http://www.codeguru.com/forum/showpo...7&postcount=14
-
April 10th, 2008, 12:02 AM
#10
Re: passing pointers between the process
Thanks a lot for all ur replies..
Meanwhile I came across this tutorial on MSDN which is regarding the use of shared memory. I think its pretty easy and I can use that in future as well.
Here is the link
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|