#include "GdiPlus.h" using namespace Gdiplus; __declspec( dllexport ) int _stdcall CaptureToJPEG( LPCSTR FileName ) { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; RECT r; ::GetWindowRect(GetDesktopWindow(), &r); HDC dc = ::GetWindowDC(0); HDC memDC = ::CreateCompatibleDC(dc); HBITMAP bm = ::CreateCompatibleBitmap(dc, (r.right-r.left), (r.bottom-r.top)); HBITMAP oldbm = (HBITMAP) ::SelectObject(memDC, bm); ::BitBlt(memDC, 0, 0, r.right-r.left, r.bottom-r.top, dc, 0, 0, SRCCOPY); ::ReleaseDC(0, dc); ::SelectObject(memDC, oldbm); ::DeleteDC(memDC); // Initialize GDI+ GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); { Bitmap img(bm, NULL); wchar_t fn[MAX_PATH]; MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, FileName, -1, fn, MAX_PATH); CLSID jpegClsid; int result = GetCodecClsid(L"image/jpeg", &jpegClsid); img.Save(fn, &jpegClsid); } GdiplusShutdown(gdiplusToken); return 0; }You'll get the VC++ project and compiled DLL by email. Sorry, there is no error and exception handling.
Declare Integer CaptureToJPEG in Capture.dll String FileName CaptureToJPEG("screenshot.jpg")If you would prefer to make a COM library, then instead of Declare you will use CreateObject().