Re[3]: from C to delphi
От: randydom  
Дата: 17.10.09 10:30
Оценка:
Здравствуйте, wallaby, Вы писали:

W>Здравствуйте, randydom, Вы писали:


R>>I use and declare the function FilterConnectCommunicationPort as follows :

R>>function FilterConnectCommunicationPort(lpPortName: pWideChar; dwOptions: DWORD;
R>> lpContect: pBYTE; wSizeOfContext: WORD; lpSecurityAttributes: PSECURITY_ATTRIBUTES; hPort: PHANDLE): HRESULT;stdcall; external 'FLTLIB.dll';

W>from MSDN:

W>
W>HRESULT
W>WINAPI
W>  FilterConnectCommunicationPort(
W>    IN LPCWSTR  lpPortName,
W>    IN DWORD  dwOptions,
W>    IN LPVOID  lpContext OPTIONAL,
W>    IN DWORD  dwSizeOfContext, // <== DWORD
W>    IN LPSECURITY_ATTRIBUTES  lpSecurityAttributes OPTIONAL,
W>    OUT HANDLE  *hPort
W>    ); 
W>


I DID it but i get an Exception :
Scanner : Error replying message .Error = 0x800703E6

Here's my Code :

function ScannerWorker(Context:PSCANNER_THREAD_CONTEXT): DWORD; 

var 
notification: PSCANNER_NOTIFICATION; 
replyMessage: SCANNER_REPLY_MESSAGE; 
msg: PSCANNER_MESSAGE; 
pOvlp:POVERLAPPED; 
bResult: BOOL; 
outSize: DWORD; 
hr: HRESULT; 
key: DWORD; 

begin 

While True Do 
    begin 
   bResult := GetQueuedCompletionStatus(Context^.Completion,OutSize,Key,pOvlp,INFINITE); 
  
    Msg := PSCANNER_MESSAGE(@PSCANNER_MESSAGE(pOvlp)^.Ovlp); 
    If Not(bResult) Then 
      begin 
      HR := HRESULT_FROM_WIN32(GetLastError()); 
      Break; 
    end; 

    WriteLN(Format('Received message: %d',[pOvlp.InternalHigh])); 
    notification := @msg.Notification; 
    assert(notification.BytesToScan<=SCANNER_READ_BUFFER_SIZE); 
   // result := ScanBuffer( notification^.Contents, notification.BytesToScan ); 
     replyMessage.ReplyHeader.Status:= 0; 
    replyMessage.ReplyHeader.MessageId:= msg.MessageHeader.MessageId; 

    replyMessage.Reply.SafeToOpen:=not bResult; 

    
   WriteLN(Format('Replying message, SafeToOpen: %d',[ReplyMessage.Reply.SafeToOpen])); 

    HR := FilterReplyMessage(Context^.Port,PFILTER_REPLY_HEADER(@ReplyMessage),SizeOf(ReplyMessage)); 
    If SUCCEEDED(HR) Then 
      begin 
      WriteLN('Replied message'); 
    end 
    Else 
      begin 
WriteLN(('Scanner: Error replying message. Error = 0x'+inttoHex(HR,2)));//EXCEPTION:0x800703E6 
      Break; 
    end; 
   FillChar(Msg^.FOverlapped,0,SizeOf(OVERLAPPED)); 
    //#define FIELD_OFFSET(t, f)    ((unsigned int)(unsigned long)&(((t *)0)->f)) 
  

    HR := FilterGetMessage(Context^.Port,@Msg^.MessageHeader,DWORD(@PSCANNER_MESSAGE(0)^.FOverlapped),@Msg^.FOverlapped); 
    If HR <> HRESULT_FROM_WIN32(ERROR_IO_PENDING) Then Break; 
  end; 
  If Not(SUCCEEDED(HR)) Then 
    begin 
    If HR = HRESULT_FROM_WIN32(ERROR_INVALID_HANDLE) Then 
      begin 
      WriteLN('Scanner: Port is disconnected, probably due to scanner filter unloading.'); 
    end 
    Else 
      begin 
      WriteLN(Format('Scanner: Unknown error occured. Error = 0x%x',<hr>)); 
    end; 
  end; 
  FreeMem(Msg); 
  Result := HR; 


end;


Please where's the Error ?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.