Question Including C.NET in my VB.NET Project, can't get it working

jeffulot

New member
Joined
May 31, 2013
Messages
1
Programming Experience
10+
Hello all!

I have an existing VB.NET project, using VS-2008. The project is ever evolving, and I've decided to integrated a light beacon by DELCOM PRODUCTS.

They provide a library of code, but it's in C#. They are telling me that VS supports combining the two, and that I can integrate their function library by following their steps below.


  1. Create your vb.net project.
  2. From the USBVIWINCS example copy the following files to you working directory.
    1. DelcomHID.cs, DeviceManagement.cs, DeviceManademenedDeclarations.cs, FileIODeclarations.cs, Hid.cs, HidDeclarations.cs
  3. Add the above files to your project. Use add existing option in Solution Explorer.
  4. Add ?Private Delcom As DelcomHID? in your code.
  5. Then call the functions. Delcom.Open(), Delcom.SendCommand(), Delcom.Close()

I've done steps 1-3.

But the "Private Delcom As DelcomHID" declaration doesn't work, no matter where I put it. I don't have any experience doing this sort of thing, so I'm hoping I can get some help here.

In step 2, when I add the C files to the project, they are added as "content" by default. I've tried changing that to "compile", which makes it not error on the Private Delcom declaration, but it won't compile/run. Many errors.

Am I missing a key element?

Here is the beginning of their form1.c file that would apparently work if I were using C. Maybe this will help someone recognize what I'm missing in the vb.net end.
-------
// Delcom C# USB HID Visual Indicator Example
// Dec 16, 2008
// This code show how to control the Delcom USB HID Device.

// Steps to make this project.
// 1 Create your project
// 2 Copy the follow file in the project source directory
// DelcomHID.cs, DeviceManagement.cs, DeviceManademenedDeclarations.cs
// FileIODeclarations.cs, Hid.cs, HidDeclarations.cs
// 3 Add the above file to your project. Use add existing in Solution Explorer
// 4 Add the following inside your namespace:
// DelcomHID Delcom = new DelcomHID(); // declare the Delcom class



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using HIDIOWINCS;

namespace HIDVIWINCS
{
public partial class MainForm : Form
{

private DelcomHID Delcom = new DelcomHID(); // declare the Delcom class
private DelcomHID.HidTxPacketStruct TxCmd;

Byte LED_GREEN_PIN, LED_RED_PIN, LED_BLUE_PIN;
....cut off here


Any help would be greatly appreciated.

Jeff
 
Last edited:
VS can support multiple languages in the same solution but not in the same project. Exactly what you need to do depends on your version and edition of VS. You will do one of two things:

1. If you are using VB Express 2010 or earlier then it will not load C# projects. In that case, you will have to use C# Express to load or create a class library project for that third-party code. You will build that project and it will generate a DLL. You can then add a reference to your VB project that refers to that DLL.

2. If you're using a version and edition of VS that does support projects using different languages in the same solution then you will be able to add a new project to your existing solution. You will then still add a reference to your VB application project but it will refer to the class library project in the same solution rather than the compiled DLL.

If you're intending to use this third-party code in multiple projects of your own without changing the code then I would go for option 1, even if your VS version and edition supports option 2. That's because, once you have the compiled DLL, referencing it in multiple other projects takes almost no effort.
 
Back
Top