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

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!

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);
}
}

Related

Portable Class Library doesn't know ArrayList, StackTrace, etc

I'm hoping I just missed something in the README somewhere, but...
I have a library of VB.net code that I'm trying to package into a PCL, ultimately for use under Xamarin. The code is relatively straightforward, there's a lot of File I/O using streams and some SQL client code, and a smaller amount of UI and control related code.
So I made a new PCL project, but I was confused what to select, so I chose Windows Store and .Net 4.5. I then Add...ed the source files from an existing project. Now I'm getting errors on the most basic things - ArrayList does not appear to exist in spite of importing System.Collections, and StackTrace doesn't exist in Diagnostics. Even simple things like StringFormat and SortedDictionary aren't there.
Did I skip a step somewhere? Perhaps I didn't download the right libs from MS? Or maybe I have to manually include a Reference to something? Any ideas?

MFC: Steps localizing MFC APP with seperate resource dlls

Before anyone bashes me with, read this first and that second, I have tried following links below to achieve internationalization with MFC.
Creating resourse DLL:
Localization of MFC Components
http://msdn.microsoft.com/en-us/library/x6h91d9w.aspx
Localization for older MFC
htp://support.microsoft.com/kb/198846/en-us
I am new to MFC so please be kind with your answers. So in order to get localization with MFC 7 and above I followed these steps. (Currently using MFC with Visual Studio11)
Created a MFC Project (MyApp) with MFC in a shared DLL
To add a another language (German) to the app, I created a win32 Dll project (MyAppDEU)
Copied the resource file (MyApp.rc) inside same folder and renamed it MyAppDEU.rc
Added the MyAppDEU.rc file to the dll project
In resource view of MyAppDEU.rc, changed the VS_VERSION_INFO -> Block header to "Deutsch (000704b0)"
Changed some strings in the string table to see the difference when the main app loads
Changed the ouput of the MyAppDEU project to build inside the MyApp Output folder
Compiled MyAppDEU to get the Dll
Compiled MyApp with and without following the instructions from point 9
http://support.microsoft.com/kb/198846/en-us
So with all these done, I failed to see any difference in my Application. It loads with the English resouce file which I created the App with. My computer has a German Windows 8 OS. From what I know MFC has inbuilt multilanguage support with Satellite Dlls. I have the correct naming format ApplicationNameXXX.dll. The dlls are in the same directory as the exe.
I hope someone can see what Im doing wrong or missing here. I am fairly new to MFC and appreciate any help regarding this.
[answer adaapted from this SO answer]
I have used a slightly different approach successfully, skipping the MFC inbuilt multilanguage support with Satellite DLLs.
We have multiple DLL projects in our solution, each one containing just one set of resources for a single language (e.g.: AppRes_ENU.DLL). At run-time InitInstance(), we select the appropriate language DLL with code like
CString sResourceDllName;
// format sResourceDllName according to the language ("%s\AppRes_%s.DLL")
hInst_aRes = LoadLibrary(sResourceDllName);
if (hInst_aRes == NULL)
{ // handle <resoure-DLL not available>
return FALSE;
}
AfxSetResourceHandle(hInst_aRes);
and use hInst_aRes to load strings, dialog boxes, ...
Have a look at this software: http://www.apptranslator.com/ . It helps with localisation using satellite dll's; the documentation probably describes how to do it. It's quite simple once you figure our the relationships between ::AfxGetResourceHandle() and hInstanceHandle and all that jazz - the easiest way to learn about that is to read the MFC source. Then you write a few helper classes and off you go :)

active reports in C /CLI

Can we use Active Reports 7.0 in C++/CLI? I have just started using active reports. I tried building a report in C# without any problem. I tried doing the same in C++/CLI, but I am unable to use the Active reports toolbox. And also when running the application, it is giving licensing errors.
The designer that generates code-based won't work with C++/CLI. You also won't be able to write "script" inside the reports with C++. However, you can design reports as the XML-based reports (rpx) instead and then you shouldn't have any problem instantiating and calling on those from C++ via the SectionReport class (for example). Something like the following:
GrapeCity::ActiveReports::SectionReport ^sectionReport = gcnew GrapeCity::ActiveReports::SectionReport();
System::Xml::XmlTextReader ^xtr = new System::Xml::XmlTextReader("..\\..\\rptScript.rpx");
sectionReport->LoadLayout(xtr);
xtr->Close();
viewer1->LoadDocument(sectionReport);
...
Keep in mind ActiveReports users are almost exclusively C# & VB.NET users so you won't find any C++ code samples, but it should be pretty trivial to translate the code from C# to C++/CLI.
The example is based on SectionReport not PageReport, but PageReport is entirely xml-based so it should work easily too.
So to clarify, if you want a C++ only solution, you need to do the following:
Create your reports as XML-based reports (*.rpx files) using the "Standalone" designer application that is installed in the start menu when you install ActiveReports. Since you can save your reports as a standalone, independent .rpx file, you will not need to use any C#/VB.NET DLL. As shown in the code example above, you can just load the .rpx files from a file directly from C++ (for example).
Although this technique does not require any C# or VB.NET DLL/EXE, if you use the scripting feature inside the standalone .rpx report file, the script will have to be either C# or VB script. However, you won't have to compile that yourself, ActiveReports deals with the script internally.

Interacting with a specific COM DLL

I'm trying to interact with a .dll which will allow me to receive information from a variety of devices (Eye Gaze to be specific). The .dll is called ETUDriver and can be found at http://www.sis.uta.fi/~csolsp/projects.php however it does not come with an accompanying .h file.
I am struggling to actually load, interact and invoke functions from the .dll. A manual is supplied but it is of no help whatsoever with regards to actually setting up the code to start it off. There are three accompanying example apps (with source code) but only two of these work and one of which is in C# so is not helpful. The one that works however loads up the .dll via MFC and this is not a viable option with my code (which is intended to be used with many other projects and as such can't enforce MFC or any other libraries that are not as standard to projects).
Essentially, within the .dll is a series of classes which I need to create within my code and invoke the relevant functions of that class.
I've tried to use HRESULT hr = CoInitialize(NULL);
hr = CoCreateInstance(__uuidof(ETUDSink), NULL, CLSCTX_INPROC, __uuidof(IETUDSink), (LPVOID*)&pETUDSink);
if(pETUDSink)
{
pETUDSink->Start();
} however it always returns an error saying that the class is not registered. I can't use MFC to call the relevant .rgs file and am completely stuck on how to get this to work otherwise.
Is there a given format to doing this that I am unaware of and has anyone had experience in using the ETUDriver (or is able to get it working in C++ without use of MFC)?
Thank you for any help you can provide on this subject :)
I am not familiar with the specific DLL in question, but it sounds like you did not register the DLL on the target machine. You can do this by running regsvr32.exe or by calling the DLL's exported DllRegisterServer function or by using side-by-side assemblies. You need to do register the DLL on each machine that needs to leverage the COM functionality within it, so when you distribute your application, make sure that your installer registers the DLL if you go the regsvr32.exe route.
You can use the #import directive in Microsoft Visual C++ to load the information contained within the DLL without using a header file or rewriting it yourself based on documentation.

how to import COM dll in D

I'm trying to create an D application which uses a (third party) COM .dll so I can scrape a text box of another application so I can sound an error when a certain string shows up.
However the third party doesn't provide .lib, .def or .h files that go with the dll (atleast with the free trial version). I can create the .lib file with the implib tool but I don't see any of the library's functions in the created .lib.
Their (visual c++) samples use the #import directive to link it in however that is of no use for me ...
On a side note how can I get the proper interfaces (in a .di with boilerplate that does the linking) of the dll automatically? I ask so the correctness of the linkage doesn't depend on my (likely to be incorrect) translation of the functions. They do have a webpage which gives all functions but the object model is a bit chaotic to say the least.
From what I know, COM libraries only expose a few functions, required to (un)register the library and to create objects.
You can however view the interfaces and functions in a COM .dll using the OLE/COM Object Viewer. It seems it might be able to output header files (.h). Afterwards, maybe you could use htod as a starting point to converting everything to D interfaces.
The DMD distribution seems to include a .COM sample (chello.d, dclient.d, dserver.d), and at first glance it doesn't look like it would require any LIBs explicitly.
Unfortunately, I've never actually used COM in D, so I can't advise any further. I hope this helps in some way.
While I have yet to actually do COM work myself, I am trying to revive Juno over on Github/he-the-great. Part of the project is tlbimpd which is what will output a D file from a DLL.
I've tested the examples and successfully run tlbimpd. Please do try things out for your use and submit any issues.