Wednesday, 11 September 2013

Can't GET the Message.WParam data

Can't GET the Message.WParam data

I Have an DLL file sent to my application message when I got message I
must do this:
If the trigger is pulled, the image data is sent to the DLL. WM_XFERSTATUS
is sent to the host application with
information about the size of the image.
When the first transfer status message is received, the host application
should provide a destination buffer for
the image by calling SNAPI_SetImageBuffer. After the entire image is
transferred from the scanner to the DLL,
the application receives a Windows message indicating that the image data
was stored.
And when start get the image i get the message:
Message WM_XFERSTATUS
Description Image data is transferring from the scanner.
Table 1-1 Windows Messages (Continued)
Attribute Description
DLL Data, Error Reporting, Messages & Beep Codes 1 - 5
Value WM_APP+7
Parameters • wParam – Pointer to DWPARAM structure (cast to DWPARAM *).
• LODWORD (wparam) – The total number of bytes received so far.
• HIDWORD (wparam) – The total number of bytes expected.
• lParam – Handle to the device for which the message was posted.
and when finishing the transfer image data I get the message:
Message WM_IMAGE
Description Image data is available from the scanner and is stored in the
buffer provided by a previous call
to SNAPI_SetImageBuffer.
Value WM_APP+2
Parameters • wParam – Pointer to DWPARAM structure (cast to DWPARAM *)
• LODWORD (wparam) – The buffer status of the data stored
• HIDWORD (wparam) – The length of the data in bytes
• lParam – Handle to the device for which the message was posted
Data Format Actual image data.
I make this code for get the message and when set length of the data i
have raised error:
type
TScanner = class
public
Device: THandle;
Connected: Boolean;
ImageData: array of Byte;
Pending: Boolean;
procedure Connect;
procedure Disconnect;
procedure RequestSnapshot;
procedure SetImageBuffer(Size: Integer);
end;
procedure TMyform.FormCreate(Sender: TObject);
var
Devices: array[0..MAX_SCANNER-1] of THandle;
NumScanners, I: Integer;
Scanner: TScanner;
begin
Scanners := TObjectList.Create;
ScannerWnd := AllocateHWnd(ScannerWndProc);
CheckSNAPIStatus(SNAPI_Init(ScannerWnd, Devices[0], NumScanners));
for I := 0 to NumScanners-1 do
begin
Scanner := TScanner.Create;
Scanner.Device := Devices[I];
Scanners.Add(Scanner);
// add it to the UI somewhere...
end;
end;
procedure TMyform.FormDestroy(Sender: TObject);
begin
DeallocateHWnd(ScannerWnd);
Scanners.Free;
end;
procedure TScanner.SetImageBuffer(Size: Integer);
begin
SetLength(ImageData, Size); //Hear I get the error
SNAPI_SetImageBuffer(Device, Pointer(ImageData), Length(ImageData));
end;
procedure TMyform.ScannerWndProc(var Message: TMessage);
var
Scanner: TScanner;
begin
case Message.Msg of
WM_XFERSTATUS:
begin
Scanner.SetImageBuffer(HiDWord(Message.WParam));
end;
WM_IMAGE:
begin
if (LO(Message.WParam) and BUFFERSIZE_MASK) <> BUFFERSIZE_GOOD then
raise Exception.Create('Image buffer error');
// use Scanner.ImageData up to HIDWORD(Message.WParam) bytes as
needed...
SetLength(Scanner.ImageData, 0);
end;
NOTE: I used the HIDWORD function but it is not working in delphi i
replaced it with HIWORD function please how to get the IMAGE DATA

No comments:

Post a Comment