Inspect environment variables of a process from Visual Studio - c++

In Visual Studio, I want to inspect environment variables of a process launched from it, like in Process Hacker or Process Explorer.
VS gives very advanced debugging capabilities, probably I'm missing something.
Background.
I've got a C++ program built by Visual Studio 2019.
It fails if launched from the Visual Studio IDE, but runs successfully if launched from a .cmd script. Cmd script sets additional environment variables, and I want to mimic this behavior with setting those variables from Project properties -> Debugging. I have done it before, and everything was working.
Now something has changed, and I'd like to figure out what.
Security policies of our company don't allow me to use Process Hacker and ProcessExplorer. If I try to launch any of these programs they are terminated by the corporate soft, installed on my PC.
Also, I'd like to avoid adding code that would retrieve these variables and print them.
So, in Visual Studio, is there something that can show environment variables for me?
Update The issue is indeed in environment vars. Specifically in the way, Visual Studio sets them. No crashes, if I set required variables globally from system control panel. However, something strange happens if I set them via project properties of Visual Studio.

In the debug mode, you can save a process dump (Debug - Save Dump As - Minidump with heap) and then inspect this .dmp file with a hex editor (or Notepad if file is small) searching for an environment variable name.

Related

How to run C/C++ code using integrated terminal in Visual Studio

How to launch a C/C++ console application using the integrated terminal in Visual Studio instead of launching a separate terminal window?
To clarify more:
When I press the run button right now, this is what happens:
But what I want is something like this (but it must happen when I press the run button), where the output is directed to a terminal inside the visual studio window, without launching a separate window, this will make it easier when debugging because I won't have to switch between multiple windows:
There is a handy VsConsoleOutput extension for Visual Studio 2019 / 2022 that redirects program output into Output window inside of Visual Studio.
However when installing it i've got an exception complaining about incorrect value of InstalledByMsi value somewhere in manifest. The workaround is to manually open downloaded .vsix package (which seems to be a .zip archive) using WinRAR or something, adjust one line in extension.vsixmanifest file and save updated archive.
<Installation AllUsers="true" InstalledByMsi="false">

SIngle-file generator changes in Visual Studio 2017

I am trying to find information on single-file generator changes (especially how to register) in Visual Studio 2017. Any help would be really appreciated.
I think the registration system is pretty much the same. You can find more details here
In Visual Studio 2017, the registry settings are stored in a private registry files.
This enables multiple installations of Visual Studio side by side, on the same machine.
However, these entries are no longer available in the global registry file.
Here is how to open such a file in regedit:
Close Visual Studio
Start Regedit.exe
Select the HKEY_LOCAL_MACHINE node
From the main menu, select File -> Load Hive... and select the private registry file. That file is stored in the Local App Data
%localappdata%\Microsoft\VisualStudio\<config>\privateregistry.bin
where <config> coresponds to the configuration hive you would like to use
It will prompt for a name - that represents the name that will be displayed under (e.g. IsolatedHive)
Now you should be able to browse the registry under the hive you created
Before launching Visual Studio, you need to unload it: From the main menu File -> Unload Hive before attempting to run VS (otherwise regedit keeps the file locked, and Visual Studio will fail to launch)

debugger already attached - cscript

I have a short JScript which creates an active X object and calls a function. That active X object is written in C++. When I run the command cscript scriptName.js //X I start VS2012 in debug mode. Than I try to attach a debugger but as you know one is already attached.
Is there a way to reattach the debugger or connect to it some how?
My current solution is not to use JScript and call the code from C++.
Which debugger do you want to use?Visual Studio or WinDBG?
Do you really need to debug both the JavaScript code AND the C++ code simultanously?
If the latter isn't an issue for you, and you want to focus on the C++ code, in Visual Studio (or WinDBG) just debug cscript.exe, without the /x flag. No need even to attach, you can start debugging with F5 from Visual Studio.
In Visual Studio (2008, 2010, or 2012 - they all work), right click on the ActiveX project (That's the C++ project).
Go to: Configuration Properties -> Debugging
In the Command put the cscript full path: C:\Windows\System32\cscript.exe
In the Command Arguments put the full path of you JS file
Put a break point on your ActiveX code (on dllmain, or the constructor of your COM object)
Hit F5
Visual Studio will complain about lack of symbols of cscript. That's OK. keep going.
You'll hit your breakpoint
Some point to consider:
Setup the symbol path to include the Microsoft Symbols. This way, you'll see the names of the functions that calls your code (oleaut32.dll and friends).
Also, this is the default, but make sure that:
The debugger type in the same property box would be either Native or Auto.

Visual Studio is not loading modules when attaching to process

I have a C++ application. When i press F5 in visual studio application starts and i can debug it. But when I run application from windows explorer and then attach this process in visual studio I see breakpoints can be hit (they are completely red) but breakpoint does not hit. When I see modules window nothing is present there. What is problem?
Verify the code type Visual Studio is configured to load symbols. Attach To Process dialog has Select Code Type option to specify which symbols to load. Here you can select Managed symbols and/or Native symbols.
Also the assemblies should be of same version.
It sounds like the executable code that you are debugging (F5) is not the same as the one you are running from explorer. Check the date of the executable you are running. Also, it may be picking up a different version of DLL if you are using them. Try renaming one of your DLL files and then running from explorer. Use depends.exe to see which modules are being loaded.

How to set up a project in VS2010 that can also be compiled from within VS with a different compiler?

I have a Visual Studio 2010 project with C++ code that I want to run on 2 Systems. I develop,compile,debug, etc. it in Visual 2010 but also have a separate batchfile with which I can compile some of the classes for a different system.
How do I have to set up the configuration manager (or do whatever else is necessary) so that I can run,debug,etc. my project normally in vs2010 with mfc/win32 and then switch to another, new configuration where only a batch file is being executed from vs2010 (and no longer the vs2010 compiler) and the results of that are being shown in the output window ?
I got it working by creating a new configuration in the configuration manager where I selected any kind of platform (doesn't matter for this) and then excluded all files from build with their individual file properties. The compiler has nothing to do then. So I added a custom build step in the project settings where my batch file is being executed. Now whenever I switch to this configuration in the menu only my batch file is being run and I can easily switch back to my normal debug profile for developing, testing and debugging in vs2010. Its not that elegant but it works...