IDebugProgramProvider2::WatchForProviderEventsIDebugProgramProvider2::WatchForProviderEvents

Permet au processus de notification des événements de port.Allows the process to be notified of port events.

SyntaxeSyntax

HRESULT WatchForProviderEvents(  
   PROVIDER_FLAGS       Flags,  
   IDebugDefaultPort2*  pPort,  
   AD_PROCESS_ID        processId,  
   CONST_GUID_ARRAY     EngineFilter,  
   REFGUID              guidLaunchingEngine,  
   IDebugPortNotify2*   pEventCallback  
);  
int WatchForProviderEvents(  
   enum_PROVIDER_FLAGS   Flags,  
   IDebugDefaultPort2    pPort,  
   AD_PROCESS_ID         ProcessId,  
   CONST_GUID_ARRAY      EngineFilter,  
   ref Guid              guidLaunchingEngine,  
   IDebugPortNotify2     pEventCallback  
);  

ParamètresParameters

Flags
[in] Une combinaison d’indicateurs à partir de la PROVIDER_FLAGS énumération.[in] A combination of flags from the PROVIDER_FLAGS enumeration. Les indicateurs suivants sont classiques pour cet appel :The following flags are typical for this call:

IndicateurFlag DescriptionDescription
PFLAG_REMOTE_PORT L’appelant est en cours d’exécution sur l’ordinateur distant.Caller is running on remote machine.
PFLAG_DEBUGGEE L’appelant est en cours de débogage (informations supplémentaires sur le marshaling sont retournées pour chaque nœud).Caller is currently being debugged (additional information about marshalling is returned for each node).
PFLAG_ATTACHED_TO_DEBUGGEE L’appelant a été attaché à mais pas lancé par le débogueur.Caller was attached to but not launched by the debugger.
PFLAG_REASON_WATCH L’appelant souhaite surveiller les événements.Caller wants to watch for events. Si cet indicateur n’est pas défini.If this flag is not set. Ensuite, l’événement de rappel est supprimé et l’appelant ne reçoit plus les notifications.then the callback event is removed and the caller no longer receives notifications.

pPort
[in] Le port, le processus appelant s’exécute sur.[in] The port the calling process is running on.

processId
[in] Un AD_PROCESS_ID structure qui contient l’ID du processus qui contient le programme en question.[in] An AD_PROCESS_ID structure holding the ID of the process that contains the program in question.

EngineFilter
[in] Un tableau des GUID des moteurs de débogage associés au processus.[in] An array of GUIDs of debug engines associated with the process.

guidLaunchingEngine
[in] GUID du moteur de débogage qui a lancé ce processus (le cas échéant).[in] GUID of the debug engine that launched this process (if any).

pEventCallback
[in] Un IDebugPortNotify2 objet qui reçoit les notifications d’événements.[in] An IDebugPortNotify2 object that receives the event notifications.

Valeur de retourReturn Value

En cas de réussite, retourne S_OK; sinon, retourne un code d’erreur.If successful, returns S_OK; otherwise, returns an error code.

NotesRemarks

Lorsque l’appelant veut supprimer un gestionnaire d’événements qui a été établi avec un appel précédent à cette méthode, l’appelant transmet les mêmes paramètres, comme il le faisait la première fois, mais laisse hors tension le PFLAG_REASON_WATCH indicateur.When a caller wants to remove an event handler that was established with a previous call to this method, the caller passes the same parameters as it did the first time but leaves off the PFLAG_REASON_WATCH flag.

ExempleExample

L’exemple suivant montre comment implémenter cette méthode pour un CDebugEngine objet qui expose la IDebugProgramProvider2 interface.The following example shows how to implement this method for a CDebugEngine object that exposes the IDebugProgramProvider2 interface.

