how to port VB code in C++ - c++

I want to use VB.NET code in win32 (C++) (I dont want to convert my code). I have heard about wrapping VB code in COM but i don't know how to do it. Also, I am not aware if there is an alternative (or any better) way of porting the code.
Any help is appereciated.
Update: I created a class library in vb and saved it as a dll after setting the comvisible attribute to true, then imported it in my c++ project and accessed the interfaces via COM
*thank you everone for helping me out !!!!!!! *

You cannot call .NET code directly from a native C++ application, so there is some work involved.
Of course, your question leaves us guessing at why you're wanting to do this, but unless you are still going to be using the library from a .NET application, I would be a strong advocate in favor of porting it (like your title suggests) to C++.
But if you don't want to do this, you have a couple of other options:
Write a wrapper around the VB.NET code using C++/CLI. This would probably be the simpler solution, especially if you're reasonably familiar with both the VB.NET and C++ languages.
Expose the VB.NET methods you need as COM functions, using the <ComVisible(true)> attribute. This is going to be a bit trickier to get going, especially if you're uncomfortable or unfamiliar with COM programming in C++. It's too much to explain in a Stack Overflow answer; investigate purchasing a good book on COM programming. And although you're using VB.NET, the steps are basically the same for C#, for which you'll have much better luck finding examples.

You can't directly port VB into C++, but if you are looking to just switch to a more powerful language and still use the GUI libraries, you can check out C#. It uses very similar code, and a quick google search provided me this program: C# converter. If you really need C++, you could probably then convert the C# code to C++, but there really wouldn't be a need to since C# is VERY close to C++. Just googling that I found this: C++ converter.
I hope this will help you.

Related

Using MFC in a "managed C++" application

One of our products is a C++ application - using MFC (MDI). (And we skin the application with Codejock.)
I've been asked if we could "port the application to .NET" - so it would be possible to use, e.g., C# libraries and other .NET features. I know there is something called "C++.NET" - or maybe (if I understand it right) it should be called "managed C++" now. But I don't know much about it.
My question: Is this at all possible? Could we run an MFC-application as "managed C++"? (And can an application using Codejock be run as a "managed C++" application?) There is some other threads about this, but I haven't been able to find "a definitive answer"...
I'd be very grateful for some good advice! :-)
As far as I understand, you want to keep your MFC/Codejock GUI and allow the use of .NET libraries from you application's C++ code.
This is indeed possible, but for a complete application that is currently compiled as "native" C++ it is probably not such a good idea to convert all of it to being compiled with C++/CLI. "It Just Works (IJW)" is a nice meme, but it doesn't work always :-)
We have the same situation, namely a C++/MFC/Codejock application that needs to call into .NET assemblies. This works mostly without problems:
We have C++/CLI modules that offer a native C++ DLL interface for the native C++ code to call into and that then route these call on to an assembly written in C#.
We also have C++/CLI assemblies that offer a .NET interface for the C# code and then call back into pure native modules.
It should also be possible to have a single (say, exe) project that is compiled natively and you only enable the /clr switch for selected cpp files that need managed interop. And at the end you link everything together. Since we've never mixed it that way, I can't really say anything about this approach however. What I can say for sure though is that it is possible to compile parts on a module as /clr and parts as native.
I faced a similar problem some years ago, and found that unless for trivial cases converting from un-managed to managed or reverse side was really painfull. I ended leaving the two worlds each in its side, and simply use interop to have the COM - .NET compatibility.
It was not very nice, but a lot cheaper. The conclusion that we should wait a major evolution to consider a full rewriting.

Is possible on easy way to program in c++/lua in unity?

