AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

From C to delphi

Ein Thema von mohfa · begonnen am 4. Okt 2009 · letzter Beitrag vom 17. Okt 2009
 
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
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz