I added this well documented macro to MyMacros, Environment Events in VS 2008 Macros in order to cancel failed builds:
Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
If Success = False Then
'The build failed...cancel any further builds.
DTE.ExecuteCommand("Build.Cancel")
End If
But it's not canceling my builds. I also set breakpoints to hopefully catch it firing but they are not hit either.
I also added this test macro but its not being fired either:
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
Beep()
Beep()
End Sub
The "Allow macros to run" option is set.
Why is it not being fired? Why are my breakponts not being hit?
Thanks for your help
Apparently you have to run Debug (green play button) in the Macros IDE for breakpoints to be hit.
Now I know.
Related
I changed the resource file for a new icon for my exe and generated the exe for vb6 project. However, the exe icon has changed but the windows 7 task bar is still showing the old icon.
If I generate the exe in some other location other than my project directory its working fine. Could someone please help on this issue?
You need to tell Windows you updated the icon so it can update its cache.
If you're using VB6, make yourself a little utility:
Create a new EXE project (name it "ForceIconsRefresh" or something like that)
In the project properties, change the Startup Object to "Sub Main"
Add a new module, remove the default Form object
In the module add the following:
Option Explicit
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
Private Const SHCNE_ASSOCCHANGED As Long = &H8000000
Private Const SHCNF_FLUSHNOWAIT As Long = &H2000
Sub Main()
Call SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSHNOWAIT, 0, 0)
End Sub
Compile
Execute after building an EXE with an updated icon
VoilĂ !
I have got an infuriating problem trying to compile a VB6 Outlook Add-in component following an upgrade of Office on the same PC to Office 2013 Pro Plus.
The error
Compile Error: Automation type not supported in Visual Basic
is being thrown on the line:
Implements IDExtensibility2
I will paste the full code from that file below.
On another PC, I managed to get everything set up, and upgrade Office to 2012 and it compiled no problem, but on that same PC now - I get the same error. I have messed around a lot with the Office install in the interim so I couldn't accurately tell you what I did in between it working and not working, but the bottom line is it seems it shouldn't be beyond possibility to do what I am trying to do (as I have done it!), I just need some guidance on what I may need to do to get back to a working setup. Any ideas??
Implements IDTExtensibility2
Private gBaseClass As New clsOlkAddIn
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, custom() As Variant)
gBaseClass.InitHandler Application, AddInInst.ProgId
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode _
As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
Dim objCB As Office.CommandBar
On Error Resume Next
'If RemoveMode = ext_dm_UserClosed Then
Set objCB = golApp.ActiveExplorer.CommandBars("Addin")
objCB.FindControl(Type:=msoControlPopup, Tag:="Menu").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="AddEmailsButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncContactsButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncTasksButton").Delete
objCB.FindControl(Type:=msoControlButton, Tag:="SyncCalendarButton").Delete
objCB.Delete
'End If
gBaseClass.UnInitHandler
Set gBaseClass = Nothing
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
'To Be Declared for IDTExtensibility2
End Sub
Another cause of this error, as I found today is having an optional parameter on a function and giving it a default, e.g.
Public Function Foo(MyString as String, Optional MyVariant as variant = null)
Changing this to:
Public Function Foo(MyString as String, Optional MyVariant as variant)
Solved it, I didn't get there as simply as it looks above though (hence, why I'm hanging around here), I did change the optional parameter to a string first, which worked, in fact, even with a variant parameter, having a default of anything other than Null worked. It was the default of Null that was causing the error.
As you've confirmed in your answer (in comments), ensuring you've upgraded to the latest service pack is always the best option unless you know you're relying upon features that were dropped or changed in later service packs.
Installing the "Cumulative update rollup for the Visual Basic 6.0 Service Pack 6 Runtime Extended Files" (https://support.microsoft.com/en-us/help/957924/description-of-the-cumulative-update-rollup-for-the-visual-basic-6-0-s) resolved this error in my instance.
I am looking to create a Visual Studio AddIn which can help me launch my own debugging process. I want to keep the original F5 based debugging intact and hence i do not want to intercept that call and need a separate AddIn.
Any suggestions
The easiest way is to capture the system events/macros using an addin. It is really easy to override what vs does in these events. All the events are automatically fired when using the standard visual studio commands such as F5. This includes all of the standard visual studio shortcut keys, menus and tool bar buttons.
Create a new vs addin project and it will automatically add the code to attach the OnBeforeCommandEvent. In vb the event handler will look like the code below.
Friend Sub OnBeforeCommandEvent(sGuid As String, ID As Integer, CustomIn As Object, CustomOut As Object, ByRef CancelDefault As Boolean)
The event passes you sGuid and ID. You can resolve these two items to a macro string name (sCommandName) as follows:-
Dim objCommand As EnvDTE.Command
Try
objCommand = _applicationObject.Commands.Item(sGuid, ID)
Catch ex As Exception
'unknown guids can be ignored
Exit Sub
End Try
If objCommand Is Nothing Then Exit Sub
Dim sCommandName As String
sCommandName = objCommand.Name
nb: The _applicationObject is passed to your code when the addin starts. A new addin project will automatically inlude the following code for the OnConnection event, the first argument is the _applicationObject shown above.
OnConnection(ByVal application As Object
Once you have the sCommandName variable it will contain the name of a Visual Studio macro such as Debug.Start.
To override the Debug.Start functions then you would add some of your own code and remember to set CancelDefault to True before you exit the handler.
When you set CancelDefault to true Visual Studio will not run the standard macro which means you can run your own debugger when F5 is pressed.
These are Visual Studio macro names that are used during the build process. You can override as many or as few as you like. I have grouped them into their related functionality but you can handle them in any combination.
Select Case sCommandName
Case "Debug.Start", _
"Debug.StartWithoutDebugging"
System.Windows.Forms.MessageBox.Show("You clicked F5, we are overriding the debug process")
CancelDefault=true
Exit Sub
Case "ClassViewContextMenus.ClassViewProject.Rebuild", _
"ClassViewContextMenus.ClassViewProject.Build", _
"Build.RebuildOnlyProject", _
"Build.RebuildSelection", _
"Build.BuildOnlyProject", _
"Build.BuildSelection"
Case "Build.RebuildSolution", _
"Build.BuildSolution"
Case "ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance", _
"ClassViewContextMenus.ClassViewProject.Debug.StepIntonewinstance"
Case "Build.CleanSelection", _
"Build.CleanSolution", _
"ClassViewContextMenus.ClassViewProject.Clean"
Case "Build.SolutionConfigurations"
Is there way to automatically maximize the output window on hitting build and then to automatically restore to previous state when the build completes?
You could create a macro that builds the solution then activates the output window. For example:
DTE.ExecuteCommand("Build.BuildSolution")
DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
You could then replace the Build button or the build keyboard shortcut to execute that macro.
I could implement a solution using a combination of macros.
Part of the solution is in this SO question:
OnBuildBegin does not fire in Visual Studio Macro until I run it from Macro Explorer
And the other part is to use 2 exported window settings and to toggle them on build events.
Something like:
Public Sub BuildEvents_OnBuildBegin() Handles BuildEvents.OnBuildBegin
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:C:\Development\VsSettings\build_inprocess.vssettings")
End Sub
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) _
Handles BuildEvents.OnBuildDone
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:C:\Development\VsSettings\Two_Screen.vssettings")
End Sub
I just cannot for the life of me figure out why my build event macro is no longer firing. Any ideas?
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module EnvironmentEvents
Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, _
ByVal ProjectConfig As String, _
ByVal Platform As String, _
ByVal SolutionConfig As String, _
ByVal Success As Boolean) _
Handles BuildEvents.OnBuildProjConfigDone
If Success = False Then
'The build failed...cancel any further builds.
DTE.ExecuteCommand("Build.Cancel")
End If
End Sub
End Module
Have you tried running Windows Update? Are all the macros not working or just this one?