註冊程式
如需 Visual Studio 2017 的最新文件請參閱 Visual Studio 2017 文件。
偵錯引擎取得連接埠之後,由IDebugPort2介面,讓偵錯程式下一步是註冊該連接埠。 註冊之後,程式會有可供偵錯由下列方式的其中一個︰
程序的連接,可讓偵錯工具,來取得執行中應用程式的完整控制權限偵錯。
在 just-in-time (JIT) 偵錯時,可用來執行與偵錯工具無關的程式偵錯之後事實。 當執行階段架構會攔截錯誤時,作業系統之前先通知偵錯工具,或執行階段環境釋放的記憶體和資源失敗的程式。
註冊程序
若要註冊您的程式
呼叫AddProgramNode連接埠所實作的方法。
IDebugPortNotify2::AddProgramNode
需要指標IDebugProgramNode2介面。一般而言,當作業系統或執行階段環境會在載入程式,它會建立程式節點。 如果偵錯引擎 (DE) 會要求載入程式 DE 會建立並註冊程式節點。
下列範例會顯示啟動程式,然後註冊與連接埠的偵錯引擎。
注意
這不是唯一的方式來啟動,並繼續處理程序。這是主要登錄程式與連接埠的範例。
// 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 paramters */,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); }