포트는 프로세스가 실행 중인 컴퓨터에 대한 연결을 나타냅니다. 해당 컴퓨터는 로컬 컴퓨터 또는 원격 컴퓨터일 수 있습니다(Windows 기반이 아닌 운영 체제를 실행할 수 있음) 자세한 내용은 포트 를 참조하세요.
포트는 IDebugPort2 인터페이스로 표시됩니다. 포트가 연결된 컴퓨터에서 실행되는 프로세스에 대한 정보를 가져오는 데 사용됩니다.
디버그 엔진은 포트에 프로그램 노드를 등록하고 프로세스 정보에 대한 요청을 충족하기 위해 포트에 액세스해야 합니다. 예를 들어 디버그 엔진이 IDebugProgramProvider2 인터페이스를 구현하는 경우 GetProviderProcessData 메서드의 구현은 포트에 필요한 프로세스 정보를 반환하도록 요청할 수 있습니다.
Visual Studio는 디버그 엔진에 필요한 포트를 제공하고 포트 공급자로부터 이 포트를 가져옵니다. 프로그램이 디버거 내에서 연결되었거나 예외가 발생하여 JIT(Just-In-Time) 대화 상자가 트리거된 경우, 사용자에게 사용할 전송 수단(포트 공급자의 다른 명칭)을 선택할 수 있는 옵션이 제공됩니다. 그렇지 않으면 사용자가 디버거 내에서 프로그램을 시작하면 프로젝트 시스템에서 사용할 포트 공급자를 지정합니다. 두 이벤트 중 하나에서 Visual Studio는 IDebugPortSupplier2 인터페이스로 표시되는 포트 공급자를 인스턴스화하고 IDebugPortRequest2 인터페이스를 사용하여 AddPort를 호출하여 새 포트를 요청합니다. 그런 다음 이 포트는 한 폼 또는 다른 형식으로 디버그 엔진에 전달됩니다.
Example
이 코드 조각에서는 LaunchSuspended 에 제공된 포트를 사용하여 ResumeProcess에 프로그램 노드를 등록하는 방법을 보여 줍니다. 이 개념과 직접 관련이 없는 매개 변수는 명확성을 위해 생략되었습니다.
비고
이 예제에서는 포트를 사용하여 프로세스를 시작하고 다시 시작하고 IDebugPortEx2 인터페이스가 포트에서 구현된다고 가정합니다. 이것은 반드시 이러한 작업을 수행할 수 있는 유일한 방법은 아니며, 프로그램의 IDebugProgramNode2 를 지정하는 것 외에는 포트가 관련되지 않을 수도 있습니다.
// This is an IDebugEngineLaunch2 method.
HRESULT CDebugEngine::LaunchSuspended(/* omitted parameters */,
IDebugPort2 *pPort,
/* omitted parameters */,
IDebugProcess2**ppDebugProcess)
{
// do stuff here to set up for a launch (such as handling the other parameters)
...
// Now get the IPortNotify2 interface so we can register a program node
// in CDebugEngine::ResumeProcess.
CComPtr<IDebugDefaultPort2> spDefaultPort;
HRESULT hr = pPort->QueryInterface(&spDefaultPort);
if (SUCCEEDED(hr))
{
CComPtr<IDebugPortNotify2> spPortNotify;
hr = spDefaultPort->GetPortNotify(&spPortNotify);
if (SUCCEEDED(hr))
{
// Remember the port notify so we can use it in ResumeProcess.
m_spPortNotify = spPortNotify;
// Now launch the process in a suspended state and return the
// IDebugProcess2 interface
CComPtr<IDebugPortEx2> spPortEx;
hr = pPort->QueryInterface(&spPortEx);
if (SUCCEEDED(hr))
{
// pass on the parameters we were given (omitted here)
hr = spPortEx->LaunchSuspended(/* omitted parameters */,ppDebugProcess)
}
}
}
return(hr);
}
HRESULT CDebugEngine::ResumeProcess(IDebugProcess2 *pDebugProcess)
{
// Make a program node for this process
HRESULT hr;
CComPtr<IDebugProgramNode2> spProgramNode;
hr = this->GetProgramNodeForProcess(pProcess, &spProgramNode);
if (SUCCEEDED(hr))
{
hr = m_spPortNotify->AddProgramNode(spProgramNode);
if (SUCCEEDED(hr))
{
// resume execution of the process using the port given to us earlier.
// (Querying for the IDebugPortEx2 interface is valid here since
// that's how we got the IDebugPortNotify2 interface in the first place.)
CComPtr<IDebugPortEx2> spPortEx;
hr = m_spPortNotify->QueryInterface(&spPortEx);
if (SUCCEEDED(hr))
{
hr = spPortEx->ResumeProcess(pDebugProcess);
}
}
}
return(hr);
}