I have to convert a C# project to VB.NET and VBA. It's a console app that uses the Microsoft Office API (Microsoft.Office.Interop.*).
My two questions:
C# -> VB.NET: .NET Reflector is a good tool for this, except that it doesn't preserve source code comments. Is there a way to do this?
.NET -> VBA: is there an automated tool to do this conversion? It would need to be a client side tool (because the code is proprietary).
The best conversion seems to be done by SharpDevelop. Open your project and from the tools menu and select convert code to. Since it has all of your c# source code it does a very good job.
There are many ways to convert C# to VB.Net; for example, try Developer Fusion.
It is not possible to automatically convert C# to VBA because the environment, language, and libraries are radically different. However, you could expose the C# code as a COM server and call it from a thin wrapper in VBA.
Answer for question #1:
You cannot use Reflector to preserve source code comments because Reflector is disassembling the compiled code, which has had all comments removed.
Consider using a commercial tool like InstantVB, which will converts C# source code into VB source code (including comments):
http://tangiblesoftwaresolutions.com/Product_Details/Instant_VB.html
You could convert the C# source code to VB.Net manually with this:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
which will preserve comments. As far as automatically converting C# to VBA or VB6, I'd be willing to say that that is almost certainly going to be completely impossible. There are many aspects of C#/.Net that are not available in VBA or VB6 (like inheritance, for one).
Related
My company has a major problem. We developed an application consisting of more than 1.000.000 lines of code in Delphi.NET. Because of this we are stuck with Delphi 2007 and .NET 2.0.
As technology and usecases are moving on we need to migrate to another development platform. So far we tried several tools which promised to convert Delphi.NET to C# code - each of this tools had several problems like wrong indexing of strings (Delphi 1 C# 0) or when types were used to declare array boundaries.
After that approach we tried to decompile the Delphi.NET assembly - the code that comes back from that is hardly readable and has hundreds of helper functions which call into Borland specific assemblies. I already looked at the possibility to write a transpiler myself, but the ambiguous syntax of Delphi is too hard to implement in a straight forward grammar.
So now the great question, is there any possibilty left that does not include translating all of the code by hand? Or maybe a migration path which allows to migrate partially and stepwise?
Check out tools like:
http://www.9rays.net/TourStep.aspx?TourStepID=21
While it may not be as simple as running your entire Delphi app through it and getting C# source in return, these kind of IL translators / decompilers are pretty accurate. My advice would be to run a few assemblies through and regression test to spot check accuracy. Chances are very high that you'll have to do some remediation in the generated code, but it's better than rewriting the entire application.
Also: check out http://blogs.msdn.com/b/danielfe/archive/2004/06/15/156087.aspx
I have a c# dll that needs to be called in Java.I see that there is a method using jni to call c++ dlls.How can I do it for a c# dll..Please help..I couldnt find any good material on this
From here:-
IKVM.NET is an implementation of Java for Mono and the Microsoft .NET
Framework. It includes the following components:
A Java Virtual Machine implemented in .NET
A .NET implementation of the Java class libraries
Tools that enable Java and .NET interoperability
You can use Java Native Interface. Or you can create a COM assembly from the C# code and use J-Interop to invoke it.
If you have C# dll sources you need to use maybe the better way will be to translate it to Java using some tools like GrassHopper.
According to GrassHopper key feature explanation it can convert MSIL to Java bite code. So can use without sources of c# dll
Check this: http://www.javonet.com
If you look for quick and easy solution then Javonet should work fine for you. It is light counterpart of IKVM and J-Integra works also as native bridge.
All you have to do is:
add Javonet.jar do your project call
call Javonet.addReference("yourlib.dll")
use your .NET library like it was almost JAVA package
Sample:
NObject obj = Javonet.New("yourDotNetClass");
obj.invoke("YourMethod","arg1", 2);
The syntax is not strongly-typed and works like reflection but gives you fastest access to any custom .NET code, third-party libs or .NET framework as no changes are needed on .NET side. If you need it is also possible to implement custom strongly-typed wrappers.
I do recommend this bridge as in my opinion it is easiest to quickly get things done but also other native bridges are worth checking as this is best approach for such case.
I would avoid going into custom JNI or COM unless you have a lot of time and you just want to learn, if you need quick and reliable solution take one of third-party bridges.
I want to create a deskband COM object for my pet project. I don't have any experience with COM and a quick search revealed that ATL will simplify things. I was wondering if there are any better ways to create a COM component today. Better in the sense less boiler plate, use of C# instead of C++ and any other things you may think of.
If deploying or relying on a .NET framework installation on the client machine is not an issue for you, than C# is much easier than C++ (although you will probably have to redeclare interfaces, IID, etc... in C#, using P/Invoke). If reducing dependencies is an issue, than C++ with ATL is better.
Just create it in C# and expose as a COM component, see this guide:
http://msdn.microsoft.com/en-us/library/zsfww439.aspx
The only reason I would consider C++/ATL is if I were connecting to any C/C++ libraries. Other than than I can't think of a strong reason to use C++ over C# (assuming your skill level is equivalent in both).
I can only recommend C++ in conjunction with Microsoft's ATL library.
I used some code generation tool written in C++ that helped me to get rid of quite a lot of boilerplate code. This tool generated code that produced more C++ friendly interfaces (like the code that gets generated in the tlh/tli files when you #import a type library in Visual Studio. My code generator produces similar code, only for COM servers.
If you are interested, send a mail to DerTopper at web dot de. Put something like "COM code generator" in the subject line, so that you won't fall through my spam filter.
Regards,
Stuart
I'm building an c# app that is designed to replicate and enhance the functionality of an VB6 app developed many years ago.
My problem is that one module in the old app does some realy complicated things and trying to replicate this starting from specs would be a big pain for me. Even if this sounds like the best idea.
My question is : is there a way i could keep the old VB module and integrate it into the c# app, so that i wouldn't have to rewrite everything ?
Thanks!
Yes. You can turn the module into a COM object, and .Net will happily call into COM objects. Depending on what you have right now you may need to find a copy of Visual Studio 6 to make that happen (it's still available on MSDN if you have a subscription). To give you more exact instructions we'd need to see more of your code.
Visual Studio has a wizard that allows you to convert VB6 into VB.NET, which you could then reference in your C# project and use. However, this migration tool is no longer shipped with Visual Studio 2010 (it was shipped in older versions) Even still though, there generally is a lot of manual touchup work required, you are generally better off rewriting it by hand which could result in higher quality code, anyway. My recommendation to you is to rewrite the code, you can make touchups and make sure that it works correctly without having to go the COM/Interop route, but don't necessarily shun that option either. If rewriting all the code really is an issue, then interop is a solution.
You can use COM or export the module as a DLL. Here's some information for you regarding VB6 and COM.
In theory yes, turning it into a com module, and calling it from your c# code. Whether this would be easier or not, I am not sure.
The problem is that this issue will not go away, and if there are changes needed to the module, or the interface, then someone has to do it. So practical yes, but consider carefully what you are doing.
You can migrate the existing vb code to vb.net and compile it as a separate assembly and add it to the C# application.
Can't VS2010 (maybe 2008) support both VB and C# projects in the same solution? If I'm not mistaken, they can. So you could actually convert your VB6 code into VB.Net and have the project in your solution with the C# stuff.
We have developed a C# class library on VS 2008. We want the same functionality as a C++ library on Red Hat Linux. How do we accomplish that?
I am sure we are not the first to migrate C# to C++. Are there any automated tools to convert the source code?
We know about Mono, but we would very much prefer C++ source code.
About 15% is the useful code, the rest 85% are unit tests using NUnit.
At the very least we do want to migrate all the unit tests as source code.
We used Reflector, which did almost all the work for us. The only thing it screwed up were constructors.
Consider the following C# code:
public MyClass() : this(1,2,3){}
it should be converted to
public MyClass() : {this(1,2,3);}
but Reflector converted it to
public MyClass() : {MyClass(1,2,3);}
um, are you asking for a general-purpose c# to c++ code converter that also switches platforms?
No problem, it's called a human, and you can hire or contract one from many different locations.
You may also want to look at the Mono Project, which has a fully functional c# compiler and .net runtime for various other platforms (including RH Linux). This way you would not need to recode the library into c++, although you may need to change the code in small ways if you're using things that mono does not support.
You can get a head start by first converting to C++/CLI (the .NET flavor of C++). Red Gate's .NET Reflector supports conversions between .NET languages (you need a plugin to decompile to C++/CLI) and there are other tools as well.
I don't think there's any way to automatically translate C# to C++, if that's what you're asking, so I don't think you could get the C++ you want without manually writing it. Maybe you can use the C# itself instead via Mono...?
Unfortunately, I'm not aware of any such tool. However, translation from C# to C++ should be easier than C++ to C#. The features C# supports but C++ doesn't (say, reflection, and defined behavior in certain cases -- like order of evaluation) is much smaller and easier to work around than the features C++ has but C# doesn't (looking at just C++ templates, you have template functions with the ability to deduce type arguments, passing compile-time constants as template arguments, partial template specialization, complete template specialization, CRTP, substitution failure is not an error, etc.).
Is there a particular reason you prefer C++ in RHEL ? If not Mono is a better solution.