What is a good workflow with Visual Studio when writing a hot-swappable dll in C? - visual-studio

I have a Visual Studio solution with an executable and a hot-swappable dll (plugin). The executable runs a file system monitor in the directory where the dll is built and when a new version is generated, it reloads it and continues working with it. One of the crucial things here is that the executable state is preserved between reloads of the dll.
Now this works fine if I run the program without debugging (Ctrl-F5) and then just build when I have changes in the dll code. The dll is reloaded, the new functionality executed, and it's a charm. The problem is when I want to debug the dll.
Unfortunately Visual Studio doesn't allow me to build while debugging. So the only thing that does work is if I run without debugging and then periodically attach and detach the debugger from the process when I make changes and want to debug the dll. This is pretty cumbersome. Especially when I want to debug the plugin init function. In such case I have to add a break in the executable before calling it (say a message box: "Plugin loaded, but init not called. Attach to process now if you want to add breakpoints in init).
Is there a Visual Studio workflow where I can skip the constant manual reattaching to the process?
(Xcode with its explicit target selection, for example, does allow me the dream workflow, where everything just works and I can build the .dylib while debugging, without explicitly reattaching the debugger to the process. init breakpoints working and all)

Related

Extending Visual Studio to run via custom exe

I want to create a custom VS project that builds a DLL, but when hitting F5 will run a custom executable that I wrote (which gets the DLL path as parameter).
Is this possible? What API should I use?
Yes, it's easy.
In the project properties, in the Debug tab, select the Start Action 'Start external program'. This program must be your executable.

How to debug chained executables in Visual Studio solution

I have two projects in VS2015. The executable from start up project at some point needs to open the output executable from the second project. (by using Process.Start)
How can I debug the second executable as well as the main one? Can VS include the second executable in the output directory and setup debugging automatically?
Either attach the debugger manually after the second process started (using Debug -> Attach to process) or use the Microsoft Child Process Debugging Power Tool

Register type library during installation

I have added an automation interface to an application I wrote. The type library is stored as a resource in the application, and on startup, the application calls RegisterTypeLib to register the type library automatically.
I just discovered that this call to RegisterTypeLib only works during development, where the application is launched from Visual Studio, because Visual Studio is running as administrator, and the application inherits this. When running the debug build from the command line, or when running the application as installed by the installer, the application is not running as administrator, and the call to RegisterTypeLib fails.
So I suppose I should register the type library during installation (which would also have the nice side effect of making the automation interface available without having to run the application first). The installer is a Windows Installer project in Visual Studio.
Is it possible to do achieve the effect of RegisterTypeLib during installation (and if yes, how)? When the installer solution is open, Visual Studio shows an editor called "Registry" wher one can add keys to the registry, but there's no way I can add each key separately - I need to somehow add the entire type library with a single call, like RegisterTypeLib does.
EDIT: After manuell's hint and some research of my own, the question boils down to this:
I need to call MyApp /RegServer from the installer (which will also create other required registry keys that aren't created by RegisterTypeLib); how exactly does one do this? I added an "Install" custom action in the Visual Studio installer solution, but haven't yet found out how to trigger it.
The usal way is to let the installer launch the application with the command line arguments /regserver or /unregserver. If you use a Framework (MFC/ATL), the handling of all the registration (unregistration) steps are done automatically.
If you want to do all by your self, check the arguments to "main", and call RegisterTypeLib. The Windows installer should launch your EXE with /regserver, if it knows that's a com server.

Build error in VS 2010

I am getting this error in my application
Error 1 Unable to copy file "D:\myproj\bin\Debug\myproj.dll" to "bin\Debug\myproj.dll". The process cannot access the file 'bin\Debug\myproj.dll' because it is being used by another process.
How to fix it
Your project dll is being used by another process. Either you ran your application and it didn't fully shut down (check the task manager) or some other program is trying to consume the dll in the d:\myproj\bin\debug\myproj.dll
For example, in the olden days, if you used a .Net dll in a VB6 app, and pointed to the debug dll, it would grab on to that and you'd have to shut down VB6 to free the dll.
I suspect you'll have to do something similar.
Start by checking task manager and making sure your app isn't still running.
Then close down any other apps that have a reference to your dll
If neither of those two work, close down studio and restart it

Is there a way to run an outside executable after a SPECIFIC solution is built in Visual Studio 2008?

I had the same question as was asked in this thread, i.e. I was looking for a way to run an executable or script after building a solution in Visual Studio.
I tried out the suggested solution of catching the OnBuildDone event with a macro, which (as I understand it) needs to be placed in the EnvironmentEvents section under MyMacros in the Macros IDE. The problem with this is that it makes the macro global to everything I do in Visual Studio. In other words, it runs the macro regardless of which solution it is that I am building. However, I only want it to run for that one solution.
Is there a way to make a macro that catches the OnBuildDone event for a specific solution only?
One way to do it is:
Define a new, faily empty, project within that solution
Specify that this new project depends on every other project (so that this new project will be built after all other projects)
Invoke your executable or script as a build event of this new project (instead of, of the solution)

Resources