I have a vb.net class library made in visual studio that I've made COM visible and it is recognizable through excel vba on my computer. The next step I need to take is allowing anyone at the office to have the capability of referencing the class library from their computer in an excel document and I am not sure how to accomplish this. I have read a little bit about publishing the class library, however that option is not available for me to click on in visual studio for my class library. Any push in the right direction is greatly appreciated.
You can copy the assembly to each computer and then register it for COM with regasm. If your assembly has other assemblies upon which it is dependent, and they are not in the GAC, you'll need to use the /codebase option when registering it.
Related
I developed a class library in Visual Studio 2019 using the .NET framework. Before building the project, I registered the.dll file to interop COM, and this process gave me a .tlb file. This class library was developed in VB.NET, besides that, it has a simple code: one class with one function (class calcular, function Soma):
It was possible to include the .tlb file in the reference of VBA and I develop a code in this language that uses the class of VB.NET to build the action of the button:
On the other hand, when I execute the code in VBA Excel it shows this message:
If a press the button debug "Depurar" VBA mark the line of the instance of the class
I read other questions about this error but there isn't a way to solve it without change my machine?
ADODB.Connection in VB6 - Open Method fails with Runtime Error '2147221164 (80040154)'
VBA Selenium "class not registered"- 80040154
I already made a repair in my MS Office getting to uninstall to install again, can you help me to solve this error that prevents a run of my library in Excel VBA?
.NET COM visible dlls should be registered using regasm utility with /codebase option.
Assembly Registration Tool
You must register the DLL before it can be used. Every time you compile a new version you need to run:
regsvr32.exe "fullPathAndFileName.dll"
You can add a post-build event to the Release in Visual Studio so that it registers the DLL every time you make a new release. If you are distributing this for others then you will need an installer that puts the DLL in to a proper location and then registers it.
You can unregister it by adding the /u flag
Microsoft Topic
Context
I need to create a vb6 ocx control and use it in vb.net.
Essentially, it is a collection of methods for drawing on the old vb6 PictureBox.
Once the .ocx file was created, I recorded it with the usual regsvr32 procedure and imported it into the Visual Studio toolbox.
I can add the new control to the form without any problems, and it runs.
Problem
If I add a button and in its click sub I call a function of the control (which should, trivially, draw a line on the picturebox) an exception is thrown:
System.IO.FileNotFoundException
Could not load file or assembly 'Interop.VBRUN, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
Attempts
I tried copying all the control code into a new project and exporting the ocx again. No result.
I tried to use the control on Visual Studio 2008 and on Visual Studio 2019 (both on windows XP and on Windows 10). No result.
I tried to comment out most of the ocx control code and leave only a few methods active. No result.
I tried to use the control in a vb6 project. It works perfectly.
I tried trying to import this Interop.VBRUN as a reference, but I couldn't find it anywhere.
Notes
I use Vb6 on a virtual machine with Windows XP. I've tested the ocx in Visual Studio (2008 and 2019) on this virtual machine and and outside of it (on Windows 10). My settings:
destination Framework = .NET Framework 4;
destination CPU = x86
I also searched on stackoverflow and around the web for a solution: there are very few similar results, but none with a valid solution.
Questions
How can I resolve this problem? What is this Interop.VBRUN? Is the problem caused by the code (which I should then rewrite) or something else?
I used aximp.exe to put a wrapper around a vb6 *.ocx. Maybe give it a try?
I've written a DLL that provides methods for extracting data from a MySQL DB and generating a report using the built-in report viewer in VS 2012. The idea is to use this in a VB6 program. I've gone through the following process:
1) Build the DLL in VS with "register for COM interop" selected
2) Placed the DLL and TLB file in the directory of the VB6 program on another machine
3) Used regasm: "regasm Report.dll /tlb: Report.tlb /codebase" (redundant step if I already have the TLB file generated by VS?)
4) Added the TLB file to project references in VB6
The VB6 program builds and executes okay, but when I got to run my report I just get "Automation error: the system cannot find the file specified".
I've gone through the above process for a trivial DLL according to the instructions given here. This worked fine. I suspect that the references used in my DLL (MySQL.Data and Microsoft.ReportViewer.WinForms) may also need to be registered on the VB6 machine. I've been able to do this with MySQL.Data but not the ReportViewer DLL.
If it makes a difference, the DLL was built on a Windows 7 64 bit machine whereas the VB6 machine runs XP 32-bit.
Thanks in advance.
Turned out the problem was that I needed to set the Copy Local property for Microsoft.ReportViewer.Common and copy the relevant DLL files along with my own DLL. Hope this helps anyone with a similar problem.
I am programming a Windows Form Control Library in Visual Studio 2010. I checked the box for registering as COM element. Building the solution also adds this to the registry. I am now writing a .bat script to add the output .dll to the registry on other computers. Concerning this I have the following question. Is registering this .dll using the resasm.exe the same as the registeration process used by visual studio when building the solution? I have used
regasm.exe "pathtodll" \tlb "pathtodll.tlb"
Can someone explain if this is correct or maybe tell me what visual studio 2010 exactly does when building the solution (in terms of registering dlls)?
Thanks
Found my mistake. I checked the register for com interop in the compile tab. Which appareantly means that the registering using regasm.exe is done via the following command:
regasm.exe pathToDll /codebase
I am not quite sure why and am not a registry expert. If someone can provide comments on the difference between this command and the one I used in my question (in light op registering Com elements) please do so.
As for solving my problem. This did the trick.
I have one problem in vb6. I created a .tlb file in VB.net 2005 by adding Com class to project. I built the project, I got .tlb file and .dll files while building project, i selected "Register for Com interop" from project properties and built. It registered autometically and I can use created .tlb file in that PC in Vb6 working fine. if I deploy application to another PC and run I am getting "Error 429 ActiveX Component Can't create object" run time error. What I need to do? Please help me as soon as possible. I can't deploy the application to client due to above error.
one possible solution is to install .net frame work on client pc i never want to install .net framework any other solution will be most appreciatable.
If you've created a DLL in a .NET language (such as VB.NET), the target computer must have the .NET Framework installed in order to use the DLL.
This a hard and fast requirement, irrelevant of how you're utilizing the DLL, whether from a VB 6 application through COM interop or otherwise. It is also a hurdle you'll have to jump over first, before you worry about things like registering COM components, as Uday's answer suggests.
If you don't want a dependency on .NET, you need to use another environment to create the ActiveX DLL; either C++ or VB 6 are possible choices.
One option may be that, while deployment, you need to register that .tlb file in System Registry using regsvr32 command in command-prompt. Generally static libraries does not work until they are registered with System Registry.
You might have seen many programs register components during installation like 'Registering Type Components' or 'Registering COM Components' (for those who do networking especially). Those components are nothing but native COM dlls and tlbs.
so when creating deployment project, add some scripting login to register thode dlls and tlb to System registry using:
regsvr32 <path to tlb/dll>
you have to recursivey call this command for every dll/tlb you want to register with system. For example, if you have 4 dlls and 2 tlbs then you have to call it 6 times providing the path of dll and tlb one at a time.