Xander
Xander

Reputation: 9171

Calling methods in one c++ program from another (Inter Process Communication)

I would like to call methods from one of my c++ programs from another. These methods would have objects that I would pass back and forth.

What is the easiest way to accomplish this?

It is pretty complex data back and forth. One possible way I was thinking would be to create a web service, but I was hoping there could be something easier. Perhaps with COM or something?

This is for Windows only.

Upvotes: 2

Views: 332

Answers (1)

Sly_TheKing
Sly_TheKing

Reputation: 528

Since u mentioned COM, I'm assuming you're working in windows.

You can use SendMessage function, and use WM_COPYDATA message.

Use it like this:

COPYDATASTRUCT *cds = new COPYDATASTRUCT;

//init cds
...

SendMessage(hwnd_receiver, WM_COPYDATA, hwnd_sender, cds);

To get hwnd of other application use EnumWindows and GetModuleFileName. Or you can use different mechanism, it's up to you.

Upvotes: 2

Related Questions