0

I have two applications:

1.: C# GUI application written in VisualStudio 2013.

2.: C++ GUI application written in VisualStudio 2013.

I would like to send float numbers from application #1 to application #2.

(In other words: If the C# app. calculates a float number (e.g.: 12.32) then I would like to see this number on the standard output written by the C++ application.)

What is the easiest way to accomplish this? Is there any Windows API, or common-memory-address-thing, etc. to accomplish this?

Fract
  • 323
  • 1
  • 6
  • 22

4 Answers4

2

Hmmm... There's some way's to do it (what i know) :

If i want do this on GUI Applcation i'll choose P\Invoke but if i want do something background i'll choose IPC Channels or Shared Memory (IPC Channels is better)

moien
  • 999
  • 11
  • 26
2

You can do this using any kind of inter-process communication mechanism. The simplest one might be anonymous pipes. You will find how to use anonymous pipes here in C++ and there in C#.

shrike
  • 4,449
  • 2
  • 22
  • 38
1

I assume both applications are running at the same time. I would do a local transfer using sockets or I assume that the c++ application just catches the data from the C# app so you can return it as a data object and pass that to the spawning C++ app as an argument.

AdmiralSmith
  • 105
  • 2
1

One of the easiest ways is to dump the values to a file in C# then pick them up in C++.

note: This method is not the most reliable/fastest and may not be best for enterprise product but for a quick one time need this should work fine.

Save the output to a file...

using System.IO;

class ConsoleApplication {
    static void Main()
    {
        using (BinaryWriter writer = new BinaryWriter(File.Open("temp.dat", FileMode.Create)))
        {
            writer.Write(1.2345F);
        }
    } }

Then read it in using c++... (Source is here)

#include <iostream>

int main(void)
{
    FILE *r_file = NULL;
    float fd_value = 0;

    r_file = fopen("temp.dat", "rb");
    if (NULL == r_file)
        return 0;

    fread(&fd_value, 1, sizeof(fd_value), r_file);
    fclose(r_file);


    printf("fd_value = %f\n", fd_value);
    return 0;
}
SunsetQuest
  • 8,041
  • 2
  • 47
  • 42