Create interop dll from .tlb file - c#

I have a C++ project and a c# project. The C# project accesses methods of the C++ project through 2 interop dlls called interop.X.dll and interop.XCom.dll.
When my C++ project rebuilds it creates X.tlb and XCom.tlb files, it also creates x_i.c, x_h.h, xCom_i.c, xCom_h.c files. I have found that the files are created due to project settings in "configuration properties -> MIDL -> output", as displayed below;
What I need to know is how to create the 2 interop dlls, which doesn't get created automatically, using the .tlb and other c files. I have tried using tlbimp x.tlb /out:Interop.x.dll, but the created dll doesn't seem to work.
Thanks.

This is a summary of my comments above.
Why not just bypass tlb references and instead just add a direct COM reference?
Adding a COM reference from .NET to your COM library requires zero change on the COM project. VS creates the interop dlls when you add a COM reference from your .NET project

Related

C# setting that works similar to VS C++ /ASSEMBLYLINKRESOURCE

I have the follwoing scenario:
C# project A uses an unmanaged dll via p/invoke: [DllImport("someUnmanaged.dll")]
project A is configured to copy "someUnmanaged.dll" to the project bin folder when compiling. This works fine.
C# project B, C and D all reference A. But they do not automatically copy the unmanaged dll. I have to configure each of those projects to copy the unmanaged dll.
So, If another developer wants to use my projectA.dll, they have to know exactly which unmanged dlls to copy, and how to configure their VS project.
If project A is a managed c++/cli project instead of a c# project, I can use /ASSEMBLYLINKRESOURCE "...\someUnmanaged.dll" to tell the compiler to always copy someUnmanaged.dll whenever it copies projectA.dll.
(this is a setting in Configuration Properties -> Linker -> Assembly Link Resource)
/ASSEMBLYLINKRESOURCE somehow annotates projectA.dll, so that when this dll is referenced in another project, visual studio will automatically search for someUnmanaged.dll as well, and copy both during compilation.
How can I get this functionality in a c# project?

How do I add a dependency to a third party dll that causes an error?

I have a Visual Studio (2015) project, written in C#, that is dependent upon an external dll (say a.dll), written in C++. This in turn is dependent upon other libraries (say b.dll, c.dll), also written in C++. These in turn are dependent upon some boost libraries. I have no control over any of the libraries, but they must be used to complete the project.
Adding library a.dll to the visual studio project is fine. I can add it as a reference and that works. However, it does not run, because the other libraries are not present.
When I try to add b.dll and c.dll to my project, then I get an error:
A reference to 'a.dll' could not be added. Please make sure the file is accessible, and that it is a valid assembly or COM component.
Using this answer (https://stackoverflow.com/a/12639732/5503148) I tried running TlbImp, and got this error:
TlbImp : error TI1002 : The input file 'b.dll' is not a valid type library.
If I copy the libraries to the output folder manually, or get them copied automatically by adding them to the project (not as references), then it all runs.
However, in the end result the project needs to have a dependency on the libraries. That way they can be loaded into another third party product.
Is there a way to do this manually - i.e. tell Visual Studio that the library a.dll is dependent upon other libraries?

Reference 3rd-party C++ DLL into VS 2013 Project

I've been provided a DLL that has been written in C++. Along with the DLL I receive the required input parms and expected output as well as a .h include file.
Can't seem to get it included as a Reference in my project. My procedure is to right click References and Add Reference, click Browse and then double click on the DLL. The error I get is:
A reference to 'c:......\dll' could not be added. Please make sure
that the file is accessible, and that it is a valid assembly or COM
component.
The problem is likely due to the name mangling of C++, but I'm not sure how to overcome the problem. I've been told by the author of the DLL that it was written for another customer who ran into the same issue, but was eventually successful in getting it referenced. I don't have access to that 'customer' and was wondering if anyone had suggestions.
Adding a reference is not how you link to this unmanaged DLL from your C# code. Instead you need to either:
Translate the header file to C# p/invoke calls, or
Create a C++/CLI wrapper around the unmanaged DLL and add a reference to that from your C# project. This option would typically involve linking to the .lib import library for the DLL which should be supplied with the DLL.

calling function which is encrypted on dll file and that file is added as a reference in my sloution

I have made one common libarary using c# (.dll file is created) that is having some common functions .
Now I have one solution which is having so many projects made on vb and c++ .
Now here I added that above dll file in this solution (by adding refrence).
and I want to access those common function from dll to this all projects .
Is this possible??
IF YES THEN HOW??
For each C++ and VB.NET project, right-click on References and add the C# project as a reference.
Then access your c# classes & methods as you would access thus from the .NET "built-in" libraries.
If it's not a project within your solution, then for each project, browse to the dll and add it that way.

Add a VB6 ActiveX DLL reference to a VS2008 project

At work, we have a VB6 project (ActiveX DLL) that we need to be able to add as a reference to another VS2008 C# project.
A developer there tells me that in the past, they have been able to do so but now we made a change to the VB6 DLL and had to recompile it.
As such, we need to update the reference in the VS2008 project but when we try to add the reference to the VB6 DLL back (after removing the old reference) to the VS2008 project, we get a yellow "!" icon on the newly added reference and then when we build, VS2008 says the reference cannot be found.
I tried the "Browse" and "COM" tabs where you can add reference, no luck.
Do we need some kind of TLB to be able to add it or something ?
Thanks.
You need to do the following from a command prompt:
#CD to wherever the dll is located
regsrv32 /u foo.dll
regsrv32 foo.dll
This will unregister the old com object and register the new one.
He's right, you could do that from command prompt.
Remember though, your Active-X control DLL could be 16-bit, so use
regsrv /u foo.dll
regsrv foo.dll
from command prompt. But 32-bit works fine for regsrv32!
I used OLE/COM object viewer (included in Windows SDK 6.0A) then I saw a bunch of COM entries in "All objects" ie: MyDLLName.className and some were pointing to a DLL file which did not exist anymore. Deleted all the relevant COM entries in the Windows registry that pointed to the deleted DLL and left all the ones which pointed to the existing DLL and then I could import it successfully in my VC# project.

Categories

Resources