1

I have a problem with two projects. My main project is in C++. Another one is in C# and it is measuring current network bandwidth (updated every second). What I need to have is that C++ project can get those values.

Mt first thought was to let the C# export calculated values to .txt file. Another project could read those values. But problem is that it would mean that both would use that file at the same moment what seems to be impossible (or maybe I could synchronize it somehow?)

I was reading a lot about creating and using library, but it looks complicated to me.

Are there any other ways to do that?

Please, I need help...

4
  • 1
    Given that the two programs should remain separately: There are many possibilities for the so-called IPC, Interprocess-communications. msdn.microsoft.com/en-us/library/windows/desktop/… Commented Jan 14, 2014 at 9:26
  • IPC, indeed, or a Named Mutex to serialize access to the txt file. See msdn.microsoft.com/en-us/library/windows/desktop/ms682411.aspx Commented Jan 14, 2014 at 9:43
  • How about a public method that one project can call from the other? Perhaps he C# project has a dll which can be called (via reflection) from the C++ project, at run time, which contains a public method. The public method then asynchronously communicates with the main thread in the C# project and gets the information you need for the C++ project. Or the other way around, obviously. Commented Jan 14, 2014 at 9:54
  • It's easier to make a C# project use a C++ DLL than the other way around. Commented Jan 14, 2014 at 23:08

2 Answers 2

1

The simplest way is using stdin / stdout for this purpose. Just write the values to Console from the C# program and read it from pipe in the C++ program.

Or maybe you'd like to extend your project to C++/CLI (.NET-based C++ extension) and directly reference your C# library.

Sign up to request clarification or add additional context in comments.

Comments

1

As well as the other options outlined by the others, you also have the option of making the functionality of your c# code into a DLL and then calling that from your C++ code to allow you to use the functionality of the DLL to get network information. I have a how-to type link here on how to create a C# DLL. You can then reference said DLL in C++ and utilise its functionality as needed.

Hope this helps, and let me know if you need any further information:)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.