Thema: Delphi From C to delphi

Einzelnen Beitrag anzeigen

mohfa

Registriert seit: 11. Feb 2007
97 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: From C to delphi

  Alt 10. Okt 2009, 09:24
Ok i did it Now i can connect to the Filter from my Delphi App :
the deal was to change : ScannerPortName:='\\ScannerPort' into ScannerPortName:='\ScannerPort';

** But i still someone's help in conevrting this into Delphi :
Code:
int _cdecl
main (
    __in int argc,
    __in_ecount(argc) char *argv[]
    )
{
    DWORD requestCount = SCANNER_DEFAULT_REQUEST_COUNT;
    DWORD threadCount = SCANNER_DEFAULT_THREAD_COUNT;
    HANDLE threads[SCANNER_MAX_THREAD_COUNT];
    SCANNER_THREAD_CONTEXT context;
    HANDLE port, completion;
    PSCANNER_MESSAGE msg;
    DWORD threadId;
    DWORD retVal = 0;
    HRESULT hr;
    DWORD i, j;
    //
    //  Check how many threads and per thread requests are desired.
    //
    if (argc > 1) {
        requestCount = atoi( argv[1] );
        if (argc > 2) {
            threadCount = atoi( argv[2] );
        }
        if (requestCount <= 0 || threadCount <= 0 || threadCount > 64) {
            Usage();
            return 1;
        }
    }
    //
    //  Open a commuication channel to the filter
    //
//
//FilterConnectCommunicationPort Now works with my DelphiApp
//
    printf( "Scanner: Connecting to the filter ...\n" );
    hr = FilterConnectCommunicationPort( ScannerPortName,
                                         0,
                                         NULL,
                                         0,
                                         NULL,
                                         &port );
    if (IS_ERROR( hr )) {
        printf( "ERROR: Connecting to filter port: 0x%08x\n", hr );
        return 2;
    }
    //
    //  Create a completion port to associate with this handle.
    //
    completion = CreateIoCompletionPort( port,
                                         NULL,
                                         0,
                                         threadCount );
    if (completion == NULL) {
        printf( "ERROR: Creating completion port: %d\n", GetLastError() );
        CloseHandle( port );
        return 3;
    }
    printf( "Scanner: Port = 0x%p Completion = 0x%p\n", port, completion );
    context.Port = port;
    context.Completion = completion;
    //
    //  Create specified number of threads.
    //
    for (i = 0; i < threadCount; i++) {
        threads[i] = CreateThread( NULL,
                                   0,
                                   ScannerWorker,
                                   &context,
                                   0,
                                   &threadId );
        if (threads[i] == NULL) {
            //
            //  Couldn't create thread.
            //
            hr = GetLastError();
            printf( "ERROR: Couldn't create thread: %d\n", hr );
            goto main_cleanup;
        }
        for (j = 0; j < requestCount; j++) {
            //
            //  Allocate the message.
            //
            msg = malloc( sizeof( SCANNER_MESSAGE ) );
            if (msg == NULL) {
                hr = ERROR_NOT_ENOUGH_MEMORY;
                goto main_cleanup;
            }
            memset( &msg->Ovlp, 0, sizeof( OVERLAPPED ) );
            //
            //  Request messages from the filter driver.
            //
            hr = FilterGetMessage( port,
                                   &msg->MessageHeader,
                                   FIELD_OFFSET( SCANNER_MESSAGE, Ovlp ),
                                   &msg->Ovlp );
            if (hr != HRESULT_FROM_WIN32( ERROR_IO_PENDING )) {
                free( msg );
                goto main_cleanup;
            }
        }
    }
    hr = S_OK;
    WaitForMultipleObjects( i, threads, TRUE, INFINITE );
main_cleanup:
    printf( "Scanner: All done. Result = 0x%08x\n", hr );
    CloseHandle( port );
    CloseHandle( completion );
    return hr;
}
  Mit Zitat antworten Zitat