MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / SendCmdArgsToSelf

Method SendCmdArgsToSelf

cppcryptfs/cppcryptfs.cpp:485–529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

483
484
485void CcppcryptfsApp::SendCmdArgsToSelf(HANDLE hPipe)
486{
487
488 HWND hWnd = ::FindWindow(L"#32770", L"cppcryptfs");
489 if (!hWnd)
490 return;
491
492 DWORD win_proc_id = 0;
493
494 GetWindowThreadProcessId(hWnd, &win_proc_id);
495
496 if (win_proc_id != ::GetCurrentProcessId())
497 return;
498
499 static_assert(sizeof(WCHAR) == sizeof(wchar_t), "sizeof(WCHAR) != sizeof(wchar_t).");
500 COPYDATASTRUCT cd;
501 memset(&cd, 0, sizeof(cd));
502 cd.dwData = CPPCRYPTFS_COPYDATA_PIPE;
503
504 std::vector<HANDLE> pipe_v;
505
506 pipe_v.push_back(hPipe);
507
508 cd.cbData =static_cast<DWORD>(sizeof(hPipe));
509
510 cd.lpData = static_cast<PVOID>(&pipe_v[0]);
511
512 SetLastError(0);
513 SendMessageW(hWnd, WM_COPYDATA, NULL, (LPARAM)&cd);
514 DWORD dwErr = GetLastError();
515 if (dwErr) {
516 if (dwErr == ERROR_ACCESS_DENIED) {
517 ConsoleErrMesPipe(L"SendMessage() returned error \"access denied\".\n\nPerhaps there is"
518 " already an instance of cppcryptfs running with administrator\nprivileges, but"
519 " you invoked this instance of cppcryptfs from a command prompt\nthat is not running"
520 " with administrator privileges.\n\nIf this is the case, then you should start a"
521 " CMD.exe window using\n\"Run as administrator\" and invoke cppcryptfs from within it.", hPipe);
522 } else {
523 WCHAR buf[80];
524 _snwprintf_s(buf, _TRUNCATE, L"SendMessage() returned error code %u", dwErr);
525 ConsoleErrMesPipe(buf, hPipe);
526 }
527 }
528
529}
530

Callers 1

NamedPipeServerCallbackFunction · 0.80

Calls 1

ConsoleErrMesPipeFunction · 0.85

Tested by

no test coverage detected