Created
September 17, 2022 11:05
-
-
Save chrisnas/98de6677ffb582e374699667a5fc5f95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int BasicConnection(DWORD pid) | |
{ | |
wchar_t pszPipeName[256]; | |
// build the pipe name as described in the protocol | |
int nCharactersWritten = -1; | |
nCharactersWritten = wsprintf( | |
pszPipeName, | |
L"\\\\.\\pipe\\dotnet-diagnostic-%d", | |
pid | |
); | |
// check that CLR has created the diagnostics named pipe | |
if (!::WaitNamedPipe(pszPipeName, 200)) | |
{ | |
auto error = ::GetLastError(); | |
std::cout << "Diagnostics named pipe is not available for process #" << pid << " (" << error << ")" << "\n"; | |
return -1; | |
} | |
// connect to the named pipe | |
HANDLE hPipe; | |
hPipe = ::CreateFile( | |
pszPipeName, // pipe name | |
GENERIC_READ | // read and write access | |
GENERIC_WRITE, | |
0, // no sharing | |
NULL, // default security attributes | |
OPEN_EXISTING, // opens existing pipe | |
0, // default attributes | |
NULL); // no template file | |
if (hPipe == INVALID_HANDLE_VALUE) | |
{ | |
std::cout << "Impossible to connect to " << pszPipeName << "\n"; | |
return -2; | |
} | |
// ... send a command... | |
// don't forget to close the named pipe | |
::CloseHandle(hPipe); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment