Porting a Visual C++ project to C# [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I got my hands on some well documented C++ code that's about 1KLOC. It would take me a significant amount of time to port this line by line and debug the results, so I'm wondering if there are tools or ways to do it faster, and I have questions in case I have to do it fully manually.
Specific questions:
Does C# also support overriding operators like * and +?
What to do with the C++ memory management code like alloc() and free()?
How to identify functions used from <stdio.h>, <conio.h> and <math.h>?
How to find replacements to such system functions?
Does C# have any special/open source libraries that provide such functions?
No graphics libraries have been used, its purely command line based.

You might want to try this tool and see if that works out for you. There is a demo where you translate up to a 100 lines of code at a time:
http://tangiblesoftwaresolutions.com/Product_Details/CPlusPlus_to_CSharp_Converter_Details.html
Try it out and let us know. But it would prolly be more beneficial to port this yourself in c# so you can get a handle of the features that c# comes with.

You will need to do it manually, and 1KLOC isn't much.
However, you will need to learn C#.
To answer your questions:
Yes
Depending on what you're doing, probably List<T>
I don't know what you're asking
Look in the .Net Framework class library on MSDN
Yes

1 - C# also support operator overloading see : http://msdn.microsoft.com/en-us/library/aa288467(VS.71).aspx (it looks very much to c++ operator overriding)
2 - C# is garbage collected so you only need "new" instead of alloc. free is done by the garbage collector
3 - I have no idea , but when porting code you would have to find in standard c# library the equivalents
4 - In MSDN there is a lot of information.
5 - ( http://code2code.net/ ) ??? but better to do it at hand
More information on coding standards : http://msdn.microsoft.com/en-us/library/xzf533w0.aspx
ie naming: http://msdn.microsoft.com/en-us/library/x2dbyw72.aspx

Related

Dynamically creation some code during runtime [duplicate]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I work in a code base that is quite large and today I found a project that was emitting IL code inside a normal class.
The project containing the IL code being emitted was a implementation of a Service Locator MSDN Desctiption.
What are the advantages of doing this and why would this be done as apposed to using the C# language?
Typically this is done to circumvent the overhead of using reflection, using information only available at runtime.
You would then use reflection, which can be slow depending on what you do, to build a new piece of code that works directly with the data given to it, without using reflection.
Advantages:
Performance
Disadvantages:
Hard to debug
Hard to get right
Hard to read code afterwards
Steep learning curve
So you need to ensure it's really worth the price before embarking on this.
Note that this is a general answer. In the specific case you came across, there is no way to answer why this was done nor which particular advantages (or disadvantages) you would have without actually seeing the code.
There are many uses for this.
One of the more often used scenario is for changing/injecting code on the fly:
.NET CLR Injection: Modify IL Code during Run-time
A good tutorial that help me to understand a good use for it is:
Dynamic... But Fast: The Tale of Three Monkeys, A Wolf and the DynamicMethod and ILGenerator Classes
Good luck

How can I protect my .NET Core 2.1 Code from reverse engineering in 2018 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm currently working on a .NET Core 2.1 application in C#. I want to protect my application source code from copy piracy. In general, I know that C# can fairly easy be reverse engineered. I need to ship my final software product to the customer, but I don't want anybody to read my source code. The software will be installed on a Windows Server, I cannot provide remote access as it is hosted in a closed environment (no internet there).
How can I protect my software from reverse engineering?
What do you do or which tools and frameworks do you use to secure your .NET Core 2.1 source code from piracy in 2018?
Is it still worth it to obfuscate your code?
Should I rather just write a secure library for my business logic in C++?
Thanks for sharing some ideas!
Is it still worth it to obfuscate your code?
This is a matter of opinion, but in my opinion, no, it's not worth it.
Have you ever tried decompiling .NET code? Sure, it can be done with tools like JustDecompile, but it doesn't decompile into your original source code. It's actually quite difficult to read. Give it a try.
Even C++ can be "decompiled", although yes, it's even harder to read.
But the bottom line is this: if someone really wants to reverse engineer your code, they can do it and there's nothing you can do to stop them.
In two words, You can't
In more words
There are things that will constrain your application to certain conditions as can be using hardware keys or network boundaries
Take a look
Protect .NET code from reverse engineering?
In a word, no. But you can use a code obfuscator, and if you are really intent, going into unmanaged code and trapping the debug interrupt.
I am assuming you need to protect trade secrets. The use of non-compete agreements protect you to a large extent, along with contracts.
You will almost certainly be protected from all but the most determined with the above safeguards.

How to organize F# and C# side by side [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
The project I am working on will have to be migrated from C# to F# based on what brings food on the table tomorrow - in other words, the two languages have to live side by side in this project for years to come.
The problem I am faced with repeatedly is how I should organize projects in the solution to meet this need.
I translate pieces from C# to F# all the time, because it frequently shortens the development time and increases the quality. But I end up with C# code that wants to use F# code, and F# code that want to use C# code, in the same layer, or at boundaries between layers or modules. I find myself putting code in the wrong projects just to avoid creating yet another project in some layer.
The situation is not bad now, but I worry that I will paint myself into a corner at some point, unless I can come up with a pattern or a structure, or simply understand the problem better.
Is there some modification to a normal F# architecture - a pattern, a substructure or a superstructure - that is well suited to such a mixed solution?
Are there patterns that are known to be especially helpful in solving this particular challenge?
Use an interface to communicate between the two languages.
Typically when porting, f# is the lower-level dll and C# can call f# as usual.
Now for f# to call c# define an interface in the f# dll (e.g. IClibApi) that is implemented in c# (e.g. ConcreteClibApi extends IClibApi). Create an instance of ConcreteClibApi and pass it to f#. Now f# can call c# thru IClibApi.
Later you can start porting ConcreteClibApi :)

Can C# do everything C++ can do? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm a C# programmer for a few months, and lately I've been considering learning C++.
So my question is, is there anything C++ can do that C# can't do?
I know about the manual memory management in C++, but as long as I don't program operating systems or extremely heavy memory applications, I shouldn't worry about that too much (becuase I heard .NET handles automatic memory management very well).
But, can I program in C# everything that I can in C#? I also mean things like DLL injection, Registry Editing, Drivers and things like that.
Is C# considered as powerful as C++? If not, what can't C# do that C++ can?
C# and C++ are languages. It's somewhat elusive to define what a language "can" and "can't" do. One example of a thing that C++ can do and C# can't, is free the memory of an heap allocated object at will, without freeing other unused objects as well. But it's a thing that won't matter most of the time. (You can use Marshal.AllocHGlobal and Marshal.FreeHGlobal to allocate and deallocate memory like in C.)
The main reason why C++ can be used to write things like Windows drivers is because this is what Windows supports and facilitates. If one day Microsoft decided to support only C# and ditch C++, we'd be here saying that C# can do something that C++ can't (even if the languages magically remained as they are now, by then). Most likely it won't, and rightly so, because C++ is better fit for systems programming than C#. But hopefully you get the point.
Essentially, it's not a matter of the languages themselves, but their implementations, their tools and the world around them. For example, you can easily write an operating system in C#. Why? Because there's a proper tool for it. You can also write for embedded systems with non-real-time requirements. It has nothing to do with the language, again, it's because there's a tool for it.
That being said, do learn C++. Regardless of how it compares with other languages, it's absolutely useful.
C# is a slightly higher level language that C++. Its requirement of a managed runtime environment means that you wont be able to write an operating system, or even a device driver, in it. This sort of area is typically known as systems programming
However, there is a Microsoft research project currently underway into creating a systems program version of C#. It's headed up by Joe Duffy, the Windows threading guru, and if the rumors on the web are to be believed it will be called M#. Joe has posted some information about his progress on his blog.

Is there a way to write an LLVM front end compiler in C#? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Is there a way to write an LLVM front end compiler in C#?
I don't see why not. There is a language reference for LLVM and as long as you are compliant with the language, there is no reason you can't write something in C# which will parse that language and either:
Produce output based on the language (like a real-time interpreter)
Create an assembly in C# which will execute the LLVM instructions
This isn't to say it will be easy, but it can be done.
There are two ways. You could P/Invoke LLVM's C bindings (more than enough for implementing a compiler backend), or you could write your own wrapper with C++/CLI.
I used Clang-generated XML AST dump for LLVM's C bindings headers to generate .NET bindings for them automatically. But it is not possible to do it any longer, as XML AST printer had been removed from Clang, with no replacement available.
If you are looking to have a LLVM compiler FOR C#, Mono 2.6 can use LLVM

Categories

Resources