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".
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 have a solution in Visual Studio with three projects added to it. The first project is a C# WinForms project with it's dependency set to the second project. The second project is a VC++ project which compiles to a DLL.
This VC++ project is dependent on another VC++ project which is a static library. I am able to run the executable from the debug/release folder directly on the development system.
But when I try to test on a different computer, I get an error after UI loads saying "Could not find file or assembly "mydll.dll" or one of its dependencies. The specified module could not be found."
Both the VC++ projects have their output set to a specific folder. When I right click in the references and check path, it looks fine.
What must I do?
I would try opening the csproj file in a test editor like Notepad or Notepad++ and figure out if the references are pointing to the right dll(s). Also pay attention as some of the references might include signatures, and it might not be the right signature either.
What shows up on the IDE might not be exactly the same that you have on the csproj file.
You need to unload the project from VS to be able to edit it in a text editor.
Also do this for all the projects on the solution.
Did the other computer have the Microsoft C++ Redistributable installed, of the appropriate version (year) and architecture? Also you can investigate dependencies with dumpbin.
I have a library written in C++, and a wrapper for this library written in C#.
Both projects are under development, and the way it is now I have to manually copy the .dll from the C++ project to the C# project after each build.
So I was wondering if there was any way to make Visual Studio copy the .dll from the C++ project automatically when re-building?
You can use Build events in visual studio and place a dos command to copy the dll to the current project
Right click on the project in Solution explorer in Visual studio, select properties. There in Build events you can type:
copy c:\Cplusproject\yourproject.dll $(TargetDir)
You can use Post Build or Pre Build events based on your requirements
See this article: http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx
Use post build event for that. Just something like xcopy <yourDllFilePath> <destinationPath> and it will copy your dll file to wherever your want
if yr using that c++ dll as reference, then u might be able to add the c++ project as a project reference, and everything will be copied automaticly, and it also helps while debugging.
Click on references in yr c# project, then a dialog window opens and choose Projects and select yr c++ project
There are several approach to achieve what you request.
Here I suppose you are using Microsoft Visual C++, but on other platforms there will be analogous functionalities.
Right click on the icon representing the vc++ project on the Solution explorer
Click Properties
Select the Configuration Properties/Build Events/Post Build Event node
Write the Command Line required to copy the dll around
Remember you must do it for every Configuration and for every Platform supported from your project.
Alternatively you may ask the Linker to output directly on the location referenced by your C# project:
Right click on the icon representing the vc++ project on the Solution explorer
Click Properties
Select the Configuration Properties/Linker/General Event node
Set the Output File property to the location referenced by your C# project
That said, you may also get the dll from the c# project.
While searching for debugging c# DLLs, I came across this article.
http://msdn.microsoft.com/en-us/library/c91k1xcf%28v=VS.100%29.aspx which says
You can start debugging DLL from:
The project used to create the executable that calls the DLL.
or
The project used to create the DLL itself.
I have source code(C#) for the executable project as well as the DLL.
My DLL project is in a different solution.
I want to debug the DLL from my exe project. How do I proceed with this. I have searched goole but without any detailed steps. I also added the DLL project to the exe project solution and added the break points in the source code for library project. But the breakpoint is never hit. How does the debugger know that I have loaded the source code for the DLL. Am I missing anything?
Update:
Following Avitus and Mick's suggestions, I added the DLL project to the exe solution. Also added the reference to the DLL project and the breakpoints were hit.
I also tried to debug it through the DLL project by
project--properties--Debug and setting the exe in the Start external program. In this case the break points were not hit, it kept saying the debug symbols not loaded. I tried all the options here without any success
Configuration was set to Active(Debug).
Debug Info was set to full.
In Tools--options--debugging(Enable just my code[Managed code] was unchecked)
In Tools--options--debugging--symbols, I had all modules,unless excluded selected and the Specify excluded modules list of empty. For some reason this method did not work.
The DLL has to have a debug database, or basically you have to include the DLL's solution in the solution you would debug it in.
Also visual studio has a Create Test feature which generates a bunch of test for methods and functions.
I'm trying to add a generated COM interop assembly project to my solution, and the only solution I could come up with feels really nasty.
I created a .net dll project, removed all .cs files from it and then created the following post-build event:
call "$(DevEnvDir)..\tools\vsvars32.bat"
midl.exe $(ProjectDir)relative-path-to-my-idl\MyComName.idl /tlb MyComName.tlb
tlbimp.exe /keyfile:path-to-my-key\k.snk MyComName.tlb
Essentially, I first create an empty DLL, then overwrite it with a real interop DLL. And there's no dependency management here - it's created every time.
Is there a better way to do this?
The MIDL compilation can be handled by making the COM interop project a managed C++ project (instead of a C# project) then adding the idl and h to the project as regular source files.
You can overcome the dependency problem by using MSBuild tasks directly instead of a PostBuild batch file, which line up nicely with the MSBuild dependency system.
However, why are you generating the file manually from an idl? When I need COM interop, I just import it and put the generated assembly (*.Interop.dll) into version control. This way, you always have the version you need and it's already ready to use, and Visual Studio can find the interop DLL before the first build, i.e. Intellisense is there right from the beginning.
Now some people won't like to check in a binary file, which I typically agree with, but well, if it works... :)
Of course, my method won't work if building the COM server is part of building the solution. In this case, just try to put the generation into the MSBuild script to get rid of the dependency thing, unless Visual Studio accepts a reference to a solution-internal non-.NET-COM project.