using a legacy (VB6) DLL in new visual studio express (C++ prefrred) project

967 Views Asked by At

I've got an old legacy application for communicating via serial port to an embedded controller communications bus. that someone else developed.

The application is written in VB6, and is structured as two projects - a DLL to handle the connection and communications logic, with an application GUI project.

I was hoping to be able to write a new application GUI (in C++ ideally) to use the existing DLL as-is, but I'm having lots of problems working out how to import it.

So I'm wondering, is it even going to be possible to use this old DLL into a C++ project as is? or is it possible to import into a C# project? or a VB.NET project? (would prefer not to use VB, but can if I have to)

Where I am now:

I have the existing compiled executable and DLL, and these run on my system.

I also have the project files, and they're all readable in notepad++ but I don't have VB6, and importing the project into visual studio VB.NET 2008 express isn't at all straightforward. Especially not without a working example to dig through and play with first (DLL project may be importable, but has 50+ things indicated as needing changing in the upgrade report. It also seems to be ignoring three .cls files that look very important to my not particularly VB6-savvy eyes... The application project has a message in the upgrade report about something "missing a design time license" and the only project files that actually seem to come into the project explorer for imported project is the project file itself, and the assembly info file.)

Most examples of how to import a DLL into VS C++ assume you have a solution with the DLL project all compiling nicely alongside your project that will use it. Or at least a .DLL and .lib and .h file... I spoke with the original developer of the code (in another city, we don't work directly) and got a .lib to match my .dll, but still have no .h file.

I'm usually fine to bash through something new, but without a baseline working example of the project even in VB6 that I can get my understanding from, it makes this very hard. Also a lack of similar questions anywher google can find them on the net makes me wonder if this is something i should be even attempting.

I'm working on getting a non-express copy of visual studio if that will make any difference (express worked fine for everything up until now so I never needed anything more) but that will take a number of weeks, most likely.

Any suggestions would be very much appreciated.

thanks for reading!

1

There are 1 best solutions below

1
On BEST ANSWER

I have to disclaim this as I have no experience doing it, but merely found that it should be possible given some reading of the docs on the subject.

I'm not sure you'll have much luck with the VB to .NET import/conversion process if there is a lot of low level stuff going on. The existing dll is likely a COM object, no?

It seems like there is some MSDN documentation to get you started from C++ using COM object dlls - and it looks like the #import directive will generate some .h (header) files as well.

http://msdn.microsoft.com/en-us/library/8etzzkb6.aspx

So I would try simply adding an #import directive for it.

#import "somelibrary.dll"

and see what visual studio generates.

Have a look at the following example as well, (copied shamelessly from another forum)

 #import "F:\proj\VB6\ActiveXDLL\VBTestDLL.dll"
 using namespace VBTestLib;

void CDialogTestDlg::OnButton1() 
{

 HRESULT hresult;
 CLSID clsid;
 _CTest *t; // a pointer to the CTest object
 _bstr_t bstrA = L"hello";
 _bstr_t bstrB = L" world"; 
 _bstr_t bstrR;
 ::CoInitialize(NULL);
  hresult=CLSIDFromProgID(OLESTR("VBTestLib.CTest"), &clsid);
  hresult= CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,
                               __uuidof(_CTest),(LPVOID*) &t);
  if(hresult == S_OK)
  {
     bstrR  = t->vbConcat(bstrA , bstrB);
     AfxMessageBox((char*)bstrR);
   }
 }