포트 가져오기
포트는 프로세스가 실행 중인 머신에 대한 연결을 나타냅니다. 해당 머신은 로컬 머신 또는 원격 머신일 수 있습니다(Windows 기반이 아닌 운영 체제를 실행할 수 있음, 자세한 내용은 포트 참조).
포트는 IDebugPort2 인터페이스로 표시됩니다. 포트가 연결된 머신에서 실행되는 프로세스에 대한 정보를 가져오는 데 사용됩니다.
디버그 엔진은 포트에 프로그램 노드를 등록하고 프로세스 정보에 대한 요청을 충족하기 위해 포트에 액세스해야 합니다. 예를 들어 디버그 엔진이 IDebugProgramProvider2 인터페이스를 구현하는 경우 GetProviderProcessData 메서드에 대한 구현은 포트에 필요한 프로세스 정보를 반환하도록 요청할 수 있습니다.
Visual Studio는 디버그 엔진에 필요한 포트를 제공하고 포트 공급자로부터 이 포트를 가져옵니다. 프로그램이 연결된 경우(디버거 내에서 또는 예외가 throw되어, JIT[Just-In-Time] 대화 상자를 트리거함) 사용자에게 사용할 전송(포트 공급자의 다른 이름)을 선택할 수 있습니다. 그렇지 않으면 사용자가 디버거 내에서 프로그램을 시작하면 프로젝트 시스템에서 사용할 포트 공급자를 지정합니다. 두 이벤트 중 하나에서 Visual Studio는 IDebugPortSupplier2 인터페이스로 표현되는 포트 공급자를 인스턴스화하고 IDebugPortRequest2 인터페이스를 사용하여 AddPort를 호출하여 새 포트를 요청합니다. 그런 다음, 이 포트는 하나의 양식 또는 다른 양식으로 디버그 엔진에 전달됩니다.
예시
이 코드 조각에서는 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);
}