B4R Question [Solved] Inline C (How to pass inline string to B4R byte array?)

Discussion in 'B4R Questions' started by rbghongade, Jul 23, 2019.

  1. rbghongade

    rbghongade Active Member Licensed User

    Dear friends,
    I am unable to pass inline string to B4R byte array.
    here is the partial inline C code:
    Code:
    String u1=adr[0];
      
       byte b1[u1.length() + 
    1];
       u1.getBytes(b1, sizeof(b1));
       b4r_main::_a1->data = b1;
       b4r_main::_a1->length = sizeof(b1);
    Note that a1 is declared as:
    Code:
    Dim a1() As Byte
    I am logging a1 and am getting this output:
    Code:
    @��? ��?
     
  2. rbghongade

    rbghongade Active Member Licensed User

    Ok managed to solve the issue. Just declared String u1 and byte b1 as global variables in inline C section.
     
  3. janderkan

    janderkan Active Member Licensed User

    Please show your code.
     
  4. rbghongade

    rbghongade Active Member Licensed User

    Here is the code [relevant part only]
    Code:
    Dim a1(),a2(),a3(),a4() As Byte


    #if C
    String adr[4];
    String u1,u2,u3,u4;
    byte b1[18],b2[18],b3[18],b4[18];

    void some function to fill adr...


     
    void read (B4R::Object* o) {
     
      
       u1=adr[0];
       u1.getBytes(b1, sizeof(b1));
       b4r_main::_a1->data = b1;
       b4r_main::_a1->length = sizeof(b1);
       u2=adr[1];
       u2.getBytes(b2, sizeof(b2));
       b4r_main::_a2->data = b2;
       b4r_main::_a2->length = sizeof(b2);
       u3=adr[2];
       u3.getBytes(b3, sizeof(b3));
       b4r_main::_a3->data = b3;
       b4r_main::_a3->length = sizeof(b3);
       u4=adr[3];
       u4.getBytes(b4, sizeof(b4));
       b4r_main::_a4->data = b4;
       b4r_main::_a4->length = sizeof(b4);
      
      }
    #end if
     
  5. Chris Tyrie

    Chris Tyrie Member Licensed User

    Nailed it like a pro. Color me impressed.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice