Monday, July 19, 2010

VB 6 COM w/ C# libraries

Ok. As much as I love Visual Basic 6 (sarcasm), I was put on a project to ensure that a vb6 app that used C# COM objects compiled and ran.


1. The C# projects, [I used VS 2008], needs special settings in order to work correctly with Visual Basic 6.

a. Go to the project settings. Go to the Compile tab. Go to Advanced Compile option. Change the target framework to 3.5.

b. Visual Studio 2008 changed the location or rc.exe [If you don't have it, you can install the SDK of the .NET framework]. You have to find it on your computer. In the Compile option, there is a 'Build Events...' button. A dialog box appears, and in this box, in the "Pre-Build event command line:" section, there is logic to find rc.exe. Delete all text. Put in --> "[rc.exe location]" /r "$(ProjectDir)InteropUserControl.rc" Now substitute the rc.exe path for [rc.exe location]. /r and $(Project... is exactly the same for all libraries.

c. In References option, remove the Microsoft.InteropFormTools reference.

Ok. Recompile the project. This must be done on the machine that you are going to develop the vb6 on, otherwise, vb6 won't recognize the library.

2. Regasm is a tool that adds assemblies to the registry. Well, when you compile the *.tlb and *.dll files from .NET, use the Visual Studio command line tool. Navigate to the /Release folder of the desired project. Use the command regasm /regfile [dll file name] [reg output file name]. You must have the regasm path in the Environment Variables on MyComputer properties. Regasm with make a [filename].reg. This will be used in the vb6 app to register the COM objects.

3. The Package and Deployment Wizard for Visual Basic 6 is finicky. I couldn't find where to choose the location of the .NET dlls in the *.reg files. I mean, I wanted to be able to choose where the registry knew where my .NET COM object dll files were located, but I couldn't find that. Therefore, I had to change where my dll files were installed. The .tlb files were installed into the /system32/ folder and the dll files were installed into the /apppath/. I'm sure there is a way to change the directory path, but I didn't spend that long on the project.

I may have forgotten a step, if so, I'll update soon.

No comments:

Post a Comment