Announcement

Collapse
No announcement yet.

C translation arrays

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C translation arrays

    Hi

    Could someone help me a bit? I have to translate a C++ function call to PB and I'm getting stuck.

    The C++ is this:
    extern EXPORTQUAL CHECKER_RC check(const char* checkTxt, CHECKRESULT &res,
    int &noOfResults,
    char results[RESULTSSIZE][RESULTSBUFSIZE], char* info);

    This is part of the example code I received, on how to call this function:
    Code:
        int checkres = 0;
        int noOfRes = 0;
    
        // results (suggestions) will be put in this array of arrays
        char results[RESULTSSIZE][RESULTSBUFSIZE];
        // extra information will be put in this array
        char info[INFOBUFSIZE];
    
        int checkret = check(buf.c_str(), checkres, noOfRes, results, info);

    I've tried this (and many more variations) but I'm missing somehting. Is the results array a 2 dimensional thing?

    Code:
        LOCAL checkTxt AS ASCIIZ * 100
        DIM results(%RESULTSSIZE, %RESULTSBUFSIZE) AS LOCAL ASCIIZ * 256
        DIM info(%INFOBUFSIZE) AS LOCAL ASCIIZ * 256
        
        checkTxt = "factuur"
        
        lResult = CHECK( checkTxt , %checkres, %noOfRes, results() , info() )

    Hope someone can help

    Thanx
    Jeroen


    Just be to complete: below are the types and constants.


    // linguistic return codes
    typedef int CHECKRESULT;
    const CHECKRESULT CHECK_OK = 10;
    const CHECKRESULT CHECK_AMBIGUOUS = 20;
    const CHECKRESULT CHECK_ERROR = 30;
    const CHECKRESULT CHECK_UNKNOWN = 40;

    // return codes for initialize/terminate
    typedef int CHECKER_RC;
    const CHECKER_RC CRC_OK = 0;
    const CHECKER_RC CRC_FAIL_null_parameter = 1;
    const CHECKER_RC CRC_FAIL_parameter_value = 2;
    const CHECKER_RC CRC_FAIL_parameter_size = 3;
    const CHECKER_RC CRC_FAIL_no_logfile = 10;
    const CHECKER_RC CRC_FAIL_cant_write_logfile = 11;
    const CHECKER_RC CRC_FAIL_no_resource = 20;
    const CHECKER_RC CRC_FAIL_cant_read_resource = 21;
    const CHECKER_RC CRC_FAIL_cant_write_resource = 22;
    const CHECKER_RC CRC_FAIL_resource_error = 23;
    const CHECKER_RC CRC_FAIL_no_library = 30;
    const CHECKER_RC CRC_FAIL_cant_open_library = 31;
    const CHECKER_RC CRC_FAIL_library_error = 32;
    const CHECKER_RC CRC_FAIL = 40;
    const CHECKER_RC CRC_FAIL_uninitialized = 41;
    const CHECKER_RC CRC_FAIL_previous_error = 42;
    const CHECKER_RC CRC_FAIL_out_of_memory = 43;
    const CHECKER_RC CRC_FAIL_exception = 44;

    // fixed size of results array
    const int RESULTSSIZE = 10;
    const int RESULTSBUFSIZE = 100; //maximum word length for words in the results buffer
    const int INFOBUFSIZE = 10000; //maximum number of characters in info buffer



    ------------------

  • #2
    Code:
    extern EXPORTQUAL CHECKER_RC check(const char* checkTxt, CHECKRESULT &res, 
    int &noOfResults, char results[RESULTSSIZE][RESULTSBUFSIZE], char* info);
    '---==>
    lResult = CHECK( checkTxt , %checkres, %noOfRes, results() , info() )
    The bold parameters should be passed by reference ("&" means "address of").

    Although your declare is not shown, I don't think you can pass a numeric literal by reference (an equate is a numeric literal).

    The italicized parameters are not right, either: you can't pass a PB array to a non-PB function. What you should be passing there is the address of the first element of the array.

    Work on getting the DECLARE fixed up and I think Good Things will ensue.

    Show what you have so far for a DECLARE statement and someone will help you tune it.



    [This message has been edited by Michael Mattias (edited June 26, 2007).]
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Hello Michael,

      My declare was:
      DECLARE FUNCTION CHECK LIB "ChatbotChecker.dll" ALIAS "check" ( spelwoord AS asciiz * 100, checkres AS INTEGER, noOfRes AS INTEGER, results() AS ASCIIZ * 256, info() AS ASCIIZ * 256 ) AS LONG

      With your comment I've tried to change it to
      DECLARE FUNCTION CHECK LIB "ChatbotChecker.dll" ALIAS "check" ( spelwoord AS ASCIIZ * 100, BYREF checkres AS INTEGER, BYREF noOfRes AS INTEGER, lresults AS DWORD, linfo AS DWORD ) AS LONG

      with the call being:
      Code:
          lResult = CHECK( checkTxt , BYREF %checkres, BYREF %noOfRes, VARPTR( results(0,0) ), VARPTR( info(0) ) )
      But unfortunately this doesn't change anything.

      Am I declaring the results array alright as a 2 dimensional array this way?

      Regards
      Jeroen

      ------------------

      Comment


      • #4
        >lresults AS DWORD, linfo AS DWORD
        These have to be BYVAL

        >BYREF %checkres, BYREF %noOfRes,
        These have to be variables passed by reference, not literals or equates.

        >But unfortunately this doesn't change anything.
        Unfortunately you haven't told us what is happening.

        I don't know that this should even compile, trying to pass equates by reference (because it makes no sense to do so). Then again, what's posted isn't even in the area code of a compilable example demonstrating the problem.

        The DECLARE may also require the CDECL option, but what I've said so far totally taps out my knowledge of C/C++.

        See if you can construct a simple but complete program which others CAN compile (or get the same compile time error, if that's what your problem is). Then explain the problem: Can't compile? Runs but program fails on protection fault? What kind of protection fault? Runs but returns incorrect output?

        MCM



        [This message has been edited by Michael Mattias (edited June 26, 2007).]
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Hello Michael,

          True, a test program would help a lot but I cannot share the third party dll.... That's part of the problem here.

          But thanks a lot anyway: I played around with the ideas you posted and now it works! The proper syntax seems to

          Code:
              LOCAL checkTxt AS ASCIIZ * 100
              DIM results(%RESULTSSIZE, %RESULTSBUFSIZE) AS LOCAL ASCIIZ * 256
              DIM info(%INFOBUFSIZE) AS LOCAL ASCIIZ * 256
              
              checkTxt = "factuur"
              
              LOCAL lcheckres AS INTEGER
              LOCAL lnoOfRes AS INTEGER
              
              lcheckres = %checkres
              lnoOfRes = %noOfRes
              
              lResult = CHECK( checkTxt , BYREF lcheckres, BYREF lnoOfRes, BYVAL VARPTR( results(0,0) ), BYVAL VARPTR( info(0) ) )
          Thanks a lot.

          Jeroen

          ------------------

          Comment


          • #6
            Not only does it work, but you get ten (10) bonus points for just sticking to it instead of whining about what a PITA it is to use DLLs.


            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Thanks Michael for all the help.
              Sticking to it is one of the traits of a programmer, no?

              ------------------

              Comment

              Working...
              X