I want to learn Unity but C# is not my first choice. Is possible to program in c++/lua in unity ?
I want to escape from marmalade to unity or shiva.
I will start by saying that C# is my favorite language and although I sometimes wish Unity could be fully programmed in C++ (especially when I need something that C++ would give) I do think C# lets you do almost everything you need but just a bit slower than C++.
You can make plugins with C++ but that is it.
Any particular reason why you want to do C++? Also if you know C++ you already know C#.
No it is not possible. Except for plugin development.
http://forum.unity3d.com/threads/68109-Unity-and-C
http://answers.unity3d.com/questions/12809/can-i-use-c-as-a-scripting-lanques-for-unity.html

Photoshop COM and C++ (How to)

I would like to use Photoshop via COM using C++, but I'm not sure if I'm getting it right. I've seen lot's of tutorials on how to do that with C# and even tried one but as far as I know ideology of COM says that you can use any language you like since it's source is just binary. So, C++ is exactly what I want and to start I should have a photoshop interface class in my client programm, right ? So, the question is: Where can I get it (interface class) ? And even if I had one, how would I know about functions to operate photoshop instance. Or maybe I understanding COM + C++ wrong ? Your help is highly appreciate.
Thank you in advance!
You are right, COM is language-neutral, but it requires a lot of extra runtime work to ask the OS for pointers to the interfaces and methods you need. COM is a huge pain in C++. You're looking at 5-10 lines of code for a single function call. Microsoft's "helper" libraries like MFC and ATL can help make it easier, but it's still not pretty.
C# abstracts a lot of the details away and makes COM look like regular object-oriented code. In C++, you'd have to write the wrapper class yourself or find someone else's implementation. It won't necessarily be hard, but it will be tedious.
I work with COM in C++ and I would jump at the chance to do it with C# instead.

Learn C++ when mastering VB.NET

I consider myself a master at vb.net, and now I'd like to learn C++. I know they are similar in many ways, so instead of starting from a standard "learn C++ Basics" which there are thousands of, and then move on from there on, as I have done with all other languages. I would love if someone could point me to a tutorial that learns, someone with knowledge in vb.net, C++. Or maybe a page pointing out the differences between the two.
Also, with them being similar, is their simple converter, that can convert code on line-base from vb.net to C++? I would like to convert my current asp.net website (less than 30 lines of code right now) project to C++, as I find the best way to learn is through doing it.
As #ildjarn and #GregHewgill pointed out, C++ is quite different from vb.net. C# and (to some extent) C++/CLI would be much closer (and despite the name, C++/CLI is not C++).
C++ (by itself) does essentially nothing to support web development, so converting an asp.net web site to C++ will most likely be a decidedly non-trivial exercise. There are frameworks (e.g., Wt, POCO, ACE) that support network and web development in C++, but I don't believe they have automated tools to convert from asp.net. In any case, converting a web site to C++ using one of these libraries is not going to teach you much about C++. At best, it's going to teach you about that library.
I feel obliged to point out, however, that if web development is your primary interest, C++ probably isn't your best possible choice. At the very least it's quite an unpopular choice for that purpose.
The typical answer for people who already know how to program in some other language and want to learn C++ is Accelerated C++ (but you may want to see The Definitive C++ Book List for other possibilities).

Is it possible to program iPhone in C++

