Hello all,

I am tasked with porting an MFC-based program to Qt4, and would like to set up as much groundwork as possible to make this app as much cross-platform as possible (at this time, certain hardware limitations prevent us from completely porting this to Linux).

The program spawns several processes and communicates with these processes using a shared memory segment set up like so:
Qt Code:
  1. HANDLE m_hMap;
  2. LPVOID m_pSharedData;
  3. // ...
  4. void initSharedMemory() {
  5. m_hMap=::CreateFileMapping((HANDLE)0xffffffff,0,PAGE_READWRITE,0,sizeof(RTC_DATA),MAPFILE);
  6. m_pSharedData=::MapViewOfFile(m_hMap,FILE_MAP_WRITE,0,0,0);
  7. }
To copy to clipboard, switch view to plain text mode 

where RTC_DATA is the gobal struct containing the data and MAPFILE a #define.

The sub-processes are spawned like so:
Qt Code:
  1. ShellExecute( HWND(this), "open", "proc.exe", str_args, NULL, SW_HIDE);
To copy to clipboard, switch view to plain text mode 

Later in the code, the processes are being sent messages like this:
Qt Code:
  1. int SendMsgToProc(int procid, int cmd, long code, long code1)
  2. {
  3. char strtmp[10];
  4. sprintf(strtmp,"PROC%d",motorid);
  5. CWnd *pWnd;
  6. pWnd = CWnd::FindWindow(NULL,strtmp);
  7. if(pWnd)
  8. {
  9. WM_MSG msg;
  10. msg.command = cmd;
  11. msg.code = code;
  12. msg.code1 = code1;
  13. COPYDATASTRUCT cs;
  14. cs.cbData=sizeof(WM_MSG);
  15. cs.dwData=0;
  16. cs.lpData=&msg;
  17. pWnd->SendMessage(WM_COPYDATA,(WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cs);
  18. return 0;
  19. }
  20. else
  21. {
  22. return -1;
  23. }
  24. }
To copy to clipboard, switch view to plain text mode 

So far, I believe QProcess would be the right thing to do, and did the following:

Qt Code:
  1. QProcess *sub_proc = new QProcess(qApp);
  2. // ... reading a configuration file ...
  3. QStringList args = line.split("\s");
  4. sub_proc->start("proc.exe",args);
To copy to clipboard, switch view to plain text mode 

I also replaced the shared memory implementation with QSharedMemory. Now, however I need to be able to access these processes in a like manner as the "SendMsgToProc" function above.

Can anyone point me into the right direction? I know there is a WId for widgets, but would that even be feasible? Am I correct in attaching the QProcess instances to the global qApp?

I have no idea about MFC, and am only somewhat intermediate with Qt. If QProcess is not the right way to go, I would appreciate any comments as to what would be better.

Thanks,
Stephan