Archived

This topic is now archived and is closed to further replies.

Last Attacker

C++ and VB

Recommended Posts

I heard that it is possible to kind of mix C++ and VB code in .NET . I was wondering if you guys know how to mix C++ and VB since I don''t like MFC and neither the slow performance of VB. It would be cool to do GUI easily with VB and put in the powerfull code of C++. Thanks // Last Attacker \\---=( LA )=---// LA Extreme \\

ICQ Number : 120585863

E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites
You have always been able to mix code through the use of com objects. Many people write a com object for intensive computations in C++, and then call it from the VB programs. I think what you are talking about is mixed mode. VS.Net will allow you to mix languages together as long as they are all compiled to the CLR. There was supposed to be another way where you can have C++ code that was unmanaged and have VB make direct calls to it. This can be very bad as C++ does not have a garbage collector by default. I have not tried it myself, but some friends that do application development state there is a bug in VS which does not allow this. It is supposed to be fixed in VS.NET.

Share this post


Link to post
Share on other sites
I remember reading that you can compile a dll in c++ and call it''s functions from VB- giving you the computing power of c++ and the easy-to-build features of VB.

Grant Palin

Share this post


Link to post
Share on other sites
You can make a DLL, and import functions ect. into VB, but as far as I know they must be in COM objects. And Your not really getting much of a difference from doing it all in Visual C++ for ease of use. Personally I find VB and VC++ are equally easly to implement simple UI stuff.

Pat - Ex nihilo nihilus

Share this post


Link to post
Share on other sites
quote:
Original post by patindahat
You can make a DLL, and import functions ect. into VB, but as far as I know they must be in COM objects.


You can simply declare the functions linking to the ones in the DLL. One little line of code.

quote:
That''s pretty much what MFC already is --> A mix of C++ (powerful language) and VB (RAD)...


"Rapid-development" is one of the last words I would use to describe MFC.

Share this post


Link to post
Share on other sites
I think the previous posters missed the mark - they are talking about C++ and VB6. LA asked about .Net. If you use C++ with Managed Extentions (and have VS2k3) you can use the _same_ RAD UI tools (WinForms) that VB.Net uses. VB.Net is a new language that is basic-like, it is not code-compatible with VB6 (what two version of basic are?), though some stuff is the same.

VB.Net is a real OO language - you can not only use objects but also write new ones. Part of the whole .Net idea is that you can easily write object in one language and use them in another -i.e. C++/ME and VB.net.

Formerly, you could use C++ to write a COM object and then it was pretty easy to use it in VB. I wrote a tut on how to do this some time ago, ATL COM tutorial.

Share this post


Link to post
Share on other sites
If you want RAD development for windows programs in C++ similar (but in my opinion better) than VB, you should look into the Borland C++ Builder programs. You can get full versions of earlier versions (such as 5 pro) on magazine coverdisks, else you'll have to pay for the newer ones. Its very useful for quickly making software tools for your own use, however in the version I have you have to find and distribute the VCL DLLs with you software for others without it to work.

Its an option if your willing to pay for the newer ones.

-J

[edited by - jason2jason on August 16, 2003 8:45:44 AM]

Share this post


Link to post
Share on other sites
Thanks MagMai for catching my point!
I didn''t really like MFC, its (from my opinion) very
complicated and I don''t know whats going on (It''ll take a very good tutorial to explain that to me .

I knew about compiling a C++ dll file and calling that from VB but I was hoping for something in the line of making 2 projects (one C++ and the other VB). I code all the heavy stuff in C++ and call it from VB and create all the objects that comes with the window.

Thanks for everyone''s reply.

If it is possible to do it like the way I hoped it would be, please don''t hesitate to reply.

Thanks again!

God bless!


// Last Attacker \\---=( LA )=---// LA Extreme \\

ICQ Number : 120585863

E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites
What don''t you use the java/c++ combination through the Java native interface.

I''m using it with VTK ( visualization ToolKit) with a very little lost of cpu. The big advantage is that your cade is cross-platform without changing anything ( if you use ansi c++ and not platform specific function such as GlobalAlloc or API such as directX). Even opengl support this combination

Crazyjul

Share this post


Link to post
Share on other sites
quote:
Original post by Last Attacker
If it is possible to do it like the way I hoped it would be, please don''t hesitate to reply.

It is, but I''m not completely sure how. First, you should have a solution that contains both your C++ project and your VB project.

.Net is object driven. The only C++ code that you will be able to call from VB will be the one found in your __gc classes. If you don''t know what __gc classes are, read about Managed Extensions for C++.

Even though you can''t call a regular C++ function from VB, your __gc classes have the power to do that, so they serve as intermediaries between non-CLR C++ and .Net. Your non-CLR C++ can also be unmanaged, to get better performance.

I think that if your C++ code is compiled to MSIL, you will automatically have an assembly in your project structure. (I may be talking through my hat here, but) This contains the signature of your classes and functions. I think that you don''t have to use it directly, but if you see it in your project, it''s a good sign.

Finally, VB.Net project needs to have a reference to your C++ project. Check the "References" part of your VB project tree, and add it there.

Cédric

Share this post


Link to post
Share on other sites
Thanks Cedric!
So what you''re basicly telling me is to check out these _gc classes and to add a Managed C++ project with VB.

BTW. crazyjul, I don''t know Java yet, I''ll start with that next year and will try to keep that in mind.

Cheers!

// Last Attacker \\---=( LA )=---// LA Extreme \\

ICQ Number : 120585863

E-mail: laextr@icqmail.com

Share this post


Link to post
Share on other sites