Generating a COM visible assembly from managed c++ (C++/CLI) - com

I need to develop some classes that should be callable from VB6 with Managed C++ (C++/CLI).
I've developed first a sample in C# and I can use the assembly through COM without problems
just using the setting "Register for COM interop" and "Make assembly COM visible" (and using the attribute [ClassInterface(ClassInterfaceType.AutoDual)] to make methods available at VB6.
After that I tried to translate the sample to C++/CLI without success. I've created the same class with the [ClassInterface(ClassInterfaceType.AutoDual)] attribute. I've set the "Embedded IDL" setting to specify the output TLB but the TLB is not generated automatically. If I use the tlbexp util over the generated DLL I get a tlb that can be imported at VB6 but when I try to create an instance I get an "ActiveX compoennt can't create object (429)"
What more do I need to do with the project to let it run?
Thanks in advance.

Not much to go on but you never mentioned registering the assembly. The C++ IDE doesn't have the "Register for COM interop" option. From the Visual Studio Command Prompt, run Regasm.exe on the assembly to get it registered. You need the /codebase option if you don't put the assembly in the GAC. And the /tlb option generates the type library, making tlbexp.exe unnecessary.

Related

VBA Runtime error '-2147221164 (80040154)': class not Registered

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

Creating a VB.NET COM DLL

I have created a project in VB.NET, and I set "Make assembly COM visible". I have added 1 function to the project and then compiled it with admin rights.
I was under the impression that this is sufficient to make the project a COM exe, to register it and that I could consume it from within VB6.
However, when I try to add the .exe as a reference in VB6, VB6 says that it can't add a reference to the VB.NET .exe file.
What am I missing?
I have noticed that there is another checkbox named "Register for COM interop", but I'm not sure if I really need that.
I had to change the application style from Windows-Forms-App to Class Library.
Afterwards, I could check "Register for COM interop".
After compilation, a TLB would be created.
I could then reference this TLB.
That solved my problem.

ASP - Server.CreateObject returns nothing, Classic ASP

Team,
The following code returns empty/null to myobj, in my classic ASP page while trying to invoke a dll component.
Set myobj = Server.CreateObject("MODULENAME.cCLASSNAME")
This is related to a DLL which is placed alongside this asp page under \Bin. The DLL is an Interop COM dll custom developed by a former colleague and currently there's no access to the code.
The DLL components are appearing in the regEdit under HKEY_LOCAL_MACHINE\SOFTWARE\Classes\ which makes me assume it is registered. However when I try to re-register using regsvr32, it shows that it was loaded but couldn't find DLLRegisterServer method. I use regAsm to register the component.
Any alternate approach that can be done here? Am I missing something?
If the file name starts with "Interop" or "AxInterop", it is likely a wrapper to a COM DLL, not the DLL it's self. The COM DLL must be registered on the system and then a dotNet application will use/create that wrapper so you can make calls to it.
What you need to do is find the DLL, not the Interop because you are not using dotNet in Classic ASP. Make sure it is registered on that computer (using regsvr32 without error) and then this should work.
Last note/hint, that dll created by ex-coworker was done in C or VB (not dotNet) right? If done in dotNet, it is not COM and you need to research "How to call a managed DLL from unmanaged code".

Add COM library reference in MonoDevelop

I have downloaded a .exe file that when executed (in wine) it puts two dll's in the system32 folder and a dll in the "Common files/App-name/" folder.
In theory, the installing of this file creates a tab in Visual Studio that appears when referencing and it is a COM library.
I have tried to reference these dll's in my console project but I get a message of "Is not a valid .Net assembly".
Is there something I can do?
MonoDevelop does not have support for adding COM references directly. You will have to use tlbimp.exe to generate a wrapper dll, then reference that. This is essentially what VS does transparently when you reference a native COM dll.

COM DLL registration failed with TFS 2010

I have a C++ DLL project which is created in VS 2010. It is exposed as COM(ATL). I used this dll to another .NET Project as reference. C++ Project linker settings are set as follows:
­"Register Output" = Yes
"Per-user Redirection = Yes
I created a build definition to build these two projects in tfs 2010. C++ Project builds fine, but .NET project fails because the output dll of C++ project is not registered. Setting to "Per-User redirection" = false does not work. I also tried using WF activity 'InvokeProecss' to register the c++ dll using Regsrv32/batch file/my own exe etc, but I get exit code of 5. My TFS 2010 is in Windows 2008 Server R2. And I think, it's not running the process as admin.
If I generate a interop dll using tlbimp, and then I refer that interop in my .NET proejct, it works fine(oviously in tfs build, I need to add InvokeProecss to call tlb). But this is not acceptable as our general practice is to refer a COM dll directly from .NET proejct.
Can anybody please help about this?
Is there a way to run the tfs automated build activity 'InvokeProcess' as Administrator without prompting for user name/password?
By default, the TFS Build Service runs as the "Network Service" account which is a relatively low-privilege account. Alternatively, you can configure it to run as any domain account you like. I wouldn't recommend that as a solution to the problem you described, however. I would agree with Hans that, in this case, it would be better to use the type library importer (TlbImp.exe) to "reference" your COM server from your managed assembly.
If the COM object isn't changing, you can just use the type library importer to generate an interop assembly, check that in and reference it from your .NET project. If it is changing, you can add a post-build step to generate the interop assembly rather than using the InvokeProcess activity. As Hans pointed out, you can't actually reference a COM object directly from a managed assembly. Your reference is actually causing an interop assembly to get generated at build time after resolving the reference to the registered COM server.