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

\b4r_main.h:12:13: note: candidate: static void b4r_main::_newmessage(B4R::Array*)
static void _newmessage(B4R::Array* _m);
^
C:\Users\Klaus\DOCUME~1\B4RApps\ESPNOW~2\ESPNOW~1\Objects\bin\sketch\b4r_main.h:12:13: note: no known conversion for argument 1 from 'char [32]' to 'B4R::Array*'

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
Top