Hello,
the function EwNewStringAnsi() expects the string to be zero-terminated as this is usual in C. It would be thus better to adapt the MyStringStruct definition to reserve one additional char. Concrete to change the size of a string from 32 to 33. For example:
typedef struct
{
char text[33];
char id[33];
} MyStringStruct;
If this is not possible, then you can't use the function EwNewStringAnsi(). Instead, you have to perform a temp. copy step into an array containing an additional zero terminator sign. For example:
var string text = "";
var string id = "";
native( text, id )
{
// temp. buffers for the strings. Per default filled with zero char.
char tmpText[ sizeof( test.text ) + 1 ] = { 0 };
char tmpId [ sizeof( test.id ) + 1 ] = { 0 };
// copy the strings from the 'test' data structure. Use memcpy() or
// EmWi-own EwCopy() function:
EwCopy( tmpText, test.text, sizeof( test.text ));
EwCopy( tmpId, test.id, sizeof( test.id ));
text = EwNewStringAnsi ( tmpText );
id = EewNewStringAnsi( tmpId );
}
Alternative approach omits the local arrays. Instead you have to copy the string sign by sign into a previously created EmWi string. To create such string use the function EwNewStringChar():
var string text = "";
var string id = "";
native( text, id )
{
int i;
// First create new EmWi string with enough capacity.
text = EwNewStringChar( 0, sizeof( test.text ));
id = EwNewStringChar( 0, sizeof( id.text ));
// Then copy the ANSI string into the EmWi string. Sign by sign.
for ( i = 0; i < sizeof( test.text ); i++ )
text[i] = test.text[i];
// Repeat the operation for the second string.
for ( i = 0; i < sizeof( test.id ); i++ )
id[i] = test.id[i];
}
Does it help you further?
Best regards
Paul Banach