B4R Question Return char[] to a B4R sub

KMatle

Expert
Licensed User
Longtime User
In C I have this struct and I want to call a B4R sub with myData.a (= char[32]).

B4X:
private Sub newmessage(m() As Byte)

Call from C: b4r_main::_newmessage(myData.a);

B4X:
typedef struct struct_message {
  char a[32];
  int b;
  float c;
  String d;
  bool e;
} struct_message;

// Create a struct_message called myData
struct_message myData;


Compile fails with


What is the correct type in B4R? I tried object but that didn't work either.
 

Daestrum

Expert
Licensed User
Longtime User
may not be the best way - but seems to work

B4X:
B4R::Object* doit(B4R::Object* xxx){
    string s = "hello";
    strcpy(myData.a,s.c_str());    
    B4R::Array jimbo;
    jimbo.wrap(myData.a,s.length());
    b4r_main::_newmessage(&jimbo);
}
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…