Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# classes Pin
Gerry Schmitz11-Jan-17 8:26
mveGerry Schmitz11-Jan-17 8:26 
QuestionHow to dynamically Add and Close tab items in Browser click on add and close buttons Pin
Aniruddha.A10-Jan-17 18:53
Aniruddha.A10-Jan-17 18:53 
AnswerRe: How to dynamically Add and Close tab items in Browser click on add and close buttons Pin
Afzaal Ahmad Zeeshan11-Jan-17 0:03
professionalAfzaal Ahmad Zeeshan11-Jan-17 0:03 
QuestionUse of LevDan.Exif assembly for DNG files?? Pin
Grahame_20059-Jan-17 23:33
Grahame_20059-Jan-17 23:33 
AnswerRe: Use of LevDan.Exif assembly for DNG files?? Pin
Pete O'Hanlon10-Jan-17 2:30
mvePete O'Hanlon10-Jan-17 2:30 
GeneralRe: Use of LevDan.Exif assembly for DNG files?? Pin
Grahame_200510-Jan-17 3:43
Grahame_200510-Jan-17 3:43 
GeneralRe: Use of LevDan.Exif assembly for DNG files?? Pin
Pete O'Hanlon10-Jan-17 4:29
mvePete O'Hanlon10-Jan-17 4:29 
QuestionProgrammatically Open A Solution In Current IDE Pin
Kevin Marois9-Jan-17 10:31
professionalKevin Marois9-Jan-17 10:31 
Using VS2015.

I'm trying to write some code that gives a list a solutions, and when clicked, opens that solution in the CURRENT instance of VS.

So far I have this:
    public static class AutomateVS
    {
        [DllImport("ole32.dll")]
        private static extern int CreateBindCtx(uint reserved, out IBindCtx ppbc);

        public static DTE GetDTE(int processId)
        {
            string progId = "!VisualStudio.DTE.14.0:" + processId.ToString();
            object runningObject = null;

            IBindCtx bindCtx = null;
            IRunningObjectTable rot = null;
            IEnumMoniker enumMonikers = null;

            try
            {
                Marshal.ThrowExceptionForHR(CreateBindCtx(reserved: 0, ppbc: out bindCtx));
                bindCtx.GetRunningObjectTable(out rot);
                rot.EnumRunning(out enumMonikers);

                IMoniker[] moniker = new IMoniker[1];
                IntPtr numberFetched = IntPtr.Zero;
                while (enumMonikers.Next(1, moniker, numberFetched) == 0)
                {
                    IMoniker runningObjectMoniker = moniker[0];

                    string name = null;

                    try
                    {
                        if (runningObjectMoniker != null)
                        {
                            runningObjectMoniker.GetDisplayName(bindCtx, null, out name);
                        }
                    }
                    catch (UnauthorizedAccessException)
                    {
                        // Do nothing, there is something in the ROT that we do not have access to.
                    }

                    if (!string.IsNullOrEmpty(name) && name.Contains("!VisualStudio.DTE.14.0:"))
                    {
                        rot.GetObject(runningObjectMoniker, out runningObject);
                        break;
                    }
                    if (!string.IsNullOrEmpty(name) && string.Equals(name, progId, StringComparison.Ordinal))
                    {
                        Marshal.ThrowExceptionForHR(rot.GetObject(runningObjectMoniker, out runningObject));
                        break;
                    }
                }
            }
            finally
            {
                if (enumMonikers != null)
                {
                    Marshal.ReleaseComObject(enumMonikers);
                }

                if (rot != null)
                {
                    Marshal.ReleaseComObject(rot);
                }

                if (bindCtx != null)
                {
                    Marshal.ReleaseComObject(bindCtx);
                }
            }

            return (DTE)runningObject;

        }

    }
}

and use it like this
var process = System.Diagnostics.Process.GetCurrentProcess();
var id = process.Id;
_envDTE = AutomateVS.GetDTE(id);

if (_envDTE != null)
{
    _envDTE.Solution.Open(solutionFile);
}

But it opens in the wrong VS instance. I need it to open in the instance my app is running in.

Anyone know what's wrong?

Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.

AnswerRe: Programmatically Open A Solution In Current IDE Pin
Afzaal Ahmad Zeeshan11-Jan-17 0:09
professionalAfzaal Ahmad Zeeshan11-Jan-17 0:09 
QuestionNothing happens when CheckBox is checked Pin
Pavlex49-Jan-17 8:00
Pavlex49-Jan-17 8:00 
AnswerRe: Nothing happens when CheckBox is checked Pin
NotPolitcallyCorrect9-Jan-17 8:17
NotPolitcallyCorrect9-Jan-17 8:17 
AnswerRe: Nothing happens when CheckBox is checked Pin
Richard MacCutchan9-Jan-17 22:30
mveRichard MacCutchan9-Jan-17 22:30 
QuestionC# Enumerable Repeat Pin
Pavlex48-Jan-17 4:01
Pavlex48-Jan-17 4:01 
AnswerRe: C# Enumerable Repeat PinPopular
OriginalGriff8-Jan-17 4:49
mveOriginalGriff8-Jan-17 4:49 
AnswerRe: C# Enumerable Repeat Pin
Pete O'Hanlon8-Jan-17 23:01
mvePete O'Hanlon8-Jan-17 23:01 
GeneralRe: C# Enumerable Repeat Pin
harold aptroot9-Jan-17 8:20
harold aptroot9-Jan-17 8:20 
QuestionVisual Studio Debugger Questions Pin
zequion7-Jan-17 21:15
professionalzequion7-Jan-17 21:15 
AnswerRe: Visual Studio Debugger Questions Pin
Slacker0077-Jan-17 21:22
professionalSlacker0077-Jan-17 21:22 
GeneralRe: Visual Studio Debugger Questions Pin
zequion8-Jan-17 19:27
professionalzequion8-Jan-17 19:27 
GeneralRe: Visual Studio Debugger Questions Pin
Dave Kreskowiak9-Jan-17 2:52
mveDave Kreskowiak9-Jan-17 2:52 
GeneralRe: Visual Studio Debugger Questions Pin
zequion9-Jan-17 3:18
professionalzequion9-Jan-17 3:18 
GeneralRe: Visual Studio Debugger Questions Pin
Richard MacCutchan9-Jan-17 3:51
mveRichard MacCutchan9-Jan-17 3:51 
AnswerRe: Visual Studio Debugger Questions Pin
Jon McKee8-Jan-17 20:50
professionalJon McKee8-Jan-17 20:50 
QuestionCommon Variables in Main, Dlls, and Functions in .cs Pin
zequion7-Jan-17 21:11
professionalzequion7-Jan-17 21:11 
AnswerRe: Common Variables in Main, Dlls, and Functions in .cs Pin
Richard MacCutchan7-Jan-17 21:28
mveRichard MacCutchan7-Jan-17 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.