Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Combining VB.net and C++ .net

Posted on 2004-08-27
2
Medium Priority
?
270 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 150 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

810 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