DLL Project using C++ Not Running in Visual Studio - dll

Working with DLLs using C++, I've come across an issue, the code builds but does not compile/run in Visual Studio. When I use Visual Studio 2017, the problem is "xxx.dll is not a valid win32 application", when using Visual Studio 2010, it's something like "xxx.dll is missing ", the code builds fine, it just doesn't run in Visual Studio, I'm a newbie in DLLs and need to use some sort of debugger.

DLLs don't run. They contain code that is loaded by something else. You can't just run a DLL in Visual Studio. You need an executable (EXE) which loads the DLL.
You can set an executable which runs when you press Start Debugging. This is done in the properties of the project. By default, this is set to the variable $(TargetPath), but you can change this to launch anything under the debugger.
I don't have VS2017, but here is the project properties for VS2015:

Related

msbuild fails to compile vsto project

We recently installed a new development environment (Windows 10) from scratch with Visual Studio 2017 but we cannot manage to make msbuild compile a Microsoft Office Addin for Word (vsto).
Within the Visual Studio installer we made sure to include the required components for Office Development.
It throws the following error (german translated to english)
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" was not found. Also, tried to find "OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" [...]
However, the project builds fine within Visual Studio.
On the old system, everything works fine, and i cannot remember having to configure anything at all.
You need to install Office build tools when installing Build Tools for Visual Studio 2017
In my case, I managed to get around the issue by copying the folder
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio
from the development environment (the old environment in your case) to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio
on the build environment (the new environment in your case). I would have thought that one should be able to simply get the relevant targets from the Build Tools for Visual Studio 2017 but that appears not to be the case.
After reinstalling everything it works now.
I guess back then when we set up this machine, the build tools setup was bugged or something.
Now we could install everything we needed for the buildtools using the visual studio installer and it works like a charm.
Okay, so I've worked through this one now. The problem was caused by me using Windows\Microsoft.NET\Framework64\v4...\Msbuild.exe.
It looks as though running msbuild from this location results in it not being able to implicitly locate many of the assemblies and build utilities required to build a VSTO project.
I resolved the problem by switching to using C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe

See how Visual Studio compiles my project so I can compile it from command line

I have a Visual Studio (.Net) project. When I hit the rebuild option in VS it compiles perfectly. In the Output window I only see the progress but it doesn't show how Visual Studio is compiling (compiler, arguments, etc. etc.)
How can I see the exact thing visual studio is executing in order to compile my solution?
Open Visual Studio and in the Quick Launch (Ctrl+Q) window type "MSBuild".
Then in the window that pops up, change the msbuild project output verbosity to Detailed. Or, play around with the settings to get the amount of output that you like.

Debug DLL with Labview and Visual studio

I wrote a C_Wrapper for a DLL (C ++).
This DLL is imported in Labview.
Since there are many problems with this import in Labview, I would like to know:
Is it possible with Labview and Visual Studio to debug this DLL step for step
In Visual Studio navigate to Debug->Attach to Process then select labview.exe (note: at that time your labview code which uses dll should be already ran). Now you will be able to catch all labview calls to your dll and debug it inside of VS environment (note: you can see all data passed from labview, put your breakpoints into c++ code, etc...).
This is indeed possible. I suppose you already have a visual studio project to build your DLL.
Go to your project's property pages and set the Debugging->Command parameter to the location of LabVIEW.exe (usually installed at C:\Program Files\National Instruments\{Your LabVIEW version}\LabVIEW.exe)
Then just hit F5 to start LabVIEW under the debugger.
Yes, this is possible. I tried it with Visual Studio 2015 and LabVIEW 2015
Configure you project in Visual Studio (taken from here https://msdn.microsoft.com/en-us/library/605a12zt.aspx)
Right-click the project node in the Solution Explorer and select Properties. Go to the Debug tab.
Make sure that the Configuration field at the top of the window is set to Debug.
Go to Configuration Properties / Debugging.
In the Debugger to launch list, choose Local Windows Debugger
In the Command box, add the fully-qualified path name of the application: C:\Program Files (x86)\National Instruments\LabVIEW 2015\LabVIEW.exe
Set Attach to Yes
Configure LabVIEW DLL call
Make sure your VI calls a DLL from /Debug/ folder and not from /Release/ folder
Start Debugging
Run Debug in Visual Studio. Make sure LabVIEW process is attached
Add breakpoints if needed
Start your VI

Why does my build app fail when run outside of VS12 (i.e. when deployed)?

I've written a c# program that builds *.csproj and *.vcxproj using Microsoft.Build.Evaluation. It works great on both project types if I compile and run it from inside Visual Studio 12. But if I run the exe directly (outside of Visual Studio) I get the example error message below. The error occurs only for vcx projects; c# projects continue to build just fine
Question: Why am I getting this error? Why does my program work fine for both C# and vcx projects when run from within VS12, but fails, but only for vcx projects, when run outside of VS12?
Please don't chastise me for not using MSBuild.exe. My orders were to programmatically build C# and vcx projects using Microsoft.Build.Evaluation.
Code:
using Microsoft.Build.Evaluation;
...
Project proj = new Project("MyCppProject.vcxproj");
proj.Build(logger);
Runtime Error:
Building MyCppProject
Project "MyCppProject.vcxproj" (default targets):
VCMessage:
ERROR C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(518,5): Specified platform toolset (v110) is not installed or invalid. Please make sure that a supported PlatformToolset value is selected.
Done building project "MyCppProject" -- FAILED.
One solution is to force the Visual Studio version as an environment variable prior to loading and building the project:
using Microsoft.Build.Evaluation;
...
Environment.SetEnvironmentVariable("VisualStudioVersion", "11.0")
Project proj = new Project("MyCppProject.vcxproj");
proj.Build(logger);
Visual studio maintains platform tool sets list supported for the version of Visual studio you are currently running for example on my machine I have VS 2008, 2010 and 2012
Now suppose when I install Visual Studio 2013 which has a Platform Toolset version of V120. What happens, is that the project saves this in its corresponding XML files in the format (vcproj, vcxproj, vcxproj.filter.user files).
now this valus is not known to VS 2012 so it complains when opened in VS 2012.
Similarly for opening VS 2012 project in VS 2010, as in your case and so on.
Solution:
To fix this issue, Open you solution file in notepad++.
Make these 2 changes
1) Replace
Format Version 12.00
with
Format Version 11.00
2) Replace
Visual Studio 2012
with
Visual Studio 2010
Then open the file again in visual studio and rebuild solution.

How do I create a package of my application in VB.net which can run on other's systems too?

I made an application in Visual Studio 2012 using VB.net language.
I want to make a package or a setup so that any user whether they have visual studios or not can run my application.
I searched on internet and what I found is that there is something like statically or dynamically linking. Do these relate to my question?
Please give me a step by step method of packaging so that my application can run on Windows without needing Visual Studio or any other program to run it.
You will find it in the menu under Build -> Publish.
This will produce an executable that can be run without Visual Studio. The .NET Framework has to be installed on the computer though, but that usually is.