Creating a VB.NET COM DLL - vb.net

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.

Related

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".

Adding a reference to a DLL, while keeping it a native DLL instead of an ActiveX Control

I'm forced to use a third-party COM component in an application, and I'm having issues adding the reference to my project.
I've added this DLL as a reference to a project before, but in the past it would link directly to the DLL, such that the "Path" in the reference's properties would be filesystem path where the DLL was installed (i.e. not relative to my solution's directory). However, now, when I add the reference, the "Path" is to my project's obj directory, "Embed Interop Types" is set to True, and it's listed as an ActiveX component (which is not correct).
Then, I stumbled upon this MSDN article, which says:
If you want to add a reference to a registered COM DLL that contains an internal manifest, unregister the DLL first. Otherwise, Visual Studio adds the assembly reference as an ActiveX Control instead of as a native DLL.
Well, there you have it. That's my exact problem. I need the native DLL, but I'm getting an ActiveX Control instead. So, I did as it suggested and unregistered the DLL. However, when I then try to add the reference, I get an error saying:
A reference to ... could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.
If I register the DLL again, I'm able to add it as a reference, but again, it's added as an ActiveX control. At this point, I don't know what else to do. Microsoft is very clear that I must unregister it before adding it as a reference, but then Visual Studio 2013 apparently won't let me add an unregistered DLL. Any one have any idea how to work around this?
UPDATE
So, apparently a recent update to this app made COM the only option (no directly using the DLL). The fact that it was added as ActiveX didn't mean anything. The problem turned out to be that this was a 32-bit library trying to run in 64-bits. I knew that was a potential problem, but switching the platform target to x86, still resulted in an error so I ended up chasing a red herring. Turns out IIS Express 8 runs natively as 64-bits even if the platform target of the site you're debugging is 32-bit. I had to go into Visual Studio options and uncheck the flag that tells IIS Express to run 64-bit (under "Web Projects") and then everything ran fine.
So, since adding the registered DLL was pretty much a no-go, I focused instead on trying to figure out why Visual Studio wouldn't let me add it when it was unregistered. I mean, sure, I might get an error about it being an unregistered DLL once I tried to run the project, but it should at least let me add it as a reference, regardless.
I eventually stumbled upon tlbimp.exe, which according to Microsoft:
The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library.
Okay. Well anyways, I opened a Visual Studio Developer Prompt (regular cmd doesn't have tlbimp.exe on the path), and ran my DLL through it. It created a new DLL, which I was able to add as a reference, and it satisfied my project dependencies. However, I haven't tested it just yet to make sure everything still works as it should once this thing is running, so I'll update with what I find there.
UPDATE
Yeah, so this doesn't work either. I get the same error once it's running saying that the class is not registered. Only now, I can't register this DLL because tlbimp.exe removes the entry-point.

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.

error "429" AcitveX Component Can't create object (in vb6)

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.

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

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.