Campo VsDebugTargetInfo2.bstrEnv

 

BSTR que contém as configurações do ambiente (DLO_CreateProcess).

Namespace:   Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop.8.0 (em Microsoft.VisualStudio.Shell.Interop.8.0.dll)

Sintaxe

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

Valor de Campo

Type: System.String

Comentários

Este campo é usado para definir variáveis de ambiente personalizadas.Observe que bstrEnv deve ser um bloco terminada por caractere nulo de seqüências de caracteres terminada por caractere nulo.Você também deve passar a DBGLAUNCH_MergeEnv a LaunchFlags para especificar que você deseja que as variáveis de ambiente de sistema padrão a ser mesclado com o que você está especificando.Para obter mais informações, consulte a seção lpEnvironment no tópico CreateProcess.

Este é um exemplo de definição deste campo corretamente.

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();
} 

Consulte também

Estrutura VsDebugTargetInfo2
Namespace Microsoft.VisualStudio.Shell.Interop

Retornar ao topo