STDMETHODIMP CDebugEngine::WatchForProviderEvents(  
    PROVIDER_FLAGS Flags,   
    IDebugDefaultPort2 *pPort,   
    AD_PROCESS_ID processId,   
    CONST_GUID_ARRAY EngineFilter,   
    REFGUID guidLaunchingEngine,   
    IDebugPortNotify2 *pPortNotify)  
{  
    HRESULT hRes = E_FAIL;  

    if (EVAL(pPort != NULL) && EVAL(pPortNotify != NULL))  
    {  
        // We will only watch/send events about the process if the debugger  
        // is actually debugging the process, and only if this is an attach or a LoRIE launch  
        if (IsFlagSet(Flags, PFLAG_DEBUGGEE) &&  
            guidLaunchingEngine == GUID_NULL &&  
            processId.ProcessIdType == AD_PROCESS_ID_SYSTEM)  
        {  
            // We don't support WatchForProviderEvents when in interop mode  
            if (m_fInterop)  
            {  
                ASSERT(!"Shouldn't ever be called in interop mode");  
                hRes = E_FAIL;  
            }  
            else  
            {  
                if (IsFlagSet(Flags, PFLAG_REASON_WATCH))  
                {  
                    // QI to get IDebugEventCallback2 which is required.  
                    CComQIPtr<IDebugEventCallback2> pCallback(pPortNotify);  

                    ASSERT(pCallback != NULL);  
                    if ( pCallback != NULL )  
                    {  
                        // Register the callback  
                        hRes = this->InitDebugSession(pCallback);  

                        if ( S_OK == hRes )  
                        {  
                            // Get the IDebugProcess2 from the port and call AttachImpl  
                            CComPtr<IDebugProcess2> spProcess;  

                            hRes = pPort->GetProcess(processId, &spProcess);  

                            if (HREVAL(S_OK, hRes))  
                            {  
                                hRes = AttachImpl(spProcess, NULL, NULL, processId.ProcessId.dwProcessId, ATTACH_REASON_USER, NULL);  

                                if ( FAILED(hRes) && (!m_pPidList || 0 == m_pPidList->GetCount()) )  
                                    this->Cleanup();  
                            }  
                        }  
                        else  
                            this->Cleanup();  
                    }  
                    else  
                        hRes = E_FAIL;  
                }  
                else  
                {  
                    // Detach will be done by SDM calling on programs directly if there are managed programs.  

                    // This handling is the case where no managed code ever ran.  
                    if ( this->IsProcessBeingDebugged(processId.ProcessId.dwProcessId) )  
                    {  
                        ProgramList *pProgList = this->GetProgramListCopy();  

                        if ( EVAL(pProgList) )  
                        {  
                            if ( pProgList->GetCount() == 0)  
                            {  
                                CComPtr<ICorDebugProcess> pCorProcess;  

                                hRes = this->GetCorProcess(processId.ProcessId.dwProcessId, &pCorProcess);  

                                if (HREVAL(S_OK, hRes) )  
                                {  
                                    hRes = pCorProcess->Stop(INFINITE);  

                                    if ( HREVAL(S_OK, hRes) )  
                                        hRes = pCorProcess->Detach();  
                                }  

                                // Tell the engine that it should unregister this process from com+  
                                this->UnregisterProcess(processId.ProcessId.dwProcessId);  

                                // If there are no more pids left then cleanup everything.  
                                if ( 0 == m_pPidList->GetCount() )  
                                    this->Cleanup();  
                            }  
                            // This is needed for cases where the SDM has not yet recieved program create  
                            // by the time that we need to detach (example: the managed attach succeeds,  
                            // but some other attach step fails).  
                            else  
                            {  
                                PROGNODE *pProgNode = NULL;  
                                while ( pProgNode = pProgList->Next(pProgNode) )  
                                {  
                                    CDebugProgram * pProgram = ((CDebugProgram *)pProgNode->data);  
                                    hRes = pProgram->Detach();  
                                }  
                            }  

                            delete pProgList;  
                        }  
                    }  
                    else  
                        hRes = S_OK;  
                }  
            }  
        }  
        else  
        {  
            hRes = S_FALSE;  
        }  
    }  
    else  
    {  
        hRes = E_INVALIDARG;  
    }  

    return hRes;  
}  

Voir aussiSee Also

IDebugProgramProvider2 IDebugProgramProvider2
PROVIDER_FLAGS PROVIDER_FLAGS
AD_PROCESS_ID AD_PROCESS_ID
CONST_GUID_ARRAY CONST_GUID_ARRAY
IDebugDefaultPort2 IDebugDefaultPort2
IDebugPortNotify2IDebugPortNotify2