Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 7 of 7

vc++ to vb

This is a discussion on vc++ to vb within the MapPoint Desktop Discussion forums, part of the Map Forums category; can anyone help me to translate the vc++ code to visual basic. thanks in advance //******************** // I N C ...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    vc++ to vb

    can anyone help me to translate the vc++ code to visual basic. thanks in advance




    //********************
    // I N C L U D E S
    //********************

    #include <windows.h>
    #include <winbase.h>
    #include <string.h>
    #include <stdio.h>
    #include <process.h>

    #include "..\\inc\\scn.h"
    #include "..\\inc\\wdemo.h"

    //********************
    // V A R I A B L E S
    //********************

    extern DWORD codeline_pocket_mod1 ;
    extern char path_img[_MAX_PATH] ;
    extern struct global_var Info_device ;

    static HANDLE hSemAPI ;
    static HANDLE hSemRdr ;
    static HANDLE hSemImg ;
    static HANDLE hSemSts ;

    static HWND theApp ;
    static int thError ;

    static char sz_prefix[512] ;
    static BOOL enScanner ;

    static BYTE sideImg ;
    static BYTE typeImg ;

    static DWORD dwImgCnt;
    static DWORD dwDocCnt;

    //********************
    // F U N C T I O N S D E F I N E S
    //********************

    int ADH_Mode1(HWND, DWORD, BYTE , BYTE , LPSTR, DWORD, LPDWORD) ;

    static BOOL ADH_MakeSemaphores(void) ;
    static VOID ADH_DestroySemaphores(void) ;

    static int ADH_GetReaderStatus(HWND) ;
    static int ADH_ChangePockets(HWND) ;

    void ADH_thLetturaSingoloDocumento(LPVOID) ;
    int ADH_ScaricaImmagine(BYTE, BYTE, BYTE, LPSTR) ;
    int ADH_Save_RAW_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_BMP_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_JPG_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_TIF_to_File(int, BYTE, LPSTR, LPSTR) ;

    static BOOL IsEnableScanner(HWND);
    static int ProcessYield(HWND) ;

    //********************
    // D E F I N E S
    //********************

    #define FIMG "f.img"
    #define RIMG "r.img"
    #define FBMP "f.bmp"
    #define RBMP "r.bmp"
    #define W1IMG "w1.img"
    #define W2IMG "w2.img"
    #define W1BMP "w1.bmp"
    #define W2BMP "w2.bmp"
    #define FJPG "f.jpg"
    #define RJPG "r.jpg"
    #define W1JPG "w1.jpg"
    #define W2JPG "w2.jpg"
    #define FTIFF "f.tif"
    #define RTIFF "r.tif"
    #define W1TIFF "w1.tif"
    #define W2TIFF "w2.tif"

    //================

    /*
    *
    * Create Semaphores.
    *
    */
    static BOOL ADH_MakeSemaphores(void)
    {
    //
    // Create Semaphore for avoiding to release parallel threads.
    //
    hSemRdr = CreateSemaphore(NULL,1,1,NULL);
    if (hSemRdr == NULL) return(FALSE);
    //
    // Create Semaphore for images downloading, free at the beginning.
    //
    hSemImg = CreateSemaphore(NULL,1,1,NULL);
    if (hSemImg == NULL) {
    (void) CloseHandle(hSemRdr) ;
    return(FALSE);
    }
    //
    // Create Semaphore for the state variable of SCN_AutoDocHandle.
    //
    hSemSts = CreateSemaphore(NULL,1,1,NULL);
    if (hSemSts == NULL) {
    (void) CloseHandle(hSemRdr) ;
    (void) CloseHandle(hSemImg) ;
    return(FALSE);
    }

    return(TRUE);
    }

    //================

    /*
    *
    * Close Semaphore and cancel each reference.
    *
    */
    static void ADH_DestroySemaphores(void)
    {
    if (hSemRdr != NULL) {
    (void) ReleaseSemaphore(hSemRdr, 1, NULL);
    (void) CloseHandle(hSemRdr);
    hSemRdr = NULL ;
    }
    if (hSemImg != NULL) {
    (void) ReleaseSemaphore(hSemImg, 1, NULL);
    (void) CloseHandle(hSemImg);
    hSemImg = NULL ;
    }
    if (hSemSts != NULL) {
    (void) ReleaseSemaphore(hSemSts, 1, NULL);
    (void) CloseHandle(hSemSts);
    hSemSts = NULL ;
    }

    return;
    }

    //================================================== ============================

    /*
    *
    * ADH_Mode1(...).
    *
    *
    */
    int ADH_Mode1(HWND hwnd, DWORD max_doc, BYTE receive_img, BYTE tipo_img, LPSTR prefix, DWORD start, LPDWORD num_doc_processed)
    {
    int RetStat ;
    int Ret ;
    int ThrStat ;
    int ErrStat ;
    int dwThDoc ;
    static BYTE bydefpocket ;

    RetStat = SCN_OK ;
    ThrStat = SCN_OK ;
    //
    // Test values for documents.
    //
    if (start < 1) start = 1 ;
    if (max_doc < 1) max_doc = 99999 ;

    dwThDoc = max_doc ;

    (void) strcpy(sz_prefix, (char *)prefix);

    theApp = hwnd ;

    sideImg = receive_img ;
    typeImg = tipo_img ;
    //
    // Reset of semaphores.
    //
    (void) ADH_DestroySemaphores() ;
    if (ADH_MakeSemaphores() == FALSE) return(SCN_ADH_TIMEOUT);
    //
    // Set to zero the thread error flag.
    //
    ErrStat = SCN_OK ;
    thError = SCN_OK ;
    //
    // Set to zero the images and doc counter (to download).
    //
    dwImgCnt = 0 ;
    dwDocCnt = 0 ;
    //
    // Is the image acquisition enable?
    //
    enScanner = IsEnableScanner(hwnd) ;
    //
    // Reset reader.
    //
    RetStat = SCN_Reset(hwnd,RESET_DOC_QUEUE); // Reset documents queue.
    (void) Sleep(API_LOOP_DELAY) ;
    RetStat = SCN_Reset(hwnd,RESET_ERROR) ; // Reset error signals.
    (void) Sleep(API_LOOP_DELAY) ;
    RetStat = SCN_Reset(hwnd,RESET_COMPLETE) ; // Complete reset.
    (void) Sleep(API_LOOP_DELAY) ;
    //
    // Disable all pockets full.
    //
    if ((RetStat == SCN_OK) && (strstr(Info_device.Device_name, PRODUCT_6000) != NULL))
    {
    RetStat = SCN_SetSdhMode(hwnd, SCN_SDH_POCKET_00_OFF);
    if (RetStat != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    //
    // Get the default pocket.
    //
    if (RetStat == SCN_OK)
    {
    RetStat = SCN_GetRegister_Pocket(hwnd, &bydefpocket);
    if (RetStat != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    //
    // Is reader ready?
    //
    if (RetStat == SCN_OK) RetStat = ADH_GetReaderStatus(hwnd) ;
    //
    // Threads generator, document reading.
    //
    while ((RetStat == SCN_OK) && (dwThDoc > 0)) {
    //
    // Wait for ready semaphore.
    //
    if (WaitForSingleObject(hSemRdr, 10000L) != WAIT_OBJECT_0) {
    //
    // Check the state of precedent thread.
    //
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    ErrStat = thError ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    if (ErrStat != SCN_OK) {
    RetStat = ErrStat ;
    } else {
    RetStat = SCN_ADH_TIMEOUT ;
    }
    }
    //
    // Is there an error in the thread?
    //
    if (RetStat == SCN_OK) {
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    ErrStat = thError ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    if (ErrStat != SCN_OK) RetStat = ErrStat ;
    }
    //
    // Msg Windows Queue.
    //
    (void) ProcessYield(hwnd) ;
    //
    // Create a new thread.
    //
    if (RetStat == SCN_OK) {
    ThrStat = _beginthread(ADH_thLetturaSingoloDocumento, 65535, (LPVOID)(start++)) ;
    if (ThrStat < 0) {
    //
    // Error in the thread creation.
    //
    RetStat = SCN_ADH_TIMEOUT ;
    } else {
    //
    // Documents counter.
    //
    dwThDoc-- ;
    }
    }
    }
    //
    // Waiting the last thread.
    //
    do {
    (void) Sleep(500) ;
    (void) WaitForSingleObject(hSemImg, 10000L) ;
    ErrStat = dwImgCnt ;
    (void) ReleaseSemaphore(hSemImg, 1, NULL) ;
    } while (ErrStat > 0) ;
    //
    // Destroy semaphores.
    //
    (void) Sleep(1000) ;
    (void) ADH_DestroySemaphores() ;
    //
    // Document counter.
    //
    (*num_doc_processed) = dwDocCnt ;
    //
    // Thread Time-Out?
    //
    if (RetStat == SCN_ADH_TIMEOUT) return(RetStat);
    //
    // Is Reader in error?
    //
    RetStat = thError ;
    //
    // num_doc_processed == max_doc and no errors?
    //
    if ((RetStat == SCN_OK) && (dwDocCnt == max_doc)) RetStat = SCN_ADH_DOC_PROCESSED_OK ;

    switch(RetStat) {

    case SCN_ADH_COMMUNICATION_ERROR:
    case SCN_ADH_DOC_PROCESSED_OK:
    case SCN_ADH_DOC_NOT_PRESENT:
    case SCN_ADH_CDL_WRITE_ERROR:
    case SCN_ADH_IMG_CONVERT_ERROR:
    case SCN_ADH_IMG_WRITE_ERROR:
    case SCN_ADH_COVER_OPEN:
    case SCN_ADH_BOURRAGE:
    case SCN_ADH_SLIP_DOC:
    case SCN_ADH_2THICKNESS_ERROR:
    case SCN_ADH_POCKET1_FULL:
    case SCN_ADH_POCKET2_FULL:
    case SCN_ADH_POCKET3_FULL:
    case SCN_ADH_ALL_POCKETS_FULL:
    case SCN_ADH_DOC_IN_TRACK:
    break;

    case SCN_ADH_CDL_ERROR:
    case SCN_ADH_IMG_ERROR:
    thError = ADH_GetReaderStatus(hwnd);
    if ((thError == SCN_ADH_BOURRAGE) ||
    (thError == SCN_ADH_COVER_OPEN) ||
    (thError == SCN_ADH_2THICKNESS_ERROR)) RetStat = thError;
    break;

    default:
    RetStat = ADH_GetReaderStatus(hwnd);
    break;
    }
    //
    // Set the default pocket.
    //
    Ret = SCN_SetRegister_Pocket(hwnd, bydefpocket);

    return(RetStat);
    }

    //================================================== ============================

    /*
    *
    * Get reader status.
    *
    */
    static int ADH_GetReaderStatus(HWND hWnd)
    {
    int ret ;
    BYTE rdrState ;
    BYTE rdrError ;
    BYTE rdrPhoto1 ;
    BYTE rdrPhoto2 ;
    BYTE rdrPocket ;
    BYTE rdrBadge ;
    //
    // Get status.
    //
    ret = (int) SCN_GetRegister_Reader(hWnd, (LPBYTE)&rdrState, (LPBYTE)&rdrError, (LPBYTE)&rdrPhoto1, (LPBYTE)&rdrPhoto2, (LPBYTE)&rdrPocket, (LPBYTE)&rdrBadge);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    //
    // ErrorCode.
    //
    if (rdrError != SCN_OK) {

    if ((rdrError & SCN_COVER_OPEN) == SCN_COVER_OPEN) return(SCN_ADH_COVER_OPEN) ;
    if ((rdrError & SCN_2THICKNESS) == SCN_2THICKNESS) return(SCN_ADH_2THICKNESS_ERROR) ;
    if ((rdrError & SCN_BOURRAGE) == SCN_BOURRAGE) return(SCN_ADH_BOURRAGE) ;
    if ((rdrError & SCN_SLIP_DOC) == SCN_SLIP_DOC) return(SCN_ADH_SLIP_DOC) ;
    }
    //
    // Document jammed in the scanner?
    //
    if (rdrPhoto2 > 0x00) return(SCN_ADH_DOC_IN_TRACK);
    //
    // Check if the exit pockets are full.
    //
    if (strstr(Info_device.Device_name, PRODUCT_6000) != NULL) {

    if ((rdrPocket & SCN_RGR_POCKET1_FULL) == SCN_RGR_POCKET1_FULL) return(SCN_ADH_POCKET1_FULL);
    if ((rdrPocket & SCN_RGR_POCKET2_FULL) == SCN_RGR_POCKET2_FULL) return(SCN_ADH_POCKET2_FULL);
    if ((rdrPocket & SCN_RGR_POCKET3_FULL) == SCN_RGR_POCKET3_FULL) return(SCN_ADH_POCKET3_FULL);

    }
    //
    // Feeder Empty?
    //
    if (rdrPhoto1 == FEEDER_EMPTY) return(SCN_ADH_DOC_NOT_PRESENT);

    return(SCN_OK);
    }


    //================================================== ============================

    /*
    *
    * Change the pockets.
    *
    */
    static int ADH_ChangePockets(HWND hWnd)
    {
    int ret ;
    BYTE rdrState ;
    BYTE rdrError ;
    BYTE rdrPhoto1 ;
    BYTE rdrPhoto2 ;
    BYTE rdrPocket ;
    BYTE rdrBadge ;
    //
    // Get status.
    //
    ret = (int) SCN_GetRegister_Reader(hWnd, (LPBYTE)&rdrState, (LPBYTE)&rdrError, (LPBYTE)&rdrPhoto1, (LPBYTE)&rdrPhoto2, (LPBYTE)&rdrPocket, (LPBYTE)&rdrBadge);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    //
    // Check if the exit pockets are full.
    //
    if (strstr(Info_device.Device_name, PRODUCT_6000) != NULL) {

    if (((rdrPocket & SCN_RGR_POCKET1_FULL) == SCN_RGR_POCKET1_FULL) &&
    ((rdrPocket & SCN_RGR_POCKET2_FULL) == SCN_RGR_POCKET2_FULL) &&
    ((rdrPocket & SCN_RGR_POCKET3_FULL) == SCN_RGR_POCKET3_FULL)) return(SCN_ADH_ALL_POCKETS_FULL);

    if ((rdrPocket & SCN_RGR_POCKET1_FULL) != SCN_RGR_POCKET1_FULL)
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET1);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    else
    {
    if ((rdrPocket & SCN_RGR_POCKET3_FULL) != SCN_RGR_POCKET3_FULL)
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET3);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    else
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET2);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    }
    }
    return(ret);
    }

    //================================================== ============================

    /*
    *
    * Reading document thread.
    *
    */
    static void ADH_thLetturaSingoloDocumento(LPVOID count)
    {
    int status ;
    BOOL fSaveCdl ;
    DWORD wrBytes ;
    DWORD dataSize ;
    WORD wNum ;
    char sz_data[DIM_CODELINE] ;
    char sz_datapK[DIM_CODELINE] ;
    char file_codeline_img[512] ;
    char file_codeline_txt[512] ;
    BYTE id_doc ;
    BYTE bPocket, bVal ;
    HANDLE hf ;

    (void) sprintf(file_codeline_img, "%s%s%010d", path_img, sz_prefix, (int)count);
    (void) sprintf(file_codeline_txt, "%s%s%010d.txt", path_img, sz_prefix, (int)count);
    //
    // OK save codeline.
    //
    fSaveCdl = TRUE ;
    //
    // Reading document.
    //
    //
    //
    status = ADH_ChangePockets(theApp);
    //
    //
    //
    if (status == SCN_OK)
    status = SCN_SingleDocHandle(theApp, &id_doc) ;
    //
    // Reader not READY.
    //
    while (status == SCN_INCORRECT_STATE) {
    (void) Sleep(API_LOOP_DELAY);
    //
    //
    //
    status = ADH_ChangePockets(theApp);
    //
    //
    //
    if (status == SCN_OK)
    status = SCN_SingleDocHandle(theApp, &id_doc);
    }
    //
    // DoubleThickness detect in SCN_SingleDocHandle?
    //
    if (status == SCN_2THICKNESS_DETECT) status = SCN_OK;
    //
    // Receive codeline.
    //
    if (status == SCN_OK) {
    //
    // Increase doc counter.
    //
    dwDocCnt++ ;

    dataSize = 0 ;
    status = SCN_ReceiveCodeline(theApp, id_doc, sz_data, &dataSize) ;
    //
    // Is there an error in the codeline?
    //
    switch(status) {

    case SCN_DOC_CODELINE_OK :
    case SCN_DOC_CODELINE_OK_ERR:
    case SCN_DOC_CODELINE_OK_EMPTY:
    status = SCN_OK;
    break ;

    case SCN_DOC_CODELINE_OFF:
    fSaveCdl = FALSE;
    status = SCN_OK;
    break;

    default:
    status = SCN_ADH_CDL_ERROR;
    break;
    }
    }
    //
    // Codeline saving if fCodeLinePocket == FALSE.
    //
    if (status == SCN_OK) {
    if ((fSaveCdl == TRUE) && (codeline_pocket_mod1 == 0)){
    status = SCN_ADH_CDL_WRITE_ERROR;
    hf = CreateFile(file_codeline_txt,GENERIC_WRITE,0,NULL, CREATE_ALWAYS,0,NULL);
    if (hf != INVALID_HANDLE_VALUE) {
    if (WriteFile(hf, sz_data, dataSize, &wrBytes, NULL) == TRUE) status = SCN_OK;
    (void) CloseHandle(hf) ;
    }
    }
    }
    //
    // Check error for codeline.
    //
    if (status != SCN_OK) {

    switch(status) {

    case SCN_ADH_DOC_NOT_PRESENT:
    case SCN_ADH_CDL_WRITE_ERROR:
    case SCN_ADH_COVER_OPEN:
    case SCN_ADH_BOURRAGE:
    case SCN_ADH_SLIP_DOC:
    case SCN_ADH_2THICKNESS_ERROR:
    case SCN_POCKET1_FULL:
    case SCN_POCKET2_FULL:
    case SCN_POCKET3_FULL:
    case SCN_ADH_ALL_POCKETS_FULL:
    break;

    default:
    status = SCN_ADH_CDL_ERROR;
    break ;

    }

    (void) WaitForSingleObject(hSemSts, 10000L) ;
    if (thError == SCN_OK) thError = status ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    }
    //
    // In case of reading error or if scanners are not enable, thread end.
    //
    if (enScanner == FALSE) {
    //
    // Document free.
    //
    (void) SCN_DocFree(theApp, id_doc) ;
    //
    // Semaphore of reading document free, another thread can start.
    //
    (void) ReleaseSemaphore(hSemRdr, 1, NULL) ;
    //
    // Thread end.
    //
    (void) _endthread();
    return ;
    }
    //
    // Increase the images counter to download.
    //
    if (status == SCN_OK) dwImgCnt++ ;
    //
    // Semaphore of reading document free, another thread can start.
    //
    (void) ReleaseSemaphore(hSemRdr, 1, NULL) ;

    (void) Sleep(200);

    (void) WaitForSingleObject(hSemImg, 10000L) ;

    if (status == SCN_OK) {
    //
    // Images download.
    //
    if ((sideImg & RECEIVE_DATA_IMG_FRONT) == RECEIVE_DATA_IMG_FRONT) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_IMG_FRONT, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_IMG_BACK) == RECEIVE_DATA_IMG_BACK) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_IMG_BACK, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_WINDOW1) == RECEIVE_DATA_WINDOW1) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_WINDOW1, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_WINDOW2) == RECEIVE_DATA_WINDOW2) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_WINDOW2, id_doc, file_codeline_img);
    }
    //
    // Decrease the images counter.
    //
    dwImgCnt-- ;
    //
    // Codeline saving if codeline_pocket_mod1 == 1.
    //
    if (status == SCN_OK) {
    if ((fSaveCdl == TRUE) && (codeline_pocket_mod1 == 1)) {
    //
    // Get Pocket.
    //
    status = SCN_GetRegister_Document(theApp, &id_doc, &bVal, &bVal,
    &bVal, &bVal, &bVal, &bVal, &wNum,
    &wNum, &bPocket);
    //
    // Pocket not available -> Waiting.
    //
    while ((status == SCN_OK) && (bPocket == POCKET0)) {
    (void) Sleep(API_LOOP_DELAY);
    status = SCN_GetRegister_Document(theApp, &id_doc, &bVal, &bVal,
    &bVal, &bVal, &bVal, &bVal, &wNum,
    &wNum, &bPocket);
    }
    //
    // It adds to the codeline the exit pocket indication.
    //
    if (status == SCN_OK) {
    dataSize = sprintf(sz_datapK, "[P%0.1d]%s", bPocket, sz_data);
    //
    // Codeline saving.
    //
    status = SCN_ADH_CDL_WRITE_ERROR;
    hf = CreateFile(file_codeline_txt,GENERIC_WRITE,0,NULL, CREATE_ALWAYS,0,NULL);
    if (hf != INVALID_HANDLE_VALUE) {
    if (WriteFile(hf, sz_datapK, dataSize, &wrBytes, NULL) == TRUE) status = SCN_OK;
    (void) CloseHandle(hf) ;
    }
    }
    }
    }
    //
    // Check error.
    //
    if (status != SCN_OK) {
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    thError = status ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    }
    }
    //
    // Document free.
    //
    (void) SCN_DocFree(theApp, id_doc) ;
    (void) ReleaseSemaphore(hSemImg, 1, NULL) ;
    //
    // Thread end.
    //
    _endthread();

    return;
    }

    //================================================== ============================

    /*
    *
    * Images download.
    *
    */
    static int ADH_ScaricaImmagine(BYTE TipeImg, BYTE SideImg, BYTE img_doc, LPSTR file_img)
    {
    int status ;
    LPSTR imgBuf ;
    DWORD imgSize ;
    //
    // Image buffer.
    //
    imgBuf = (LPSTR) GlobalAlloc(GMEM_FIXED, BUFF_IMG);
    if (imgBuf == NULL) return(SCN_ADH_IMG_ERROR);
    if (GlobalSize((HGLOBAL)imgBuf) < BUFF_IMG) {
    (void) GlobalFree((HGLOBAL)imgBuf);
    return(SCN_ADH_IMG_ERROR);
    }
    //
    // Image received.
    //
    status = SCN_ReceiveImage(theApp, SideImg, img_doc, imgBuf, &imgSize) ;
    //
    // Error in the image receiving.
    //
    if (status != SCN_OK) {
    (void) GlobalFree((HGLOBAL)imgBuf);
    return(SCN_ADH_IMG_ERROR);
    }
    //
    // Image saving in the required format.
    //
    switch(TipeImg) {

    case RAW:
    status = ADH_Save_RAW_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case BMP:
    case BMP_S:
    status = ADH_Save_BMP_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case JPG:
    case JPG_S:
    status = ADH_Save_JPG_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case TIFFG3:
    case TIFFG4:
    status = ADH_Save_TIF_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break;
    }

    (void) GlobalFree((HGLOBAL)imgBuf);

    return(status);
    }

    //================================================== ============================

    /*
    *
    * Save image in RAW format.
    *
    */
    static int ADH_Save_RAW_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    int righe ;
    int colonne ;
    int dimensione ;
    int wlen ;
    char fn[512] ;
    char* bufSCN ;
    HANDLE hf ;

    bufSCN = imgBuf ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FIMG) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RIMG) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1IMG) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2IMG) ;
    break;
    }
    //
    // Save the correct size of files.
    //
    colonne = MAKEWORD(bufSCN[6], bufSCN[7]) ;
    righe = MAKEWORD(bufSCN[8], bufSCN[9]) ;
    dimensione = (colonne*righe) + HEADER_IMG ;

    hf = CreateFile(fn,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0 ,NULL);
    if (hf == INVALID_HANDLE_VALUE) return(-1);
    ret = WriteFile(hf, bufSCN, dimensione, &wlen, NULL);
    (void) CloseHandle(hf) ;
    //
    // Write Error?
    //
    if ((ret == FALSE) || (wlen != dimensione)) return(SCN_IMG_WRITE_ERROR) ;

    return(SCN_OK);
    }

    //================================================== ============================

    /*
    *
    * Save image in BMP format.
    *
    */
    static int ADH_Save_BMP_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FBMP) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RBMP) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1BMP) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2BMP) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret) ;
    }

    //==[ADH_Save_JPG_to_File]================================================== ====
    //
    // Save image in JPEG format.
    //
    static int ADH_Save_JPG_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FJPG) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RJPG) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1JPG) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2JPG) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret);
    }

    //==[ADH_Save_TIF_to_File]================================================== ====
    //
    // Save image in TIFF G3/G4 format.
    //
    static int ADH_Save_TIF_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FTIFF) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RTIFF) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1TIFF) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2TIFF) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret);
    }

    //================================================== ============================

    /*
    *
    * Check if scanners are enable.
    *
    */
    BOOL IsEnableScanner(HWND hWnd)
    {
    int status ;
    BYTE scanner ;
    BYTE a,b,c,d,e,f,g,h ;
    struct img_window image ;

    status = SCN_GetRegister_Image(hWnd, &scanner,
    &a, &b, &c, &d, &e, &f, &g, &h,
    &image);

    if ((status != SCN_OK) || (scanner == IMG_SCANNER_DISABLE)) {
    return(FALSE);
    }

    return(TRUE);
    }

    //================================================== ============================

    /*
    * Function : ProcessYield.
    * Function used for allowing the windows multitasking.
    *
    */
    int ProcessYield(HWND hDlg)
    {
    MSG msg;

    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    if (hDlg != 0) {
    if (!IsDialogMessage(hDlg, &msg)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    } else {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    return(0);
    }

  2. #2
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4
    What does the code do? I find some references to image formats but nothing about MapPoint.

    Eric
    ~ Order MapPoint MapPoint 2013 Here and Get Free Access to the MapForums Downloads ~
    ~~
    ~ Upgrade to Get Access to the MapForums Downloads ~

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Re: vc++ to vb

    use MSCOMM

  4. #4
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    Looks like it uses a scanner to read some images and then saves them?

    I note that a lot of the code is missing, and is included in the include files (and perhaps obj files for linking in).

    Personally, (assuming I knew what it did exactly), I wouldn't try to convert it; but would write a completely new VB program.


    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  5. #5
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Re: vc++ to vb

    Quote Originally Posted by lito
    can anyone help me to translate the vc++ code to visual basic. thanks in advance




    //********************
    // I N C L U D E S
    //********************

    #include <windows.h>
    #include <winbase.h>
    #include <string.h>
    #include <stdio.h>
    #include <process.h>

    #include "..\\inc\\scn.h"
    #include "..\\inc\\wdemo.h"

    //********************
    // V A R I A B L E S
    //********************

    extern DWORD codeline_pocket_mod1 ;
    extern char path_img[_MAX_PATH] ;
    extern struct global_var Info_device ;

    static HANDLE hSemAPI ;
    static HANDLE hSemRdr ;
    static HANDLE hSemImg ;
    static HANDLE hSemSts ;

    static HWND theApp ;
    static int thError ;

    static char sz_prefix[512] ;
    static BOOL enScanner ;

    static BYTE sideImg ;
    static BYTE typeImg ;

    static DWORD dwImgCnt;
    static DWORD dwDocCnt;

    //********************
    // F U N C T I O N S D E F I N E S
    //********************

    int ADH_Mode1(HWND, DWORD, BYTE , BYTE , LPSTR, DWORD, LPDWORD) ;

    static BOOL ADH_MakeSemaphores(void) ;
    static VOID ADH_DestroySemaphores(void) ;

    static int ADH_GetReaderStatus(HWND) ;
    static int ADH_ChangePockets(HWND) ;

    void ADH_thLetturaSingoloDocumento(LPVOID) ;
    int ADH_ScaricaImmagine(BYTE, BYTE, BYTE, LPSTR) ;
    int ADH_Save_RAW_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_BMP_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_JPG_to_File(int, BYTE, LPSTR, LPSTR) ;
    int ADH_Save_TIF_to_File(int, BYTE, LPSTR, LPSTR) ;

    static BOOL IsEnableScanner(HWND);
    static int ProcessYield(HWND) ;

    //********************
    // D E F I N E S
    //********************

    #define FIMG "f.img"
    #define RIMG "r.img"
    #define FBMP "f.bmp"
    #define RBMP "r.bmp"
    #define W1IMG "w1.img"
    #define W2IMG "w2.img"
    #define W1BMP "w1.bmp"
    #define W2BMP "w2.bmp"
    #define FJPG "f.jpg"
    #define RJPG "r.jpg"
    #define W1JPG "w1.jpg"
    #define W2JPG "w2.jpg"
    #define FTIFF "f.tif"
    #define RTIFF "r.tif"
    #define W1TIFF "w1.tif"
    #define W2TIFF "w2.tif"

    //================

    /*
    *
    * Create Semaphores.
    *
    */
    static BOOL ADH_MakeSemaphores(void)
    {
    //
    // Create Semaphore for avoiding to release parallel threads.
    //
    hSemRdr = CreateSemaphore(NULL,1,1,NULL);
    if (hSemRdr == NULL) return(FALSE);
    //
    // Create Semaphore for images downloading, free at the beginning.
    //
    hSemImg = CreateSemaphore(NULL,1,1,NULL);
    if (hSemImg == NULL) {
    (void) CloseHandle(hSemRdr) ;
    return(FALSE);
    }
    //
    // Create Semaphore for the state variable of SCN_AutoDocHandle.
    //
    hSemSts = CreateSemaphore(NULL,1,1,NULL);
    if (hSemSts == NULL) {
    (void) CloseHandle(hSemRdr) ;
    (void) CloseHandle(hSemImg) ;
    return(FALSE);
    }

    return(TRUE);
    }

    //================

    /*
    *
    * Close Semaphore and cancel each reference.
    *
    */
    static void ADH_DestroySemaphores(void)
    {
    if (hSemRdr != NULL) {
    (void) ReleaseSemaphore(hSemRdr, 1, NULL);
    (void) CloseHandle(hSemRdr);
    hSemRdr = NULL ;
    }
    if (hSemImg != NULL) {
    (void) ReleaseSemaphore(hSemImg, 1, NULL);
    (void) CloseHandle(hSemImg);
    hSemImg = NULL ;
    }
    if (hSemSts != NULL) {
    (void) ReleaseSemaphore(hSemSts, 1, NULL);
    (void) CloseHandle(hSemSts);
    hSemSts = NULL ;
    }

    return;
    }

    //================================================== ============================

    /*
    *
    * ADH_Mode1(...).
    *
    *
    */
    int ADH_Mode1(HWND hwnd, DWORD max_doc, BYTE receive_img, BYTE tipo_img, LPSTR prefix, DWORD start, LPDWORD num_doc_processed)
    {
    int RetStat ;
    int Ret ;
    int ThrStat ;
    int ErrStat ;
    int dwThDoc ;
    static BYTE bydefpocket ;

    RetStat = SCN_OK ;
    ThrStat = SCN_OK ;
    //
    // Test values for documents.
    //
    if (start < 1) start = 1 ;
    if (max_doc < 1) max_doc = 99999 ;

    dwThDoc = max_doc ;

    (void) strcpy(sz_prefix, (char *)prefix);

    theApp = hwnd ;

    sideImg = receive_img ;
    typeImg = tipo_img ;
    //
    // Reset of semaphores.
    //
    (void) ADH_DestroySemaphores() ;
    if (ADH_MakeSemaphores() == FALSE) return(SCN_ADH_TIMEOUT);
    //
    // Set to zero the thread error flag.
    //
    ErrStat = SCN_OK ;
    thError = SCN_OK ;
    //
    // Set to zero the images and doc counter (to download).
    //
    dwImgCnt = 0 ;
    dwDocCnt = 0 ;
    //
    // Is the image acquisition enable?
    //
    enScanner = IsEnableScanner(hwnd) ;
    //
    // Reset reader.
    //
    RetStat = SCN_Reset(hwnd,RESET_DOC_QUEUE); // Reset documents queue.
    (void) Sleep(API_LOOP_DELAY) ;
    RetStat = SCN_Reset(hwnd,RESET_ERROR) ; // Reset error signals.
    (void) Sleep(API_LOOP_DELAY) ;
    RetStat = SCN_Reset(hwnd,RESET_COMPLETE) ; // Complete reset.
    (void) Sleep(API_LOOP_DELAY) ;
    //
    // Disable all pockets full.
    //
    if ((RetStat == SCN_OK) && (strstr(Info_device.Device_name, PRODUCT_6000) != NULL))
    {
    RetStat = SCN_SetSdhMode(hwnd, SCN_SDH_POCKET_00_OFF);
    if (RetStat != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    //
    // Get the default pocket.
    //
    if (RetStat == SCN_OK)
    {
    RetStat = SCN_GetRegister_Pocket(hwnd, &bydefpocket);
    if (RetStat != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    //
    // Is reader ready?
    //
    if (RetStat == SCN_OK) RetStat = ADH_GetReaderStatus(hwnd) ;
    //
    // Threads generator, document reading.
    //
    while ((RetStat == SCN_OK) && (dwThDoc > 0)) {
    //
    // Wait for ready semaphore.
    //
    if (WaitForSingleObject(hSemRdr, 10000L) != WAIT_OBJECT_0) {
    //
    // Check the state of precedent thread.
    //
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    ErrStat = thError ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    if (ErrStat != SCN_OK) {
    RetStat = ErrStat ;
    } else {
    RetStat = SCN_ADH_TIMEOUT ;
    }
    }
    //
    // Is there an error in the thread?
    //
    if (RetStat == SCN_OK) {
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    ErrStat = thError ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    if (ErrStat != SCN_OK) RetStat = ErrStat ;
    }
    //
    // Msg Windows Queue.
    //
    (void) ProcessYield(hwnd) ;
    //
    // Create a new thread.
    //
    if (RetStat == SCN_OK) {
    ThrStat = _beginthread(ADH_thLetturaSingoloDocumento, 65535, (LPVOID)(start++)) ;
    if (ThrStat < 0) {
    //
    // Error in the thread creation.
    //
    RetStat = SCN_ADH_TIMEOUT ;
    } else {
    //
    // Documents counter.
    //
    dwThDoc-- ;
    }
    }
    }
    //
    // Waiting the last thread.
    //
    do {
    (void) Sleep(500) ;
    (void) WaitForSingleObject(hSemImg, 10000L) ;
    ErrStat = dwImgCnt ;
    (void) ReleaseSemaphore(hSemImg, 1, NULL) ;
    } while (ErrStat > 0) ;
    //
    // Destroy semaphores.
    //
    (void) Sleep(1000) ;
    (void) ADH_DestroySemaphores() ;
    //
    // Document counter.
    //
    (*num_doc_processed) = dwDocCnt ;
    //
    // Thread Time-Out?
    //
    if (RetStat == SCN_ADH_TIMEOUT) return(RetStat);
    //
    // Is Reader in error?
    //
    RetStat = thError ;
    //
    // num_doc_processed == max_doc and no errors?
    //
    if ((RetStat == SCN_OK) && (dwDocCnt == max_doc)) RetStat = SCN_ADH_DOC_PROCESSED_OK ;

    switch(RetStat) {

    case SCN_ADH_COMMUNICATION_ERROR:
    case SCN_ADH_DOC_PROCESSED_OK:
    case SCN_ADH_DOC_NOT_PRESENT:
    case SCN_ADH_CDL_WRITE_ERROR:
    case SCN_ADH_IMG_CONVERT_ERROR:
    case SCN_ADH_IMG_WRITE_ERROR:
    case SCN_ADH_COVER_OPEN:
    case SCN_ADH_BOURRAGE:
    case SCN_ADH_SLIP_DOC:
    case SCN_ADH_2THICKNESS_ERROR:
    case SCN_ADH_POCKET1_FULL:
    case SCN_ADH_POCKET2_FULL:
    case SCN_ADH_POCKET3_FULL:
    case SCN_ADH_ALL_POCKETS_FULL:
    case SCN_ADH_DOC_IN_TRACK:
    break;

    case SCN_ADH_CDL_ERROR:
    case SCN_ADH_IMG_ERROR:
    thError = ADH_GetReaderStatus(hwnd);
    if ((thError == SCN_ADH_BOURRAGE) ||
    (thError == SCN_ADH_COVER_OPEN) ||
    (thError == SCN_ADH_2THICKNESS_ERROR)) RetStat = thError;
    break;

    default:
    RetStat = ADH_GetReaderStatus(hwnd);
    break;
    }
    //
    // Set the default pocket.
    //
    Ret = SCN_SetRegister_Pocket(hwnd, bydefpocket);

    return(RetStat);
    }

    //================================================== ============================

    /*
    *
    * Get reader status.
    *
    */
    static int ADH_GetReaderStatus(HWND hWnd)
    {
    int ret ;
    BYTE rdrState ;
    BYTE rdrError ;
    BYTE rdrPhoto1 ;
    BYTE rdrPhoto2 ;
    BYTE rdrPocket ;
    BYTE rdrBadge ;
    //
    // Get status.
    //
    ret = (int) SCN_GetRegister_Reader(hWnd, (LPBYTE)&rdrState, (LPBYTE)&rdrError, (LPBYTE)&rdrPhoto1, (LPBYTE)&rdrPhoto2, (LPBYTE)&rdrPocket, (LPBYTE)&rdrBadge);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    //
    // ErrorCode.
    //
    if (rdrError != SCN_OK) {

    if ((rdrError & SCN_COVER_OPEN) == SCN_COVER_OPEN) return(SCN_ADH_COVER_OPEN) ;
    if ((rdrError & SCN_2THICKNESS) == SCN_2THICKNESS) return(SCN_ADH_2THICKNESS_ERROR) ;
    if ((rdrError & SCN_BOURRAGE) == SCN_BOURRAGE) return(SCN_ADH_BOURRAGE) ;
    if ((rdrError & SCN_SLIP_DOC) == SCN_SLIP_DOC) return(SCN_ADH_SLIP_DOC) ;
    }
    //
    // Document jammed in the scanner?
    //
    if (rdrPhoto2 > 0x00) return(SCN_ADH_DOC_IN_TRACK);
    //
    // Check if the exit pockets are full.
    //
    if (strstr(Info_device.Device_name, PRODUCT_6000) != NULL) {

    if ((rdrPocket & SCN_RGR_POCKET1_FULL) == SCN_RGR_POCKET1_FULL) return(SCN_ADH_POCKET1_FULL);
    if ((rdrPocket & SCN_RGR_POCKET2_FULL) == SCN_RGR_POCKET2_FULL) return(SCN_ADH_POCKET2_FULL);
    if ((rdrPocket & SCN_RGR_POCKET3_FULL) == SCN_RGR_POCKET3_FULL) return(SCN_ADH_POCKET3_FULL);

    }
    //
    // Feeder Empty?
    //
    if (rdrPhoto1 == FEEDER_EMPTY) return(SCN_ADH_DOC_NOT_PRESENT);

    return(SCN_OK);
    }


    //================================================== ============================

    /*
    *
    * Change the pockets.
    *
    */
    static int ADH_ChangePockets(HWND hWnd)
    {
    int ret ;
    BYTE rdrState ;
    BYTE rdrError ;
    BYTE rdrPhoto1 ;
    BYTE rdrPhoto2 ;
    BYTE rdrPocket ;
    BYTE rdrBadge ;
    //
    // Get status.
    //
    ret = (int) SCN_GetRegister_Reader(hWnd, (LPBYTE)&rdrState, (LPBYTE)&rdrError, (LPBYTE)&rdrPhoto1, (LPBYTE)&rdrPhoto2, (LPBYTE)&rdrPocket, (LPBYTE)&rdrBadge);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    //
    // Check if the exit pockets are full.
    //
    if (strstr(Info_device.Device_name, PRODUCT_6000) != NULL) {

    if (((rdrPocket & SCN_RGR_POCKET1_FULL) == SCN_RGR_POCKET1_FULL) &&
    ((rdrPocket & SCN_RGR_POCKET2_FULL) == SCN_RGR_POCKET2_FULL) &&
    ((rdrPocket & SCN_RGR_POCKET3_FULL) == SCN_RGR_POCKET3_FULL)) return(SCN_ADH_ALL_POCKETS_FULL);

    if ((rdrPocket & SCN_RGR_POCKET1_FULL) != SCN_RGR_POCKET1_FULL)
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET1);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    else
    {
    if ((rdrPocket & SCN_RGR_POCKET3_FULL) != SCN_RGR_POCKET3_FULL)
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET3);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    else
    {
    ret = (int) SCN_SetRegister_Pocket(hWnd, POCKET2);
    if (ret != SCN_OK) return(SCN_ADH_COMMUNICATION_ERROR);
    }
    }
    }
    return(ret);
    }

    //================================================== ============================

    /*
    *
    * Reading document thread.
    *
    */
    static void ADH_thLetturaSingoloDocumento(LPVOID count)
    {
    int status ;
    BOOL fSaveCdl ;
    DWORD wrBytes ;
    DWORD dataSize ;
    WORD wNum ;
    char sz_data[DIM_CODELINE] ;
    char sz_datapK[DIM_CODELINE] ;
    char file_codeline_img[512] ;
    char file_codeline_txt[512] ;
    BYTE id_doc ;
    BYTE bPocket, bVal ;
    HANDLE hf ;

    (void) sprintf(file_codeline_img, "%s%s%010d", path_img, sz_prefix, (int)count);
    (void) sprintf(file_codeline_txt, "%s%s%010d.txt", path_img, sz_prefix, (int)count);
    //
    // OK save codeline.
    //
    fSaveCdl = TRUE ;
    //
    // Reading document.
    //
    //
    //
    status = ADH_ChangePockets(theApp);
    //
    //
    //
    if (status == SCN_OK)
    status = SCN_SingleDocHandle(theApp, &id_doc) ;
    //
    // Reader not READY.
    //
    while (status == SCN_INCORRECT_STATE) {
    (void) Sleep(API_LOOP_DELAY);
    //
    //
    //
    status = ADH_ChangePockets(theApp);
    //
    //
    //
    if (status == SCN_OK)
    status = SCN_SingleDocHandle(theApp, &id_doc);
    }
    //
    // DoubleThickness detect in SCN_SingleDocHandle?
    //
    if (status == SCN_2THICKNESS_DETECT) status = SCN_OK;
    //
    // Receive codeline.
    //
    if (status == SCN_OK) {
    //
    // Increase doc counter.
    //
    dwDocCnt++ ;

    dataSize = 0 ;
    status = SCN_ReceiveCodeline(theApp, id_doc, sz_data, &dataSize) ;
    //
    // Is there an error in the codeline?
    //
    switch(status) {

    case SCN_DOC_CODELINE_OK :
    case SCN_DOC_CODELINE_OK_ERR:
    case SCN_DOC_CODELINE_OK_EMPTY:
    status = SCN_OK;
    break ;

    case SCN_DOC_CODELINE_OFF:
    fSaveCdl = FALSE;
    status = SCN_OK;
    break;

    default:
    status = SCN_ADH_CDL_ERROR;
    break;
    }
    }
    //
    // Codeline saving if fCodeLinePocket == FALSE.
    //
    if (status == SCN_OK) {
    if ((fSaveCdl == TRUE) && (codeline_pocket_mod1 == 0)){
    status = SCN_ADH_CDL_WRITE_ERROR;
    hf = CreateFile(file_codeline_txt,GENERIC_WRITE,0,NULL, CREATE_ALWAYS,0,NULL);
    if (hf != INVALID_HANDLE_VALUE) {
    if (WriteFile(hf, sz_data, dataSize, &wrBytes, NULL) == TRUE) status = SCN_OK;
    (void) CloseHandle(hf) ;
    }
    }
    }
    //
    // Check error for codeline.
    //
    if (status != SCN_OK) {

    switch(status) {

    case SCN_ADH_DOC_NOT_PRESENT:
    case SCN_ADH_CDL_WRITE_ERROR:
    case SCN_ADH_COVER_OPEN:
    case SCN_ADH_BOURRAGE:
    case SCN_ADH_SLIP_DOC:
    case SCN_ADH_2THICKNESS_ERROR:
    case SCN_POCKET1_FULL:
    case SCN_POCKET2_FULL:
    case SCN_POCKET3_FULL:
    case SCN_ADH_ALL_POCKETS_FULL:
    break;

    default:
    status = SCN_ADH_CDL_ERROR;
    break ;

    }

    (void) WaitForSingleObject(hSemSts, 10000L) ;
    if (thError == SCN_OK) thError = status ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    }
    //
    // In case of reading error or if scanners are not enable, thread end.
    //
    if (enScanner == FALSE) {
    //
    // Document free.
    //
    (void) SCN_DocFree(theApp, id_doc) ;
    //
    // Semaphore of reading document free, another thread can start.
    //
    (void) ReleaseSemaphore(hSemRdr, 1, NULL) ;
    //
    // Thread end.
    //
    (void) _endthread();
    return ;
    }
    //
    // Increase the images counter to download.
    //
    if (status == SCN_OK) dwImgCnt++ ;
    //
    // Semaphore of reading document free, another thread can start.
    //
    (void) ReleaseSemaphore(hSemRdr, 1, NULL) ;

    (void) Sleep(200);

    (void) WaitForSingleObject(hSemImg, 10000L) ;

    if (status == SCN_OK) {
    //
    // Images download.
    //
    if ((sideImg & RECEIVE_DATA_IMG_FRONT) == RECEIVE_DATA_IMG_FRONT) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_IMG_FRONT, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_IMG_BACK) == RECEIVE_DATA_IMG_BACK) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_IMG_BACK, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_WINDOW1) == RECEIVE_DATA_WINDOW1) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_WINDOW1, id_doc, file_codeline_img);
    }

    if (((sideImg & RECEIVE_DATA_WINDOW2) == RECEIVE_DATA_WINDOW2) && (status == SCN_OK)) {
    status = ADH_ScaricaImmagine(typeImg, RECEIVE_DATA_WINDOW2, id_doc, file_codeline_img);
    }
    //
    // Decrease the images counter.
    //
    dwImgCnt-- ;
    //
    // Codeline saving if codeline_pocket_mod1 == 1.
    //
    if (status == SCN_OK) {
    if ((fSaveCdl == TRUE) && (codeline_pocket_mod1 == 1)) {
    //
    // Get Pocket.
    //
    status = SCN_GetRegister_Document(theApp, &id_doc, &bVal, &bVal,
    &bVal, &bVal, &bVal, &bVal, &wNum,
    &wNum, &bPocket);
    //
    // Pocket not available -> Waiting.
    //
    while ((status == SCN_OK) && (bPocket == POCKET0)) {
    (void) Sleep(API_LOOP_DELAY);
    status = SCN_GetRegister_Document(theApp, &id_doc, &bVal, &bVal,
    &bVal, &bVal, &bVal, &bVal, &wNum,
    &wNum, &bPocket);
    }
    //
    // It adds to the codeline the exit pocket indication.
    //
    if (status == SCN_OK) {
    dataSize = sprintf(sz_datapK, "[P%0.1d]%s", bPocket, sz_data);
    //
    // Codeline saving.
    //
    status = SCN_ADH_CDL_WRITE_ERROR;
    hf = CreateFile(file_codeline_txt,GENERIC_WRITE,0,NULL, CREATE_ALWAYS,0,NULL);
    if (hf != INVALID_HANDLE_VALUE) {
    if (WriteFile(hf, sz_datapK, dataSize, &wrBytes, NULL) == TRUE) status = SCN_OK;
    (void) CloseHandle(hf) ;
    }
    }
    }
    }
    //
    // Check error.
    //
    if (status != SCN_OK) {
    (void) WaitForSingleObject(hSemSts, 10000L) ;
    thError = status ;
    (void) ReleaseSemaphore(hSemSts, 1, NULL) ;
    }
    }
    //
    // Document free.
    //
    (void) SCN_DocFree(theApp, id_doc) ;
    (void) ReleaseSemaphore(hSemImg, 1, NULL) ;
    //
    // Thread end.
    //
    _endthread();

    return;
    }

    //================================================== ============================

    /*
    *
    * Images download.
    *
    */
    static int ADH_ScaricaImmagine(BYTE TipeImg, BYTE SideImg, BYTE img_doc, LPSTR file_img)
    {
    int status ;
    LPSTR imgBuf ;
    DWORD imgSize ;
    //
    // Image buffer.
    //
    imgBuf = (LPSTR) GlobalAlloc(GMEM_FIXED, BUFF_IMG);
    if (imgBuf == NULL) return(SCN_ADH_IMG_ERROR);
    if (GlobalSize((HGLOBAL)imgBuf) < BUFF_IMG) {
    (void) GlobalFree((HGLOBAL)imgBuf);
    return(SCN_ADH_IMG_ERROR);
    }
    //
    // Image received.
    //
    status = SCN_ReceiveImage(theApp, SideImg, img_doc, imgBuf, &imgSize) ;
    //
    // Error in the image receiving.
    //
    if (status != SCN_OK) {
    (void) GlobalFree((HGLOBAL)imgBuf);
    return(SCN_ADH_IMG_ERROR);
    }
    //
    // Image saving in the required format.
    //
    switch(TipeImg) {

    case RAW:
    status = ADH_Save_RAW_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case BMP:
    case BMP_S:
    status = ADH_Save_BMP_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case JPG:
    case JPG_S:
    status = ADH_Save_JPG_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break ;

    case TIFFG3:
    case TIFFG4:
    status = ADH_Save_TIF_to_File(SideImg, TipeImg, (LPSTR)imgBuf, (LPSTR)file_img);
    break;
    }

    (void) GlobalFree((HGLOBAL)imgBuf);

    return(status);
    }

    //================================================== ============================

    /*
    *
    * Save image in RAW format.
    *
    */
    static int ADH_Save_RAW_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    int righe ;
    int colonne ;
    int dimensione ;
    int wlen ;
    char fn[512] ;
    char* bufSCN ;
    HANDLE hf ;

    bufSCN = imgBuf ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FIMG) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RIMG) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1IMG) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2IMG) ;
    break;
    }
    //
    // Save the correct size of files.
    //
    colonne = MAKEWORD(bufSCN[6], bufSCN[7]) ;
    righe = MAKEWORD(bufSCN[8], bufSCN[9]) ;
    dimensione = (colonne*righe) + HEADER_IMG ;

    hf = CreateFile(fn,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,0 ,NULL);
    if (hf == INVALID_HANDLE_VALUE) return(-1);
    ret = WriteFile(hf, bufSCN, dimensione, &wlen, NULL);
    (void) CloseHandle(hf) ;
    //
    // Write Error?
    //
    if ((ret == FALSE) || (wlen != dimensione)) return(SCN_IMG_WRITE_ERROR) ;

    return(SCN_OK);
    }

    //================================================== ============================

    /*
    *
    * Save image in BMP format.
    *
    */
    static int ADH_Save_BMP_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FBMP) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RBMP) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1BMP) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2BMP) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret) ;
    }

    //==[ADH_Save_JPG_to_File]================================================== ====
    //
    // Save image in JPEG format.
    //
    static int ADH_Save_JPG_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FJPG) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RJPG) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1JPG) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2JPG) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret);
    }

    //==[ADH_Save_TIF_to_File]================================================== ====
    //
    // Save image in TIFF G3/G4 format.
    //
    static int ADH_Save_TIF_to_File(int tipo, BYTE imgMode, LPSTR imgBuf, LPSTR file)
    {
    int ret ;
    char fn[512] ;
    //
    // Images name.
    //
    switch(tipo) {

    case RECEIVE_DATA_IMG_FRONT:
    (void) sprintf(fn,"%s%s",file,FTIFF) ;
    break;

    case RECEIVE_DATA_IMG_BACK:
    (void) sprintf(fn,"%s%s",file,RTIFF) ;
    break;

    case RECEIVE_DATA_WINDOW1:
    (void) sprintf(fn,"%s%s",file,W1TIFF) ;
    break;

    case RECEIVE_DATA_WINDOW2:
    (void) sprintf(fn,"%s%s",file,W2TIFF) ;
    break;
    }

    ret = (int) SCN_ConvertImage(theApp, (LPSTR)imgBuf, imgMode, NULL, (LPSTR)fn, ON_FILE) ;

    return(ret);
    }

    //================================================== ============================

    /*
    *
    * Check if scanners are enable.
    *
    */
    BOOL IsEnableScanner(HWND hWnd)
    {
    int status ;
    BYTE scanner ;
    BYTE a,b,c,d,e,f,g,h ;
    struct img_window image ;

    status = SCN_GetRegister_Image(hWnd, &scanner,
    &a, &b, &c, &d, &e, &f, &g, &h,
    &image);

    if ((status != SCN_OK) || (scanner == IMG_SCANNER_DISABLE)) {
    return(FALSE);
    }

    return(TRUE);
    }

    //================================================== ============================

    /*
    * Function : ProcessYield.
    * Function used for allowing the windows multitasking.
    *
    */
    int ProcessYield(HWND hDlg)
    {
    MSG msg;

    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    if (hDlg != 0) {
    if (!IsDialogMessage(hDlg, &msg)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    } else {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    return(0);
    }

  6. #6
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Walther Italia - cheque reader model SCN5005AF with VB

    Hello,

    The code you are looking at is for controlling a cheque reader, in this case it is for a Walther Italia. I have a cheque reader model SCN5005AF I need to write an application to control it.

    I have documentation on the API Interface for SCN_SCSI.DLL and SCN_USB.DLL all are in C++

    I would prefer to use Visual Basic, I am having trouble referencing the DLL from Visual Basic.

    The WDEMO I believe was written in Visual Basic 4.0 or maybe Visual C as the source files are in C.

    Can you let me know how far you got?

    my email address is anhenson@hotmail.com

    thanks

    Andrew

  7. #7
    EdB
    EdB is offline Member Green Belt
    Join Date
    Aug 2002
    Posts
    56
    So to restate and remphasize Eric's question........


    What does it have to do with Mappoint?

    Seems like you ought to be looking to an MS .Net community instead of here.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36