Attaches the specified profiler to the specified process.
HRESULT AttachProfiler( [in] DWORD dwProfileeProcessID, [in] DWORD dwMillisecondsMax, // optional [in] const CLSID * pClsidProfiler, [in] LPCWSTR wszProfilerPath, // optional [in] size_is(cbClientData)] void * pvClientData, // optional [in] UINT cbClientData); // optional
This method returns the following HRESULTs.
The specified profiler has successfully attached to the target process.
There is already a profiler active or attaching to the target process.
The specified profiler does not support attachment. The trigger process may attempt to attach a different profiler.
Unable to request a profiler attachment, because the version of the target process is incompatible with the current process that is calling AttachProfiler.
The user of the trigger process does not have access to the target process.
The user of the trigger process does not have the privileges necessary to attach a profiler to the given target process. The application event log may contain more information.
A failure occurred when communicating with the target process. This commonly happens if the target process was shutting down.
The target process does not exist or is not running a CLR that supports attachment. This may indicate that the CLR was unloaded since the call to the runtime enumeration method.
The timeout expired without beginning to load the profiler. You can retry the attach operation. Timeouts occur when a finalizer in the target process runs for a longer time than the timeout value.
One or more parameters have invalid values.
Some other, unspecified failure occurred.
Other error codes
If the profiler’s ICorProfilerCallback3::InitializeForAttach method returns an HRESULT that indicates failure, AttachProfiler returns that same HRESULT. In this case, E_NOTIMPL is converted to CORPROF_E_PROFILER_NOT_ATTACHABLE.
For more information about attaching and detaching profilers, see Profiler Attach and Detach.
In keeping with COM conventions, the caller of AttachProfiler (for example, the trigger code authored by the profiler developer) is responsible for allocating and de-allocating the memory for the data that the pvClientData parameter points to. When the CLR executes the AttachProfiler call, it makes a copy of the memory that pvClientData points to and transmits it to the target process. When the CLR inside the target process receives its own copy of the pvClientData block, it passes the block to the profiler through the InitializeForAttach method, and then deallocates its copy of the pvClientData block from the target process.
Platforms: See .NET Framework System Requirements.
Header: CorProf.idl, CorProf.h
.NET Framework Versions: 4