Udostępnij za pośrednictwem


Pole VsDebugTargetInfo2.bstrEnv

 

BSTR zawierające ustawienia ochrony środowiska (DLO_CreateProcess).

Przestrzeń nazw:   Microsoft.VisualStudio.Shell.Interop
Zestaw:  Microsoft.VisualStudio.Shell.Interop.8.0 (w Microsoft.VisualStudio.Shell.Interop.8.0.dll)

Składnia

public string bstrEnv
public:
String^ bstrEnv
val mutable bstrEnv : string
Public bstrEnv As String

Wartość pola

Type: System.String

Uwagi

To pole służy do ustawiania zmiennych środowiskowych niestandardowe.Uwaga, że bstrEnv powinny być zakończony znakiem null bloku ciągów zakończona znakiem null.Musi również przekazać DBGLAUNCH_MergeEnv w LaunchFlags, aby określić domyślne systemowe zmienne środowiskowe mają być scalane z są określanie.Aby uzyskać więcej informacji, zobacz sekcję lpEnvironment w temacie CreateProcess.

Poniżej przedstawiono przykład prawidłowego ustawienia tego pola.

void LaunchMyProcessesUnderDebugger()
{
    processes = new Process[numberOfHostInstances];
    VsDebugTargetInfo3[] debugTargetInfos = new VsDebugTargetInfo3[numberOfHostInstances];
    string argumentTemplate = "-arg1 \"{0}\" -arg {1} -arg3 {2}";
    for (int i = 0; i < count; i++)
    {
        string workingDirectory = ...;
        string arguments = string.Format(argumentTemplate, val1, val2, val3);

        debugTargetInfos[i] = new VsDebugTargetInfo3();....// create process; we don't already have a process to attach to
        // create process; we don't already have a process to attach to

        debugTargetInfos[i].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess;
        // attach managed debugger
        debugTargetInfos[i].guidLaunchDebugEngine = VSConstants.CLSID_ComPlusOnlyDebugEngine;
        // full path to an exe
        debugTargetInfos[i].bstrExe = debugTargetInfos[i].bstrCurDir = workingDirectory;
        debugTargetInfos[i].bstrArg = arguments;
        debugTargetInfos[i].pStartupInfo = IntPtr.Zero;

        Dictionary<string, string> environmentVariables = new Dictionary<string, string>();
        environmentVariables.Add(CustomEnvVar, EnvVarValue);
        // custom environment variables
        vdebugTargetInfos[i].bstrEnv = GetEnvironmentString(environmentVariables);
    }
    // Merge default environment variables with custom ones above.
    debugTargetInfos[i].LaunchFlags = (uint)__VSDBGLAUNCHFLAGS2.DBGLAUNCH_MergeEnv;....}
    VsDebugTargetProcessInfo[] tpi = new VsDebugTargetProcessInfo[numberOfHostInstances];
    int hr = debugger.LaunchDebugTargets3((uint)numberOfHostInstances, debugTargetInfos, tpi);
    Marshal.ThrowExceptionForHR(hr);

    for (int i = 0; i < count; i++)
    {
        processes[i] = Process.GetProcessById((int)tpi[i].dwProcessId);
    }
}

private static string GetEnvironmentString(IDictionary<string, string> environment)
{
    if (environment == null || environment.Count == 0)
    {
        return null;
    }
// Collect all the variables as a null delimited list of key=value pairs.
    StringBuilder result = new StringBuilder();
    foreach (var pair in environment)
    {
        result.Append(pair.Key);
        result.Append('=');
        result.Append(pair.Value);
        result.Append('\0');
    }
    // Add a final list-terminating null character. This is sent to native code as a BSTR and no null is added automatically. But the format of the data requires that this be a null-delimited, null-terminated list.
    result.Append('\0');
    return result.ToString();
} 

Zobacz też

Struktura VsDebugTargetInfo2
Przestrzeń nazw Microsoft.VisualStudio.Shell.Interop

Powrót do początku