Link to home
Start Free TrialLog in
Avatar of fundo_techies
fundo_techies

asked on

Problem in PostMessage Between two Applications.

I am trying to pass a structure
typedef struct
{
int argc;
char argv[80][10];
}ARGS;
from APP1 to APP2 using PostMessage.In APP1,the flow of code is as follows:
#define WM_GETMESG WM_USER+50
ARGS *args;
args=(ARGS *)malloc(sizeof(ARGS));
args->argc=0;
strcpy(args->argv[args->argc++],"snmpget");
strcpy(args->argv[args->argc++],"-v");
strcpy(args->argv[args->argc++],"2c");
strcpy(args->argv[args->argc++],"pslv");
strcpy(args->argv[args->argc++],"public");
strcpy(args->argv[args->argc],"sysDescr.0");
      
HWND hwnd;
hwnd = ::FindWindow("SnmpGet","SNMPGET");
if(hwnd!=NULL)
{
::PostMessage(hwnd,WM_GETMESG,0,(LPARAM)(ARGS *)args);
}

In APP2:
I receieve the message under case WM_GETMESG using the GetMessage Function.But i dont get the values properly.

Kindly Help.
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

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
SOLUTION
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 fundo_techies
fundo_techies

ASKER

I dont want to use SendMessage as it blocks the 1st application till the message has been processed.I need to use only PostMessage for my applications.
Avatar of AndyAinscow
Pass the info through a memory mapped file that both apps have open.  I believe that is the recommended method for sharing things between apps.
If you are passing simple data such as DWORD, you are use the PostThreadMessage. The data is copied to local WPARAM and LPARAM variable.

For sharing a data structure,  two threads must be synchronized so that when one thread is writing, the other thread is blocked from accessing.

WM_COPYDATA message makes used of the shared memory for data exchange between threads.

The SendMessage WM_COPYDATA ensures that the receiving thread has finished copy out the data before the sending thread is allowed to amend it.

It is easier and safer way if you don't want to dive into Multithread Synchronization issue. To accelerate the SendMessage call, just do data copying in receiving thread and return immidiately. There is no time penalty for the receiving thread since this is essential thing that it needs to perform.

SOLUTION
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