Solved

Combining VB.net and C++ .net

Posted on 2004-08-27
2
237 Views
Last Modified: 2012-06-21
Can an application be built using C++ .Net and VB .Net code?  If so can someone point me to or give me an elementary example that shows this?  

Thanks.
0
Comment
Question by:hess586
2 Comments
 
LVL 2

Accepted Solution

by:
lgawlik earned 50 total points
ID: 11919529
Yes.  That is a key concept behind the .NET Framework.
You can have class libraries built in managed C++.NET and then have UI programmers write VB.NET GUIs to use your C++ (managed) code.

You can accomplish a test yourself by doing this.

1) Create a new solution
2) Add a new C++ Managed Class Library Project to the solution
  Within that Class Library add a class named Hello, like

// This is the main DLL file.
#include "stdafx.h"
#include "cppClassLibrary.h"

namespace cppClassLibrary
{
   __gc public class Hello {
   public:
      Hello() {
      }

      String* HelloWorld()
      {
         String* world = L"Hello World";
         return world;
      }
   };
}

3) Next add a VB Windows Forms Project named vbHelloWorldGUI
4) On the form add a label, leave the default name to Label1
5) Add a project referenece from your VB App to your Managed C++ project
6) Add this code to Form1.FormLoad, populates Label1 with the results of the Hello.HelloWorld property.

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim cppCL As New cppClassLibrary.Hello()
      Label1.Text = cppCL.HelloWorld
   End Sub

7) Execute

You should end up with a Managed C++ Class Library being called from a VB Windows Form application.
0
 
LVL 2

Expert Comment

by:dimitry_dimitry
ID: 11929143
Why not?
Add MC++ project to references, or as pre-compiled assembly, in case the project is not in your hands;)
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question