I'm all for language diversity, but Objective C is insane. So I'm curious: is it possible to code iPhone apps with C++ while using the Cocoa API, etc?
Although Objective-C does indeed appear to be "insane" initially, I encourage you to stick with it. Once you have an "a-ha" moment, suddenly it all starts to make sense. For me it took about 2 weeks of focused Objective-C concentration to really understand the Cocoa frameworks, the language, and how it all fits together. But once I really "got" it, it was very very exciting.
It sounds cliché, but it's true. Stick it out.
Of course, if you're bringing in C++ libraries or existing C++ code, you can use those modules with Objective-C/Objective-C++.
Short answer, yes, sort of. You can use Objective-C++, which you can read about at Apple Developer Connection.
If you know C++ already, learning Objective-C would be pretty simple, if you decided to give that a try. More info on that topic is at the ADC as well.
I use Objective-C to slap the UI together.
But the hard guts of the code is still written in C++.
That is the main purpose of Objective-C the UI interface and handling the events.
And it works great for that purpose.
I still like C++ as the backend for the code though (but that's mainly becuase I like C++) you could quite easily use Objective-C for the backend of the application as well.
First off, saying Objective-C is "insane" is humorous- I have the Bjarne Stroustrup C++ book sitting by my side which clocks in at 1020 pages. Apple's PDF on Objective-C is 141.
If you want to use UIKit it will be very, very difficult for you to do anything in C++. Any serious iPhone app that conforms to Apple's UI will need it's UI portions to be written in Objective-C. Only if you're writing an OpenGL game can you stick almost entirely to C/C++.
Having some experience of this, you can indeed use C++ code for your "core" code, but you have to use objective-C for anything iPhone specific.
Don't try to force Objective-C to act like C++. At first it will seem to you this is possible, but the resulting code really won't work well with Cocoa, and you will get very confused as to what is going on. Take the time to learn properly, without any C++ around, how to build GUIs and iPhone applications, then link in your C++ base.
You have to use Objective C to interface with the Cocoa API, so there is no choice. Of course, you can use as much C++ as you like behind the scenes (Objective C++ makes this easy).
It is an insane language indeed, but it's also... kind of fun to use once you're a bit used to it. :-)
I'm not sure about C++, but you can definitely code iPhone applications in C#, using a product called MonoTouch.
You can see this post for detailed discussion on MonoTouch Vs Obj-C: How to decide between MonoTouch and Objective-C?
I'm in the process of porting a computation-intensive Android app written in Java to iOS6. I'm doing this by porting the non-UI parts from Java to C++, writing the (minimal) UI parts in Obj-C, and wrapping the former in a (small) C interface using the standard C/C++ technique, so that it can be accessed from Obj-C, which is after all a superset of C.
This has been effective so far, and I haven't encountered any gotchas. It seems to be a legitimate approach, since Xcode lets you create C++ classes as well as Obj-C classes, and some of the official sample code does things this way. I haven't had to go outside any officially supported interfaces to do this.
There wouldn't seem to be much to gain from writing my remaining UI code in C++ even if it were possible, in view of the help given to you by the interface builder in Xcode, so my answer would be that you can use C++ for almost all your app, or as much of it as you find appropriate/convenient.
Yes but Thinking that you can program every kind of program in a single language is a flawed idea unless you are writing very simple programs. Objective C is for Cocoa as C# is for .NET, Use the right tool for right job, Trying to make C++ interact to Cocoa via writing bridging code and trying to make C++ code behave according to Cocoa requirements is not a good idea neither expecting C++ performance from Objective C is. You should try to layout design and architecture of app keeping in view existing skills and determine which part should be written in which language then build accordingly.
I'm currently writing an Objective-C++ framework called Objective-X, wich makes PURE C++ iPHONE PROGRAMMING possible. You can do like this:
#import "ObjectiveX.h"
void GUIApplicationMain() {
    GUIAlert Alert;
    GUILabel Label;
    GUIScreen MainScreen;
    Alert.set_text(#"Just a lovely alert box!");
    Alert.set_title(#"Hello!");
    Alert.set_button(#"Okay");
    Alert.show();
    Label.set_text(#"Ciao!");
    Label.set_position(100, 200, 120, 40);
    MainScreen.init();
    MainScreen.addGUIControl(Label.init());
}
and compile it using GCC's appropriate commandline options. I've already compiled this helloworld app&it w0rkX0rz like a charm. ;-) It'll available soon on GoogleCode. Search for Objective-X or visit http://infotronix.orgfree.com/objectivex approx. a week later!
Updated (but apparently inactive) URL: http://code.google.com/p/objectivex/
It may be a bit offtopic, but anyway. You can program c++ right on iOS devices. Check out CppCode ios app - http://cppcode.info. I believe it helps to learn c and c++ and objective-c later.