I'm using VS2013, and have a solution that has a C++ Project that references the TLB file from a C#.,dll project in the same solution.
My import statement
#import "Toolbox.Accessor.tlb" named_guids
in the C++ project cannot find the TLB. I get the compile time error error C1083: Cannot open type library file: 'Toolbox.Accessor.tlb': No such file or directory
While I totally understand the error message, what I don't know how to do is to get the .TLB file into the proper place, so that the C++ Compiler can find it.
I want to do this at compile time so that it will pull the generated TLB file from the C# project and will work on my build server.
I've referenced the C# Dll project as a Reference to the C++ project, and have searched the web for an answer, but alas, have found none to this point.
The answer to this question is the proper inclusion of the Additional Include Directories setting. As HansPassant pointed out in a comment..
The final answer for me was to define an include directory as follows:
$(OutDir)..\..\MyCSharpProject\bin\$(Configuration)
This works both on my individual developer system, and the build server which isn't putting any changed files into the original Source Folders, but is putting them in a BuildArtifacts folder.
Related
I'm working on a C# project that is nearing release. As part of this, I have started building the project and testing it on another machine. This has revealed some odd problems. My biggest concern, though, is that my project is failing to run. I can do some basic things, but when I try to use my projects primary functionality it crashes. Using Visual Studio, I was able to determine the exception that was causing the crash.
Essentially, I'm getting a FileNotFoundException on the dll that contains most of my project's functional code. I'm not sure if I've made an error in adding the dll to my project, or if there's a problem in one of the files in the dll.
The dll was added as a reference using the Project -> Add Reerences feature of the user interface.
The dll contains three files which contain absolute file paths (these are for #import statements). Example follows.
#import "C:\Users\Me\Documents\Projects\MyProject\Delegates\bin\MyDelegate.tlb" raw_interfaces_only
My hang up is I'm not exactly sure what I'm doing wrong here. I suspect that those import statements are causing problems, but I'm not exactly sure how to fix them if they in fact are the problem. This is my first c#/c++ project so any help would be appreciated.
Adding the dll as a reference DOES NOT include the dll with your project--you are simply telling your project to use the library for your code. The dll will need to be installed on all computers that run your application, for your application to use the dll.
If the dll also uses three files (as you specified), then those files must also be included, and be installed in the expected path.
Presuming you have redistribution rights on the dll you mention, you can include the dll in your project. Be sure to set the "copy" property as "copy always" or "copy if newer" and change the reference to use the copy that ends up in you bin folder. Then you only need to be sure to include that dll and install it in the same folder as your application.
I had one C++ project written in MFC and some of the project are of DLL type. I wanted to use those dll in my C# code(using DllImport).
I tried to add as a reference but could not able to and getting an error. Do i need to copy those dll's in any of particular location? How my code is going to link those dll's?
You can't add a reference to a native DLL. In DllImport you just import the DLL at runtime so be careful with the path to the DLL if it is not in the same directory as your managed application.
A problem with C++-DLLs is, that the function names in that DLLs can be decorated so you have to find out that decorated name before using it.
I have a solution with a C++ dll project and a C# project that uses it. The problem is that the build path of the c++ project is in the solution folder and the c# is in the project's bin folder (each nested with debug/release), so the DllImport doesn't find them.
Is there a standard way to fix this?
The way you are supposed to do this is to set the build path for both projects to the same 'bin' directory... preferrably one for the solution, not a project. Then just make all projects build to that one folder. You can change that from the Project settings.
Another technique is to use a post-build step for the C++ app that copies the DLL to the C# project's folder. That way you don't actually change any paths. You just copy over a DLL. Be careful here though because when you clean the C++ file's project, you may actually still have the copy in the C# projec'ts bin directory leaving you scratching your head as to why things aren't happening as expected.
Alternately, you can deploy the C++ DLL to a system path (also as part of a post-build step) but you'll have the same issues as stated above.
For debugging, I'd recommend these in the order presented.
I have a .dll file written in VB6. I understand that I can add this .dll file as a reference in my VS project, but I need to be able to add this .dll file as an embedded resource to my VS solution. I then would like to invoke this .dll file to call a function.
However I cannot load the .dll file as an assembly because it was written in VB6. Assuming I cannot simply rewrite this code to .net, does anyone have a working solution for converting this dll to a recognizable assembly file?
You won't need to convert it, you just need to reference it as an unmanaged DLL. See http://msdn.microsoft.com/en-us/magazine/cc301501.aspx for instructions on how to do this.
Without much luck I've been trying to attach the HTMLTidy c++ library dll within Visual Studio, however everytime I get various errors with different builds. I'm adding a reference to the project and then manually selecting the dll, which has been copied into a lib folder within the project folder.
The first dll I tried was from Mark Beaton, and I'm using his HTMLTidy wrapper as it seems the most up to date. The standard Win32 one was built.
Mark Beaton Builds
I've also tried the build from the official HTMLTidy page, again the dll
Official Build
The error when referencing, please help! I've tried compiling from source, but the source doesn't seem compatible with VS 2010.
libtidy.dll is an unmanaged C DLL, so you can't add a reference to it in Visual Studio's Add Reference dialog. You need to build the C# code from https://github.com/markbeaton/TidyManaged into a managed DLL, and add a reference to that DLL instead.
Make sure that libtidy.dll is copied to your output folder; you can achieve this by adding the DLL file to your project, and changing its properties to "Copy to Output".