Using C++ Code


Quite simple question:

I’ve got a code done in C++ which is “basic” C++ (no special library used)…

I’d like to use this code in my embedded application.

I guess I have two options:

  1. convert the code from C++ to C#…

  2. integrate C++ code inside my C# Application (Net Microframework of course)

My question is easy (maybe not easy to answer but easy to ask):

What is the “better” solution ? Rewrite or integrate ?

If integration can be done ? any clues will be welcome…


PS: No access to hardware from my code, just treatment on data…

With NETMF, you can’t program in C++ or use C++ assemblies, at lest not anytime soon. So you will need to rewrite your code in C#, which shouldn’t be too difficult.

Now, GHI offer something called RLP which allows you to write code natively and load on the system. This is only available for advanced users and it is only recommended when it is absolutely necessary. A good example on when RLP is used is for an MPEG video decoding library.

if your code is long, there are some online c++ to c# converters that you can save some time by using them. then you will just have to tweak your code to make it work.

ok… thanks for your answers

I guess rewriting the code in C# won’t be that difficult…

The fact is that the code I’m talking about is dealing with raw data of a ublock chipset (which means raw data (not NMEA) of a GPS chipset). I guess the code might be “full” of rotation or bit treatment… anyway, it’s nothing that can’t be handle using .Net…

Guess I will choose the “conversion” option.

Thanks guys (again)

Sounds like you are doing something similar to what andrejk is doing. He might have some “hints” for you.

I’m parsing NMEA data but I’m working on prototyping a library to better handle binary data (avoid churning out a bunch of strings and the slow .netmf parsing libraries). This does sound like an ideal use case to incorporate into this to-be-developed library. Thread:

How do you get the data (UART? I2c? SPI?)

hi guys

I’m not using NMEA because the chipset I use (GM862 from TELIT) provide an AT command in order to get the position.

I’ve dealed in the past with NMEA but on a PC, not embedded stuff…

But the needs of a new project, I will have to process raw data of the GPS directly in C#. First, I will see if I can get these data (raw data) from the TELIT Module and if not, I will use a ublock chipset connected through USB port… but will still have to use byte processing… But the code is not from my company but from a partner and currently, I don’t have it so I can’t tell what will me my needed to convert this code into C# code…


If you find that you have a lot of small tight loops to parse that data, you’ll be better off finding native methods to do as much of that work as possible. For example, GHIElectronics.NETMF.System.Util has methods like ExtractValueFromArray and InsertValueIntoArray that are much more efficient than writing that code yourself in C#. We’re talking about expanding that functionality.