Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving images from the Clipboard using pure API
    primarykey
    data
    text
    <p>I'm having trouble saving images from the clipboard using pure API.</p> <p>Here is my code. It creates 20 empty bmp files. I have checked dwSize and it is correct so it seems I am retreiving the data correctly, but I am writing to a file incorrectly.</p> <pre><code> program WebcamTest; //cswi uses Windows; const WM_CAP_DRIVER_CONNECT = 1034; WM_CAP_GRAB_FRAME = 1084; //WM_CAP_SAVEDIB = 1049; WM_CAP_EDIT_COPY = 1054; WM_CAP_DRIVER_DISCONNECT = 1035; function SendMessageA(hWnd: Integer; Msg: Integer; wParam: Integer; lParam: Integer): Integer; stdcall; external 'user32.dll' name 'SendMessageA'; function capGetDriverDescriptionA(DrvIndex: Cardinal; Name: PAnsiChar; NameLen: Integer; Description: PAnsiChar; DescLen: Integer) : Boolean; stdcall; external 'avicap32.dll' name 'capGetDriverDescriptionA'; function capCreateCaptureWindowA(lpszWindowName: PAnsiChar; dwStyle: Integer; x : Integer; y : Integer; nWidth : Integer; nHeight : Integer; ParentWin: Integer; nId: Integer): Integer; stdcall; external 'avicap32.dll' name 'capCreateCaptureWindowA'; function IntToStr(i: Integer): String; begin Str(i, Result); end; var WebCamId : Integer; CaptureWindow : Integer; x : Integer; FileName : PAnsiChar; hData: DWORD; pData: Pointer; dwSize: DWORD; szText : AnsiString; FileHandle, BytesWritten : LongWord; begin WebcamId := 0; CaptureWindow := capCreateCaptureWindowA('CaptureWindow', 0, 0, 0, 0, 0, 0, 0); if CaptureWindow &lt;&gt; 0 then begin if SendMessageA(CaptureWindow, WM_CAP_DRIVER_CONNECT, WebCamId, 0) &lt;&gt; 1 then begin SendMessageA(CaptureWindow, WM_CAP_DRIVER_DISCONNECT, 0, 0); end else begin for x := 1 to 20 do // Take 20 photos. begin SendMessageA(CaptureWindow, WM_CAP_GRAB_FRAME, 0, 0); FileName := PAnsiChar('C:\Test' + IntToStr(x) + '.bmp'); //SendMessageA(CaptureWindow, WM_CAP_SAVEDIB, 0, LongInt(FileName)); SendMessageA(CaptureWindow, WM_CAP_EDIT_COPY, 0, LongInt(FileName)); if OpenClipBoard(0) then begin hData := GetClipBoardData(CF_DIB); if hData &lt;&gt; 0 then begin pData := GlobalLock(hData); if pData &lt;&gt; nil then begin dwSize := GlobalSize(hData); if dwSize &lt;&gt; 0 then begin FileHandle := CreateFileA(FileName, GENERIC_WRITE, FILE_SHARE_WRITE, nil, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN, 0); WriteFile(FileHandle, pData, dwSize, BytesWritten, nil); CloseHandle(FileHandle); end; GlobalUnlock(DWORD(pData)); end; end; CloseClipBoard; end; end; end; SendMessageA(CaptureWindow, WM_CAP_DRIVER_DISCONNECT, 0, 0); end; end. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload