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

rbghongade

Active Member
Licensed User
Longtime User
Dear friends,
I am unable to pass inline string to B4R byte array.
here is the partial inline C code:
B4X:
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:
B4X:
Dim a1() As Byte
I am logging a1 and am getting this output:
B4X:
@��? ��?
 

rbghongade

Active Member
Licensed User
Longtime User
Ok managed to solve the issue. Just declared String u1 and byte b1 as global variables in inline C section.
 
Upvote 0

rbghongade

Active Member
Licensed User
Longtime User
Here is the code [relevant part only]
B4X:
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
 
Upvote 0
Top